From 053ca17207fb14773b484ec7170345737fd49174 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Tue, 11 Dec 2018 13:50:26 +0000 Subject: [PATCH 01/10] build: regenerate lint baseline file to account for changed lines + binary arch PR --- sdk/lint-baseline.xml | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/sdk/lint-baseline.xml b/sdk/lint-baseline.xml index cfa00f3ed5..0c900ea019 100644 --- a/sdk/lint-baseline.xml +++ b/sdk/lint-baseline.xml @@ -1827,6 +1827,17 @@ column="44"/> + + + + @@ -1845,7 +1856,7 @@ errorLine2=" ~~~~~~~~"> @@ -1856,7 +1867,7 @@ errorLine2=" ~~~~~~~~"> @@ -1867,7 +1878,7 @@ errorLine2=" ~~~~~~"> @@ -1878,7 +1889,7 @@ errorLine2=" ~~~~~~"> @@ -1889,7 +1900,7 @@ errorLine2=" ~~~~~~~~"> From 2ff6ca5f7335dabe4810be3f47688383bb7a72ba Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Tue, 11 Dec 2018 15:36:19 +0000 Subject: [PATCH 02/10] feat: add nullability annotations to public Client methods --- sdk/lint-baseline.xml | 451 ------------------ .../main/java/com/bugsnag/android/Client.java | 72 +-- 2 files changed, 36 insertions(+), 487 deletions(-) diff --git a/sdk/lint-baseline.xml b/sdk/lint-baseline.xml index 0c900ea019..3a2586078b 100644 --- a/sdk/lint-baseline.xml +++ b/sdk/lint-baseline.xml @@ -474,457 +474,6 @@ column="23"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - clientData, + @NonNull Map clientData, boolean blocking, - Callback callback) { + @Nullable Callback callback) { String severity = getKeyFromClientData(clientData, "severity", true); String severityReason = getKeyFromClientData(clientData, "severityReason", true); @@ -1120,7 +1120,7 @@ private String getKeyFromClientData(Map clientData, * @param key the name of the diagnostic information * @param value the contents of the diagnostic information */ - public void addToTab(String tab, String key, Object value) { + public void addToTab(@NonNull String tab, @NonNull String key, @Nullable Object value) { config.getMetaData().addToTab(tab, key, value); } @@ -1129,7 +1129,7 @@ public void addToTab(String tab, String key, Object value) { * * @param tabName the dashboard tab to remove diagnostic data from */ - public void clearTab(String tabName) { + public void clearTab(@NonNull String tabName) { config.getMetaData().clearTab(tabName); } From 8f2266232f04384975d03d55c5c3fd8d5c332761 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Tue, 11 Dec 2018 16:01:01 +0000 Subject: [PATCH 03/10] feat: add nullability annotations to public Bugsnag.java methods --- sdk/lint-baseline.xml | 341 ------------------ .../java/com/bugsnag/android/Bugsnag.java | 69 ++-- 2 files changed, 41 insertions(+), 369 deletions(-) diff --git a/sdk/lint-baseline.xml b/sdk/lint-baseline.xml index 0c900ea019..b7ba537558 100644 --- a/sdk/lint-baseline.xml +++ b/sdk/lint-baseline.xml @@ -78,347 +78,6 @@ column="12"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - clientData, + @NonNull Map clientData, boolean blocking, - Callback callback) { + @Nullable Callback callback) { getClient().internalClientNotify(exception, clientData, blocking, callback); } @@ -542,7 +553,9 @@ public static void internalClientNotify(@NonNull final Throwable exception, * @param key the name of the diagnostic information * @param value the contents of the diagnostic information */ - public static void addToTab(final String tab, final String key, final Object value) { + public static void addToTab(@NonNull final String tab, + @NonNull final String key, + @Nullable final Object value) { getClient().addToTab(tab, key, value); } @@ -551,7 +564,7 @@ public static void addToTab(final String tab, final String key, final Object val * * @param tabName the dashboard tab to remove diagnostic data from */ - public static void clearTab(String tabName) { + public static void clearTab(@NonNull String tabName) { getClient().clearTab(tabName); } From 8472047997148c055b0fa626b7c161df5a9cf39d Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Tue, 11 Dec 2018 16:18:52 +0000 Subject: [PATCH 04/10] feat: add nullability annotations for Client --- sdk/lint-baseline.xml | 330 ------------------ .../com/bugsnag/android/Configuration.java | 48 ++- 2 files changed, 30 insertions(+), 348 deletions(-) diff --git a/sdk/lint-baseline.xml b/sdk/lint-baseline.xml index 0c900ea019..776acbdbca 100644 --- a/sdk/lint-baseline.xml +++ b/sdk/lint-baseline.xml @@ -925,336 +925,6 @@ column="26"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - getErrorApiHeaders() { Map map = new HashMap<>(); map.put(HEADER_API_PAYLOAD_VERSION, "4.0"); @@ -637,6 +647,7 @@ public Map getErrorApiHeaders() { * * @return the HTTP headers */ + @NonNull public Map getSessionApiHeaders() { Map map = new HashMap<>(); map.put(HEADER_API_PAYLOAD_VERSION, "1.0"); @@ -666,7 +677,7 @@ public Map getSessionApiHeaders() { * @see BeforeSend * @see Report */ - public void beforeSend(BeforeSend beforeSend) { + public void beforeSend(@NonNull BeforeSend beforeSend) { if (!beforeSendTasks.contains(beforeSend)) { beforeSendTasks.add(beforeSend); } @@ -678,7 +689,7 @@ public void beforeSend(BeforeSend beforeSend) { * @param releaseStage the release stage to check * @return true if the release state should be notified else false */ - protected boolean shouldNotifyForReleaseStage(String releaseStage) { + protected boolean shouldNotifyForReleaseStage(@Nullable String releaseStage) { if (this.notifyReleaseStages == null) { return true; } @@ -693,7 +704,7 @@ protected boolean shouldNotifyForReleaseStage(String releaseStage) { * @param className the exception class to check * @return true if the exception class should be ignored else false */ - protected boolean shouldIgnoreClass(String className) { + protected boolean shouldIgnoreClass(@Nullable String className) { if (this.ignoreClasses == null) { return false; } @@ -707,7 +718,7 @@ protected boolean shouldIgnoreClass(String className) { * * @param beforeNotify the new before notify task */ - protected void beforeNotify(BeforeNotify beforeNotify) { + protected void beforeNotify(@NonNull BeforeNotify beforeNotify) { if (!beforeNotifyTasks.contains(beforeNotify)) { beforeNotifyTasks.add(beforeNotify); } @@ -718,7 +729,7 @@ protected void beforeNotify(BeforeNotify beforeNotify) { * * @param beforeRecordBreadcrumb the new before breadcrumb task */ - protected void beforeRecordBreadcrumb(BeforeRecordBreadcrumb beforeRecordBreadcrumb) { + protected void beforeRecordBreadcrumb(@NonNull BeforeRecordBreadcrumb beforeRecordBreadcrumb) { if (!beforeRecordBreadcrumbTasks.contains(beforeRecordBreadcrumb)) { beforeRecordBreadcrumbTasks.add(beforeRecordBreadcrumb); } @@ -747,6 +758,7 @@ protected boolean inProject(@NonNull String className) { * * @return the before breadcrumb tasks */ + @NonNull protected Collection getBeforeRecordBreadcrumbTasks() { return beforeRecordBreadcrumbTasks; } From d1fefcde96f8aa26ce6fe77b60332f0196e76307 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Wed, 12 Dec 2018 09:21:56 +0000 Subject: [PATCH 05/10] feat: add nullability annotations to NativeInterface class --- sdk/lint-baseline.xml | 328 ------------------ .../com/bugsnag/android/NativeInterface.java | 48 ++- 2 files changed, 31 insertions(+), 345 deletions(-) diff --git a/sdk/lint-baseline.xml b/sdk/lint-baseline.xml index 0c900ea019..bc622dfc5f 100644 --- a/sdk/lint-baseline.xml +++ b/sdk/lint-baseline.xml @@ -1574,335 +1574,7 @@ column="26"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - getBreadcrumbs() { * @param name name */ @SuppressWarnings("unused") - public static void setUser(final String id, - final String email, - final String name) { + public static void setUser(@Nullable final String id, + @Nullable final String email, + @Nullable final String name) { Client client = getClient(); client.setUserId(id); client.setUserEmail(email); @@ -271,7 +278,9 @@ public static void leaveBreadcrumb(@NonNull final String name, /** * Leaves a breadcrumb on the static client instance */ - public static void leaveBreadcrumb(String name, String type, Map metadata) { + public static void leaveBreadcrumb(@NonNull String name, + @NonNull String type, + @NonNull Map metadata) { String typeName = type.toUpperCase(Locale.US); Map map = metadata == null ? new HashMap() : metadata; getClient().leaveBreadcrumb(name, BreadcrumbType.valueOf(typeName), map); @@ -280,22 +289,23 @@ public static void leaveBreadcrumb(String name, String type, Map /** * Add metadata to subsequent exception reports */ - public static void addToTab(final String tab, - final String key, - final Object value) { + public static void addToTab(@NonNull final String tab, + @NonNull final String key, + @Nullable final Object value) { getClient().addToTab(tab, key, value); } /** * Set the client report release stage */ - public static void setReleaseStage(final String stage) { + public static void setReleaseStage(@Nullable final String stage) { getClient().setReleaseStage(stage); } /** * Return the client report release stage */ + @Nullable public static String getReleaseStage() { return getClient().getConfig().getReleaseStage(); } @@ -303,6 +313,7 @@ public static String getReleaseStage() { /** * Return the client session endpoint */ + @NonNull public static String getSessionEndpoint() { return getClient().getConfig().getSessionEndpoint(); } @@ -310,6 +321,7 @@ public static String getSessionEndpoint() { /** * Return the client report endpoint */ + @NonNull public static String getEndpoint() { return getClient().getConfig().getEndpoint(); } @@ -318,7 +330,7 @@ public static String getEndpoint() { * Set the client session endpoint */ @SuppressWarnings("deprecation") - public static void setSessionEndpoint(final String endpoint) { + public static void setSessionEndpoint(@NonNull final String endpoint) { getClient().getConfig().setSessionEndpoint(endpoint); } @@ -326,34 +338,35 @@ public static void setSessionEndpoint(final String endpoint) { * Set the client report endpoint */ @SuppressWarnings("deprecation") - public static void setEndpoint(final String endpoint) { + public static void setEndpoint(@NonNull final String endpoint) { getClient().getConfig().setEndpoint(endpoint); } /** * Set the client report context */ - public static void setContext(final String context) { + public static void setContext(@Nullable final String context) { getClient().setContext(context); } /** * Set the client report app version */ - public static void setAppVersion(final String version) { + public static void setAppVersion(@NonNull final String version) { getClient().setAppVersion(version); } /** * Set the binary arch used in the application */ - public static void setBinaryArch(final String binaryArch) { + public static void setBinaryArch(@NonNull final String binaryArch) { getClient().setBinaryArch(binaryArch); } /** * Return the client report app version */ + @NonNull public static String getAppVersion() { return getClient().getConfig().getAppVersion(); } @@ -361,6 +374,7 @@ public static String getAppVersion() { /** * Return which release stages notify */ + @NonNull public static String[] getNotifyReleaseStages() { return getClient().getConfig().getNotifyReleaseStages(); } @@ -368,7 +382,7 @@ public static String[] getNotifyReleaseStages() { /** * Set which release stages notify */ - public static void setNotifyReleaseStages(String[] notifyReleaseStages) { + public static void setNotifyReleaseStages(@NonNull String[] notifyReleaseStages) { getClient().getConfig().setNotifyReleaseStages(notifyReleaseStages); } @@ -380,7 +394,7 @@ public static void setNotifyReleaseStages(String[] notifyReleaseStages) { * stages */ @SuppressWarnings("unused") - public static void deliverReport(String releaseStage, String payload) { + public static void deliverReport(@Nullable String releaseStage, @NonNull String payload) { Client client = getClient(); if (releaseStage == null || releaseStage.length() == 0 @@ -400,7 +414,7 @@ public static void deliverReport(String releaseStage, String payload) { */ public static void notify(@NonNull final String name, @NonNull final String message, - final Severity severity, + @NonNull final Severity severity, @NonNull final StackTraceElement[] stacktrace) { getClient().notify(name, message, stacktrace, new Callback() { From 181e809f8ef600f6236c1c2a974613237947f27b Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Wed, 12 Dec 2018 09:52:44 +0000 Subject: [PATCH 06/10] feat: add nullability annotations to remaining public sites --- sdk/lint-baseline.xml | 494 ------------------ .../bugsnag/android/BadResponseException.java | 4 +- .../com/bugsnag/android/BeforeNotify.java | 4 +- .../java/com/bugsnag/android/BeforeSend.java | 4 +- .../com/bugsnag/android/BreadcrumbType.java | 5 +- .../com/bugsnag/android/BugsnagException.java | 7 +- .../java/com/bugsnag/android/Callback.java | 4 +- .../com/bugsnag/android/DefaultDelivery.java | 9 +- .../java/com/bugsnag/android/Delivery.java | 10 +- .../com/bugsnag/android/DeliveryCompat.java | 9 +- .../android/DeliveryFailureException.java | 7 +- .../main/java/com/bugsnag/android/Error.java | 14 +- .../bugsnag/android/ErrorReportApiClient.java | 6 +- .../com/bugsnag/android/EventReceiver.java | 4 +- .../java/com/bugsnag/android/JsonStream.java | 2 +- .../java/com/bugsnag/android/MetaData.java | 4 +- .../com/bugsnag/android/NetworkException.java | 5 +- .../java/com/bugsnag/android/NotifyType.java | 2 + .../android/SessionTrackingApiClient.java | 8 +- .../java/com/bugsnag/android/Severity.java | 1 + 20 files changed, 74 insertions(+), 529 deletions(-) diff --git a/sdk/lint-baseline.xml b/sdk/lint-baseline.xml index 0c900ea019..d071408b7d 100644 --- a/sdk/lint-baseline.xml +++ b/sdk/lint-baseline.xml @@ -34,50 +34,6 @@ column="12"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sdk/src/main/java/com/bugsnag/android/BadResponseException.java b/sdk/src/main/java/com/bugsnag/android/BadResponseException.java index f42c62f1b6..81b7642764 100644 --- a/sdk/src/main/java/com/bugsnag/android/BadResponseException.java +++ b/sdk/src/main/java/com/bugsnag/android/BadResponseException.java @@ -1,5 +1,7 @@ package com.bugsnag.android; +import android.support.annotation.NonNull; + import java.util.Locale; /** @@ -10,7 +12,7 @@ public class BadResponseException extends Exception { private static final long serialVersionUID = -870190454845379171L; - public BadResponseException(String msg, int responseCode) { + public BadResponseException(@NonNull String msg, int responseCode) { super(String.format(Locale.US, "%s (%d)", msg, responseCode)); } } diff --git a/sdk/src/main/java/com/bugsnag/android/BeforeNotify.java b/sdk/src/main/java/com/bugsnag/android/BeforeNotify.java index 01112e0dea..a67eb3a359 100644 --- a/sdk/src/main/java/com/bugsnag/android/BeforeNotify.java +++ b/sdk/src/main/java/com/bugsnag/android/BeforeNotify.java @@ -1,5 +1,7 @@ package com.bugsnag.android; +import android.support.annotation.NonNull; + /** * A callback to be run before reports are sent to Bugsnag. *

@@ -18,5 +20,5 @@ public interface BeforeNotify { * @param error the error to be sent to Bugsnag * @see Error */ - boolean run(Error error); + boolean run(@NonNull Error error); } diff --git a/sdk/src/main/java/com/bugsnag/android/BeforeSend.java b/sdk/src/main/java/com/bugsnag/android/BeforeSend.java index e652b49277..41babd2b52 100644 --- a/sdk/src/main/java/com/bugsnag/android/BeforeSend.java +++ b/sdk/src/main/java/com/bugsnag/android/BeforeSend.java @@ -1,5 +1,7 @@ package com.bugsnag.android; +import android.support.annotation.NonNull; + /** * A callback to be run before every report sent to Bugsnag. *

@@ -16,5 +18,5 @@ public interface BeforeSend { * * @param report the {@link Report} to be sent to Bugsnag */ - boolean run(Report report); + boolean run(@NonNull Report report); } diff --git a/sdk/src/main/java/com/bugsnag/android/BreadcrumbType.java b/sdk/src/main/java/com/bugsnag/android/BreadcrumbType.java index 39140de43a..b9408a1f4e 100644 --- a/sdk/src/main/java/com/bugsnag/android/BreadcrumbType.java +++ b/sdk/src/main/java/com/bugsnag/android/BreadcrumbType.java @@ -1,5 +1,7 @@ package com.bugsnag.android; +import android.support.annotation.NonNull; + /** * Recognized types of breadcrumbs */ @@ -40,11 +42,12 @@ public enum BreadcrumbType { private final String type; - BreadcrumbType(String type) { + BreadcrumbType(@NonNull String type) { this.type = type; } @Override + @NonNull public String toString() { return type; } diff --git a/sdk/src/main/java/com/bugsnag/android/BugsnagException.java b/sdk/src/main/java/com/bugsnag/android/BugsnagException.java index 3abe5585b6..25a9dd7b91 100644 --- a/sdk/src/main/java/com/bugsnag/android/BugsnagException.java +++ b/sdk/src/main/java/com/bugsnag/android/BugsnagException.java @@ -1,5 +1,7 @@ package com.bugsnag.android; +import android.support.annotation.NonNull; + /** * Used to store information about an exception that was not provided with an exception object */ @@ -19,7 +21,9 @@ public class BugsnagException extends Throwable { * @param message The exception message * @param frames The exception stack trace */ - public BugsnagException(String name, String message, StackTraceElement[] frames) { + public BugsnagException(@NonNull String name, + @NonNull String message, + @NonNull StackTraceElement[] frames) { super(message); super.setStackTrace(frames); @@ -29,6 +33,7 @@ public BugsnagException(String name, String message, StackTraceElement[] frames) /** * @return The name of the exception (used instead of the exception class) */ + @NonNull public String getName() { return name; } diff --git a/sdk/src/main/java/com/bugsnag/android/Callback.java b/sdk/src/main/java/com/bugsnag/android/Callback.java index 483d89a441..58b20a03a0 100644 --- a/sdk/src/main/java/com/bugsnag/android/Callback.java +++ b/sdk/src/main/java/com/bugsnag/android/Callback.java @@ -1,6 +1,8 @@ package com.bugsnag.android; +import android.support.annotation.NonNull; + /** * A callback to be run before an individual report is sent to Bugsnag. *

@@ -11,5 +13,5 @@ */ public interface Callback { - void beforeNotify(Report report); + void beforeNotify(@NonNull Report report); } diff --git a/sdk/src/main/java/com/bugsnag/android/DefaultDelivery.java b/sdk/src/main/java/com/bugsnag/android/DefaultDelivery.java index fe82d72ba1..76ef349322 100644 --- a/sdk/src/main/java/com/bugsnag/android/DefaultDelivery.java +++ b/sdk/src/main/java/com/bugsnag/android/DefaultDelivery.java @@ -2,6 +2,7 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import java.io.BufferedWriter; @@ -23,8 +24,8 @@ class DefaultDelivery implements Delivery { } @Override - public void deliver(SessionTrackingPayload payload, - Configuration config) throws DeliveryFailureException { + public void deliver(@NonNull SessionTrackingPayload payload, + @NonNull Configuration config) throws DeliveryFailureException { String endpoint = config.getSessionEndpoint(); int status = deliver(endpoint, payload, config.getSessionApiHeaders()); @@ -36,8 +37,8 @@ public void deliver(SessionTrackingPayload payload, } @Override - public void deliver(Report report, - Configuration config) throws DeliveryFailureException { + public void deliver(@NonNull Report report, + @NonNull Configuration config) throws DeliveryFailureException { String endpoint = config.getEndpoint(); int status = deliver(endpoint, report, config.getErrorApiHeaders()); diff --git a/sdk/src/main/java/com/bugsnag/android/Delivery.java b/sdk/src/main/java/com/bugsnag/android/Delivery.java index 2bb75990c2..72222f7acb 100644 --- a/sdk/src/main/java/com/bugsnag/android/Delivery.java +++ b/sdk/src/main/java/com/bugsnag/android/Delivery.java @@ -1,6 +1,8 @@ package com.bugsnag.android; +import android.support.annotation.NonNull; + /** * Implementations of this interface deliver Error Reports and Sessions captured to the Bugsnag API. *

@@ -36,8 +38,8 @@ public interface Delivery { * @throws DeliveryFailureException when delivery is not successful and * the report should be stored for future attempts. */ - void deliver(SessionTrackingPayload payload, - Configuration config) throws DeliveryFailureException; + void deliver(@NonNull SessionTrackingPayload payload, + @NonNull Configuration config) throws DeliveryFailureException; /** * Posts an Error Report to the Bugsnag Error Reporting API. @@ -58,6 +60,6 @@ void deliver(SessionTrackingPayload payload, * @throws DeliveryFailureException when delivery is not successful and * the report should be stored for future attempts. */ - void deliver(Report report, - Configuration config) throws DeliveryFailureException; + void deliver(@NonNull Report report, + @NonNull Configuration config) throws DeliveryFailureException; } diff --git a/sdk/src/main/java/com/bugsnag/android/DeliveryCompat.java b/sdk/src/main/java/com/bugsnag/android/DeliveryCompat.java index 98edd77674..b711c7aa65 100644 --- a/sdk/src/main/java/com/bugsnag/android/DeliveryCompat.java +++ b/sdk/src/main/java/com/bugsnag/android/DeliveryCompat.java @@ -1,5 +1,7 @@ package com.bugsnag.android; +import android.support.annotation.NonNull; + /** * A compatibility implementation of {@link Delivery} which wraps {@link ErrorReportApiClient} and * {@link SessionTrackingApiClient}. This class allows for backwards compatibility for users still @@ -15,8 +17,8 @@ class DeliveryCompat implements Delivery { volatile SessionTrackingApiClient sessionTrackingApiClient; @Override - public void deliver(SessionTrackingPayload payload, - Configuration config) throws DeliveryFailureException { + public void deliver(@NonNull SessionTrackingPayload payload, + @NonNull Configuration config) throws DeliveryFailureException { if (sessionTrackingApiClient != null) { try { sessionTrackingApiClient.postSessionTrackingPayload(config.getSessionEndpoint(), @@ -28,7 +30,8 @@ public void deliver(SessionTrackingPayload payload, } @Override - public void deliver(Report report, Configuration config) throws DeliveryFailureException { + public void deliver(@NonNull Report report, + @NonNull Configuration config) throws DeliveryFailureException { if (errorReportApiClient != null) { try { errorReportApiClient.postReport(config.getEndpoint(), diff --git a/sdk/src/main/java/com/bugsnag/android/DeliveryFailureException.java b/sdk/src/main/java/com/bugsnag/android/DeliveryFailureException.java index 25315c9f1b..8b33e257e9 100644 --- a/sdk/src/main/java/com/bugsnag/android/DeliveryFailureException.java +++ b/sdk/src/main/java/com/bugsnag/android/DeliveryFailureException.java @@ -1,5 +1,8 @@ package com.bugsnag.android; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + /** * This should be thrown if delivery of a request was not successful and you wish to try again * later. The notifier will cache the payload and initiate delivery at a future time. @@ -10,11 +13,11 @@ public class DeliveryFailureException extends Exception { private static final long serialVersionUID = 1501477209400426470L; - public DeliveryFailureException(String message) { + public DeliveryFailureException(@NonNull String message) { super(message); } - public DeliveryFailureException(String message, Throwable cause) { + public DeliveryFailureException(@NonNull String message, @Nullable Throwable cause) { super(message, cause); } } diff --git a/sdk/src/main/java/com/bugsnag/android/Error.java b/sdk/src/main/java/com/bugsnag/android/Error.java index 246aa07f59..66999cb758 100644 --- a/sdk/src/main/java/com/bugsnag/android/Error.java +++ b/sdk/src/main/java/com/bugsnag/android/Error.java @@ -191,7 +191,7 @@ public Severity getSeverity() { * @param email the email address of the user * @param name the name of the user */ - public void setUser(String id, String email, String name) { + public void setUser(@Nullable String id, @Nullable String email, @Nullable String name) { this.user = new User(id, email, name); } @@ -212,7 +212,7 @@ public User getUser() { * * @param id the id of the user */ - public void setUserId(String id) { + public void setUserId(@Nullable String id) { this.user = new User(this.user); this.user.setId(id); } @@ -222,7 +222,7 @@ public void setUserId(String id) { * * @param email the email address of the user */ - public void setUserEmail(String email) { + public void setUserEmail(@Nullable String email) { this.user = new User(this.user); this.user.setEmail(email); } @@ -232,7 +232,7 @@ public void setUserEmail(String email) { * * @param name the name of the user */ - public void setUserName(String name) { + public void setUserName(@Nullable String name) { this.user = new User(this.user); this.user.setName(name); } @@ -250,7 +250,7 @@ public void setUserName(String name) { * @param key the name of the diagnostic information * @param value the contents of the diagnostic information */ - public void addToTab(String tabName, String key, Object value) { + public void addToTab(@NonNull String tabName, @NonNull String key, @Nullable Object value) { metaData.addToTab(tabName, key, value); } @@ -259,7 +259,7 @@ public void addToTab(String tabName, String key, Object value) { * * @param tabName the dashboard tab to remove diagnostic data from */ - public void clearTab(String tabName) { + public void clearTab(@NonNull String tabName) { metaData.clearTab(tabName); } @@ -299,6 +299,7 @@ public void setMetaData(@NonNull MetaData metaData) { /** * Get the class name from the exception contained in this Error report. */ + @NonNull public String getExceptionName() { if (exception instanceof BugsnagException) { return ((BugsnagException) exception).getName(); @@ -319,6 +320,7 @@ public String getExceptionMessage() { /** * The {@linkplain Throwable exception} which triggered this Error report. */ + @NonNull public Throwable getException() { return exception; } diff --git a/sdk/src/main/java/com/bugsnag/android/ErrorReportApiClient.java b/sdk/src/main/java/com/bugsnag/android/ErrorReportApiClient.java index d3791806b8..9efd125bb2 100644 --- a/sdk/src/main/java/com/bugsnag/android/ErrorReportApiClient.java +++ b/sdk/src/main/java/com/bugsnag/android/ErrorReportApiClient.java @@ -1,5 +1,7 @@ package com.bugsnag.android; +import android.support.annotation.NonNull; + import java.util.Map; /** @@ -26,7 +28,9 @@ public interface ErrorReportApiClient { * @throws NetworkException if the client was unable to complete the request * @throws BadResponseException when a non-200 response code is received from the server */ - void postReport(String urlString, Report report, Map headers) + void postReport(@NonNull String urlString, + @NonNull Report report, + @NonNull Map headers) throws NetworkException, BadResponseException; } diff --git a/sdk/src/main/java/com/bugsnag/android/EventReceiver.java b/sdk/src/main/java/com/bugsnag/android/EventReceiver.java index bf877b75f6..40820064a3 100644 --- a/sdk/src/main/java/com/bugsnag/android/EventReceiver.java +++ b/sdk/src/main/java/com/bugsnag/android/EventReceiver.java @@ -25,12 +25,12 @@ public class EventReceiver extends BroadcastReceiver { private final Client client; - public EventReceiver(Client client) { + public EventReceiver(@NonNull Client client) { this.client = client; } @Override - public void onReceive(Context context, @NonNull Intent intent) { + public void onReceive(@NonNull Context context, @NonNull Intent intent) { try { Map meta = new HashMap<>(); String fullAction = intent.getAction(); diff --git a/sdk/src/main/java/com/bugsnag/android/JsonStream.java b/sdk/src/main/java/com/bugsnag/android/JsonStream.java index 291126cbf8..89bd103456 100644 --- a/sdk/src/main/java/com/bugsnag/android/JsonStream.java +++ b/sdk/src/main/java/com/bugsnag/android/JsonStream.java @@ -26,7 +26,7 @@ public interface Streamable { * * @param out the writer */ - public JsonStream(Writer out) { + public JsonStream(@NonNull Writer out) { super(out); setSerializeNulls(false); this.out = out; diff --git a/sdk/src/main/java/com/bugsnag/android/MetaData.java b/sdk/src/main/java/com/bugsnag/android/MetaData.java index 4b440fe9db..026bcbdc20 100644 --- a/sdk/src/main/java/com/bugsnag/android/MetaData.java +++ b/sdk/src/main/java/com/bugsnag/android/MetaData.java @@ -57,7 +57,7 @@ public void toStream(@NonNull JsonStream writer) throws IOException { * @param key the name of the diagnostic information * @param value the contents of the diagnostic information */ - public void addToTab(String tabName, String key, Object value) { + public void addToTab(@NonNull String tabName, @NonNull String key, @Nullable Object value) { Map tab = getTab(tabName); setChanged(); if (value != null) { @@ -78,7 +78,7 @@ public void addToTab(String tabName, String key, Object value) { * * @param tabName the dashboard tab to remove diagnostic data from */ - public void clearTab(String tabName) { + public void clearTab(@NonNull String tabName) { store.remove(tabName); setChanged(); notifyObservers(new NativeInterface.Message( diff --git a/sdk/src/main/java/com/bugsnag/android/NetworkException.java b/sdk/src/main/java/com/bugsnag/android/NetworkException.java index 3c08e17d48..d8d06ba493 100644 --- a/sdk/src/main/java/com/bugsnag/android/NetworkException.java +++ b/sdk/src/main/java/com/bugsnag/android/NetworkException.java @@ -1,5 +1,8 @@ package com.bugsnag.android; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + import java.io.IOException; /** @@ -10,7 +13,7 @@ public class NetworkException extends IOException { private static final long serialVersionUID = -4370366096145029322L; - public NetworkException(String msg, Throwable cause) { + public NetworkException(@NonNull String msg, @Nullable Throwable cause) { super(msg, cause); } } diff --git a/sdk/src/main/java/com/bugsnag/android/NotifyType.java b/sdk/src/main/java/com/bugsnag/android/NotifyType.java index 9a9035c31c..f1f19e06ac 100644 --- a/sdk/src/main/java/com/bugsnag/android/NotifyType.java +++ b/sdk/src/main/java/com/bugsnag/android/NotifyType.java @@ -1,5 +1,6 @@ package com.bugsnag.android; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; /** @@ -23,6 +24,7 @@ public enum NotifyType { this.intValue = intValue; } + @NonNull public Integer getValue() { return intValue; } diff --git a/sdk/src/main/java/com/bugsnag/android/SessionTrackingApiClient.java b/sdk/src/main/java/com/bugsnag/android/SessionTrackingApiClient.java index 173cdb0f1f..d270df90a6 100644 --- a/sdk/src/main/java/com/bugsnag/android/SessionTrackingApiClient.java +++ b/sdk/src/main/java/com/bugsnag/android/SessionTrackingApiClient.java @@ -1,5 +1,7 @@ package com.bugsnag.android; +import android.support.annotation.NonNull; + import java.util.Map; /** @@ -22,9 +24,9 @@ public interface SessionTrackingApiClient { * @throws NetworkException if the client was unable to complete the request * @throws BadResponseException when a non-202 response code is received from the server */ - void postSessionTrackingPayload(String urlString, - SessionTrackingPayload payload, - Map headers) + void postSessionTrackingPayload(@NonNull String urlString, + @NonNull SessionTrackingPayload payload, + @NonNull Map headers) throws NetworkException, BadResponseException; } diff --git a/sdk/src/main/java/com/bugsnag/android/Severity.java b/sdk/src/main/java/com/bugsnag/android/Severity.java index 09bfb3da52..5d300875dc 100644 --- a/sdk/src/main/java/com/bugsnag/android/Severity.java +++ b/sdk/src/main/java/com/bugsnag/android/Severity.java @@ -39,6 +39,7 @@ static Severity fromString(String input) { } } + @NonNull public String getName() { return name; } From ebab41a4c9ed74d4f5b89c2adeca0e3f09058aa0 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Thu, 13 Dec 2018 09:04:37 +0000 Subject: [PATCH 07/10] feat: update mazerunner delivery signatures to use non-null parameters --- .../com/bugsnag/android/TestHarnessHooks.kt | 20 +++++++++---------- .../android/mazerunner/scenarios/Scenario.kt | 12 +++++------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/TestHarnessHooks.kt b/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/TestHarnessHooks.kt index 98bea56795..fa6666ba5c 100644 --- a/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/TestHarnessHooks.kt +++ b/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/TestHarnessHooks.kt @@ -26,12 +26,12 @@ internal fun createSlowDelivery(context: Context): Delivery { val delivery = DefaultDelivery(cm) return object : Delivery { - override fun deliver(payload: SessionTrackingPayload?, config: Configuration?) { + override fun deliver(payload: SessionTrackingPayload, config: Configuration) { Thread.sleep(500) delivery.deliver(payload, config) } - override fun deliver(report: Report?, config: Configuration?) { + override fun deliver(report: Report, config: Configuration) { Thread.sleep(500) delivery.deliver(report, config) } @@ -47,18 +47,18 @@ internal fun createCustomHeaderDelivery(context: Context): Delivery { return object : Delivery { val delivery: DefaultDelivery = createDefaultDelivery(context) - override fun deliver(payload: SessionTrackingPayload?, config: Configuration?) { - deliver(config?.sessionEndpoint, payload, config?.sessionApiHeaders) + override fun deliver(payload: SessionTrackingPayload, config: Configuration) { + deliver(config.sessionEndpoint, payload, config.sessionApiHeaders) } - override fun deliver(report: Report?, config: Configuration?) { - deliver(config?.endpoint, report, config?.errorApiHeaders) + override fun deliver(report: Report, config: Configuration) { + deliver(config.endpoint, report, config.errorApiHeaders) } - fun deliver(endpoint: String?, - streamable: JsonStream.Streamable?, - headers: MutableMap?) { - headers!!["Custom-Client"] = "Hello World" + fun deliver(endpoint: String, + streamable: JsonStream.Streamable, + headers: MutableMap) { + headers["Custom-Client"] = "Hello World" delivery.deliver(endpoint, streamable, headers) } } diff --git a/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/Scenario.kt b/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/Scenario.kt index 7e962d13a2..a7e132df87 100644 --- a/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/Scenario.kt +++ b/features/fixtures/mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/Scenario.kt @@ -18,11 +18,11 @@ abstract internal class Scenario(protected val config: Configuration, protected fun disableSessionDelivery() { val baseDelivery = Bugsnag.getClient().config.delivery Bugsnag.getClient().config.delivery = object: Delivery { - override fun deliver(payload: SessionTrackingPayload?, config: Configuration?) { + override fun deliver(payload: SessionTrackingPayload, config: Configuration) { throw DeliveryFailureException("Session Delivery NOP", RuntimeException("NOP")) } - override fun deliver(report: Report?, config: Configuration?) { + override fun deliver(report: Report, config: Configuration) { baseDelivery.deliver(report, config) } } @@ -34,11 +34,11 @@ abstract internal class Scenario(protected val config: Configuration, protected fun disableReportDelivery() { val baseDelivery = Bugsnag.getClient().config.delivery Bugsnag.getClient().config.delivery = object: Delivery { - override fun deliver(payload: SessionTrackingPayload?, config: Configuration?) { + override fun deliver(payload: SessionTrackingPayload, config: Configuration) { baseDelivery.deliver(payload, config) } - override fun deliver(report: Report?, config: Configuration?) { + override fun deliver(report: Report, config: Configuration) { throw DeliveryFailureException("Session Delivery NOP", RuntimeException("NOP")) } } @@ -57,11 +57,11 @@ abstract internal class Scenario(protected val config: Configuration, protected fun disableAllDelivery(config: Configuration) { config.delivery = object: Delivery { - override fun deliver(payload: SessionTrackingPayload?, config: Configuration?) { + override fun deliver(payload: SessionTrackingPayload, config: Configuration) { throw DeliveryFailureException("Error Delivery NOP", RuntimeException("NOP")) } - override fun deliver(report: Report?, config: Configuration?) { + override fun deliver(report: Report, config: Configuration) { throw DeliveryFailureException("Session Delivery NOP", RuntimeException("NOP")) } } From 18c5b5a8127ad86f40a52917c535248cf043f2e5 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Thu, 13 Dec 2018 14:19:55 +0000 Subject: [PATCH 08/10] feat: add nullability annotations to missed getters --- sdk/src/main/java/com/bugsnag/android/Configuration.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/src/main/java/com/bugsnag/android/Configuration.java b/sdk/src/main/java/com/bugsnag/android/Configuration.java index 97830011b3..e85b78618a 100644 --- a/sdk/src/main/java/com/bugsnag/android/Configuration.java +++ b/sdk/src/main/java/com/bugsnag/android/Configuration.java @@ -575,10 +575,12 @@ public void setCodeBundleId(@Nullable String codeBundleId) { this.codeBundleId = codeBundleId; } + @Nullable public String getCodeBundleId() { return codeBundleId; } + @NonNull public String getNotifierType() { return notifierType; } From 55f1577736fe9ede304f218ff575c3f756b0ccce Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Fri, 14 Dec 2018 14:21:45 +0000 Subject: [PATCH 09/10] feat: final adjustments of nullability annotations on second sweep --- sdk/src/main/java/com/bugsnag/android/Bugsnag.java | 8 ++++---- sdk/src/main/java/com/bugsnag/android/Client.java | 8 ++++---- .../main/java/com/bugsnag/android/Configuration.java | 10 +++++----- .../main/java/com/bugsnag/android/NativeInterface.java | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sdk/src/main/java/com/bugsnag/android/Bugsnag.java b/sdk/src/main/java/com/bugsnag/android/Bugsnag.java index 3b18121f59..1a0dbdf1dc 100644 --- a/sdk/src/main/java/com/bugsnag/android/Bugsnag.java +++ b/sdk/src/main/java/com/bugsnag/android/Bugsnag.java @@ -151,7 +151,7 @@ public static void setBuildUUID(@Nullable final String buildUuid) { * * @param filters a list of keys to filter from metaData */ - public static void setFilters(@NonNull final String... filters) { + public static void setFilters(@Nullable final String... filters) { getClient().setFilters(filters); } @@ -164,7 +164,7 @@ public static void setFilters(@NonNull final String... filters) { * * @param ignoreClasses a list of exception classes to ignore */ - public static void setIgnoreClasses(@NonNull final String... ignoreClasses) { + public static void setIgnoreClasses(@Nullable final String... ignoreClasses) { getClient().setIgnoreClasses(ignoreClasses); } @@ -179,7 +179,7 @@ public static void setIgnoreClasses(@NonNull final String... ignoreClasses) { * @param notifyReleaseStages a list of releaseStages to notify for * @see #setReleaseStage */ - public static void setNotifyReleaseStages(@NonNull final String... notifyReleaseStages) { + public static void setNotifyReleaseStages(@Nullable final String... notifyReleaseStages) { getClient().setNotifyReleaseStages(notifyReleaseStages); } @@ -195,7 +195,7 @@ public static void setNotifyReleaseStages(@NonNull final String... notifyRelease * * @param projectPackages a list of package names */ - public static void setProjectPackages(@NonNull final String... projectPackages) { + public static void setProjectPackages(@Nullable final String... projectPackages) { getClient().setProjectPackages(projectPackages); } diff --git a/sdk/src/main/java/com/bugsnag/android/Client.java b/sdk/src/main/java/com/bugsnag/android/Client.java index fdd91baa9c..ef9ac11af0 100644 --- a/sdk/src/main/java/com/bugsnag/android/Client.java +++ b/sdk/src/main/java/com/bugsnag/android/Client.java @@ -370,7 +370,7 @@ public void setBuildUUID(@Nullable final String buildUuid) { * * @param filters a list of keys to filter from metaData */ - public void setFilters(@NonNull String... filters) { + public void setFilters(@Nullable String... filters) { config.setFilters(filters); } @@ -383,7 +383,7 @@ public void setFilters(@NonNull String... filters) { * * @param ignoreClasses a list of exception classes to ignore */ - public void setIgnoreClasses(@NonNull String... ignoreClasses) { + public void setIgnoreClasses(@Nullable String... ignoreClasses) { config.setIgnoreClasses(ignoreClasses); } @@ -398,7 +398,7 @@ public void setIgnoreClasses(@NonNull String... ignoreClasses) { * @param notifyReleaseStages a list of releaseStages to notify for * @see #setReleaseStage */ - public void setNotifyReleaseStages(@NonNull String... notifyReleaseStages) { + public void setNotifyReleaseStages(@Nullable String... notifyReleaseStages) { config.setNotifyReleaseStages(notifyReleaseStages); } @@ -414,7 +414,7 @@ public void setNotifyReleaseStages(@NonNull String... notifyReleaseStages) { * * @param projectPackages a list of package names */ - public void setProjectPackages(@NonNull String... projectPackages) { + public void setProjectPackages(@Nullable String... projectPackages) { config.setProjectPackages(projectPackages); } diff --git a/sdk/src/main/java/com/bugsnag/android/Configuration.java b/sdk/src/main/java/com/bugsnag/android/Configuration.java index e85b78618a..7dbd5bc0c6 100644 --- a/sdk/src/main/java/com/bugsnag/android/Configuration.java +++ b/sdk/src/main/java/com/bugsnag/android/Configuration.java @@ -252,7 +252,7 @@ public void setBuildUUID(@Nullable String buildUuid) { * * @return Filters */ - @NonNull + @Nullable public String[] getFilters() { return metaData.getFilters(); } @@ -270,7 +270,7 @@ public String[] getFilters() { * * @param filters a list of keys to filter from metaData */ - public void setFilters(@NonNull String[] filters) { + public void setFilters(@Nullable String[] filters) { this.metaData.setFilters(filters); } @@ -293,7 +293,7 @@ public String[] getIgnoreClasses() { * * @param ignoreClasses a list of exception classes to ignore */ - public void setIgnoreClasses(@NonNull String[] ignoreClasses) { + public void setIgnoreClasses(@Nullable String[] ignoreClasses) { this.ignoreClasses = ignoreClasses; } @@ -318,7 +318,7 @@ public String[] getNotifyReleaseStages() { * @param notifyReleaseStages a list of releaseStages to notify for * @see #setReleaseStage */ - public void setNotifyReleaseStages(@NonNull String[] notifyReleaseStages) { + public void setNotifyReleaseStages(@Nullable String[] notifyReleaseStages) { this.notifyReleaseStages = notifyReleaseStages; } @@ -344,7 +344,7 @@ public String[] getProjectPackages() { * * @param projectPackages a list of package names */ - public void setProjectPackages(@NonNull String[] projectPackages) { + public void setProjectPackages(@Nullable String[] projectPackages) { this.projectPackages = projectPackages; } diff --git a/sdk/src/main/java/com/bugsnag/android/NativeInterface.java b/sdk/src/main/java/com/bugsnag/android/NativeInterface.java index 9a58878908..4f552b234f 100644 --- a/sdk/src/main/java/com/bugsnag/android/NativeInterface.java +++ b/sdk/src/main/java/com/bugsnag/android/NativeInterface.java @@ -374,7 +374,7 @@ public static String getAppVersion() { /** * Return which release stages notify */ - @NonNull + @Nullable public static String[] getNotifyReleaseStages() { return getClient().getConfig().getNotifyReleaseStages(); } @@ -382,7 +382,7 @@ public static String[] getNotifyReleaseStages() { /** * Set which release stages notify */ - public static void setNotifyReleaseStages(@NonNull String[] notifyReleaseStages) { + public static void setNotifyReleaseStages(@Nullable String[] notifyReleaseStages) { getClient().getConfig().setNotifyReleaseStages(notifyReleaseStages); } From 194f576c70d8f9df8b9278abca560fa8bd45d8d4 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Mon, 17 Dec 2018 10:46:10 +0000 Subject: [PATCH 10/10] docs: add changelog entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f432f1ade2..71476aa148 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 4.X.X (TBD) +* Added additional nullability annotations to public API + [#395](https://github.com/bugsnag/bugsnag-android/pull/395) + ### Bug fixes * Add binary architecture of application to payload