diff --git a/mazerunner/src/main/java/com/bugsnag/android/TestHarnessHooks.kt b/mazerunner/src/main/java/com/bugsnag/android/TestHarnessHooks.kt index 9a3d2ce91c..98bea56795 100644 --- a/mazerunner/src/main/java/com/bugsnag/android/TestHarnessHooks.kt +++ b/mazerunner/src/main/java/com/bugsnag/android/TestHarnessHooks.kt @@ -67,6 +67,6 @@ internal fun createCustomHeaderDelivery(context: Context): Delivery { internal fun writeErrorToStore(client: Client) { val error = Error.Builder(Configuration("api-key"), RuntimeException(), null, - Thread.currentThread()).build() + Thread.currentThread(), false).build() client.errorStore.write(error) } diff --git a/sdk/src/androidTest/java/com/bugsnag/android/BeforeNotifyTest.kt b/sdk/src/androidTest/java/com/bugsnag/android/BeforeNotifyTest.kt index 1132f9ce5b..279cc061ff 100644 --- a/sdk/src/androidTest/java/com/bugsnag/android/BeforeNotifyTest.kt +++ b/sdk/src/androidTest/java/com/bugsnag/android/BeforeNotifyTest.kt @@ -24,7 +24,7 @@ class BeforeNotifyTest { } val error = Error.Builder(config, RuntimeException("Test"), null, - Thread.currentThread()).build() + Thread.currentThread(), false).build() beforeNotify.run(error) assertEquals(context, error.context) } diff --git a/sdk/src/androidTest/java/com/bugsnag/android/ErrorStoreTest.java b/sdk/src/androidTest/java/com/bugsnag/android/ErrorStoreTest.java index eddf017cfb..6b84c75f01 100644 --- a/sdk/src/androidTest/java/com/bugsnag/android/ErrorStoreTest.java +++ b/sdk/src/androidTest/java/com/bugsnag/android/ErrorStoreTest.java @@ -72,7 +72,7 @@ public void testWrite() throws Exception { @NonNull private Error writeErrorToStore() { Error error = new Error.Builder(config, new RuntimeException(), - null, Thread.currentThread()).build(); + null, Thread.currentThread(), false).build(); errorStore.write(error); return error; } diff --git a/sdk/src/androidTest/java/com/bugsnag/android/ErrorTest.java b/sdk/src/androidTest/java/com/bugsnag/android/ErrorTest.java index 082eb846a2..f35bfa1bef 100644 --- a/sdk/src/androidTest/java/com/bugsnag/android/ErrorTest.java +++ b/sdk/src/androidTest/java/com/bugsnag/android/ErrorTest.java @@ -41,7 +41,7 @@ public class ErrorTest { public void setUp() throws Exception { config = new Configuration("api-key"); RuntimeException exception = new RuntimeException("Example message"); - error = new Error.Builder(config, exception, null, Thread.currentThread()).build(); + error = new Error.Builder(config, exception, null, Thread.currentThread(), false).build(); } @After @@ -56,13 +56,13 @@ public void testShouldIgnoreClass() { // Shouldn't ignore classes not in ignoreClasses RuntimeException runtimeException = new RuntimeException("Test"); Error error = new Error.Builder(config, - runtimeException, null, Thread.currentThread()).build(); + runtimeException, null, Thread.currentThread(), false).build(); assertFalse(error.shouldIgnoreClass()); // Should ignore errors in ignoreClasses IOException ioException = new IOException("Test"); error = new Error.Builder(config, - ioException, null, Thread.currentThread()).build(); + ioException, null, Thread.currentThread(), false).build(); assertTrue(error.shouldIgnoreClass()); } @@ -94,7 +94,7 @@ public void testBasicSerialization() throws JSONException, IOException { @Test public void testHandledSerialisation() throws Exception { Error err = new Error.Builder(config, - new RuntimeException(), null, Thread.currentThread()) + new RuntimeException(), null, Thread.currentThread(), false) .severityReasonType(HandledState.REASON_HANDLED_EXCEPTION) .build(); @@ -112,7 +112,7 @@ public void testHandledSerialisation() throws Exception { @Test public void testUnhandledSerialisation() throws Exception { Error err = new Error.Builder(config, - new RuntimeException(), null, Thread.currentThread()) + new RuntimeException(), null, Thread.currentThread(), false) .severityReasonType(HandledState.REASON_UNHANDLED_EXCEPTION) .severity(Severity.ERROR) .build(); @@ -131,7 +131,7 @@ public void testUnhandledSerialisation() throws Exception { @Test public void testPromiseRejectionSerialisation() throws Exception { Error err = new Error.Builder(config, - new RuntimeException(), null, Thread.currentThread()) + new RuntimeException(), null, Thread.currentThread(), false) .severityReasonType(HandledState.REASON_PROMISE_REJECTION) .severity(Severity.ERROR) .build(); @@ -150,7 +150,7 @@ public void testPromiseRejectionSerialisation() throws Exception { @Test public void testLogSerialisation() throws Exception { Error err = new Error.Builder(config, - new RuntimeException(), null, Thread.currentThread()) + new RuntimeException(), null, Thread.currentThread(), false) .severityReasonType(HandledState.REASON_LOG) .severity(Severity.WARNING) .attributeValue("warning") @@ -186,7 +186,7 @@ public void testUserSpecifiedSerialisation() throws Exception { @Test public void testStrictModeSerialisation() throws Exception { Error err = new Error.Builder(config, - new RuntimeException(), null, Thread.currentThread()) + new RuntimeException(), null, Thread.currentThread(), false) .severityReasonType(HandledState.REASON_STRICT_MODE) .attributeValue("Test") .build(); @@ -252,7 +252,7 @@ public void testSetSeverity() throws JSONException, IOException { public void testSessionIncluded() throws Exception { Session session = generateSession(); Error err = new Error.Builder(config, - new RuntimeException(), session, Thread.currentThread()).build(); + new RuntimeException(), session, Thread.currentThread(), false).build(); JSONObject errorJson = streamableToJson(err); assertNotNull(errorJson); @@ -273,7 +273,7 @@ public void testSessionIncluded() throws Exception { @Test(expected = JSONException.class) public void testSessionExcluded() throws Exception { Error err = new Error.Builder(config, - new RuntimeException(), null, Thread.currentThread()).build(); + new RuntimeException(), null, Thread.currentThread(), false).build(); JSONObject errorJson = streamableToJson(err); assertNotNull(errorJson); @@ -284,11 +284,11 @@ public void testSessionExcluded() throws Exception { public void checkExceptionMessageNullity() throws Exception { String msg = "Foo"; Error err = new Error.Builder(config, - new RuntimeException(msg), null, Thread.currentThread()).build(); + new RuntimeException(msg), null, Thread.currentThread(), false).build(); assertEquals(msg, err.getExceptionMessage()); err = new Error.Builder(config, - new RuntimeException(), null, Thread.currentThread()).build(); + new RuntimeException(), null, Thread.currentThread(), false).build(); assertEquals("", err.getExceptionMessage()); } @@ -310,7 +310,7 @@ public void testBugsnagExceptionName() throws Exception { BugsnagException exception = new BugsnagException("Busgang", "exceptional", new StackTraceElement[]{}); Error err = new Error.Builder(config, - exception, null, Thread.currentThread()).build(); + exception, null, Thread.currentThread(), false).build(); assertEquals("Busgang", err.getExceptionName()); } @@ -370,7 +370,7 @@ public void testSetUser() throws Exception { public void testBuilderMetaData() { Configuration config = new Configuration("api-key"); Error.Builder builder = new Error.Builder(config, - new RuntimeException("foo"), null, Thread.currentThread()); + new RuntimeException("foo"), null, Thread.currentThread(), false); assertNotNull(builder.metaData(new MetaData()).build()); @@ -414,7 +414,8 @@ public void testBuilderNullSession() throws Throwable { Session session = generateSession(); session.setAutoCaptured(true); - error = new Error.Builder(config, exception, session, Thread.currentThread()).build(); + error = new Error.Builder(config, exception, session, + Thread.currentThread(), false).build(); JSONObject errorJson = streamableToJson(error); assertFalse(errorJson.has("session")); diff --git a/sdk/src/androidTest/java/com/bugsnag/android/NullMetadataTest.java b/sdk/src/androidTest/java/com/bugsnag/android/NullMetadataTest.java index 0e03cdba01..7ec7736467 100644 --- a/sdk/src/androidTest/java/com/bugsnag/android/NullMetadataTest.java +++ b/sdk/src/androidTest/java/com/bugsnag/android/NullMetadataTest.java @@ -42,7 +42,8 @@ public void tearDown() throws Exception { @Test public void testErrorDefaultMetaData() throws Exception { - Error error = new Error.Builder(config, throwable, null, Thread.currentThread()).build(); + Error error = new Error.Builder(config, throwable, null, + Thread.currentThread(), false).build(); validateDefaultMetadata(error.getMetaData()); } @@ -56,7 +57,8 @@ public void testSecondErrorDefaultMetaData() throws Exception { @Test public void testErrorSetMetadataRef() throws Exception { - Error error = new Error.Builder(config, throwable, null, Thread.currentThread()).build(); + Error error = new Error.Builder(config, throwable, null, + Thread.currentThread(), false).build(); MetaData metaData = new MetaData(); metaData.addToTab(TAB_KEY, "test", "data"); error.setMetaData(metaData); @@ -65,7 +67,8 @@ public void testErrorSetMetadataRef() throws Exception { @Test public void testErrorSetNullMetadata() throws Exception { - Error error = new Error.Builder(config, throwable, null, Thread.currentThread()).build(); + Error error = new Error.Builder(config, throwable, null, + Thread.currentThread(), false).build(); error.setMetaData(null); validateDefaultMetadata(error.getMetaData()); } @@ -99,7 +102,7 @@ public boolean run(Error error) { } }); Error error = new Error.Builder(config, new Throwable(), - null, Thread.currentThread()).build(); + null, Thread.currentThread(), false).build(); Client client = Bugsnag.getClient(); client.notify(error, DeliveryStyle.SAME_THREAD, null); } diff --git a/sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java b/sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java index 5a32c3b063..10e4a76e52 100644 --- a/sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java +++ b/sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java @@ -31,7 +31,8 @@ public class ReportTest { public void setUp() throws Exception { Configuration config = new Configuration("example-api-key"); RuntimeException exception = new RuntimeException("Something broke"); - Error error = new Error.Builder(config, exception, null, Thread.currentThread()).build(); + Error error = new Error.Builder(config, exception, null, + Thread.currentThread(), false).build(); report = new Report("api-key", error); } diff --git a/sdk/src/main/java/com/bugsnag/android/Client.java b/sdk/src/main/java/com/bugsnag/android/Client.java index 64e1d8896e..7a8dd329c9 100644 --- a/sdk/src/main/java/com/bugsnag/android/Client.java +++ b/sdk/src/main/java/com/bugsnag/android/Client.java @@ -762,7 +762,7 @@ public void beforeRecordBreadcrumb(BeforeRecordBreadcrumb beforeRecordBreadcrumb */ public void notify(@NonNull Throwable exception) { Error error = new Error.Builder(config, exception, sessionTracker.getCurrentSession(), - Thread.currentThread()) + Thread.currentThread(), false) .severityReasonType(HandledState.REASON_HANDLED_EXCEPTION) .build(); notify(error, !BLOCKING); @@ -777,7 +777,7 @@ public void notify(@NonNull Throwable exception) { */ public void notify(@NonNull Throwable exception, Callback callback) { Error error = new Error.Builder(config, exception, sessionTracker.getCurrentSession(), - Thread.currentThread()) + Thread.currentThread(), false) .severityReasonType(HandledState.REASON_HANDLED_EXCEPTION) .build(); notify(error, DeliveryStyle.ASYNC, callback); @@ -812,7 +812,7 @@ public void notify(@NonNull String name, */ public void notify(@NonNull Throwable exception, Severity severity) { Error error = new Error.Builder(config, exception, sessionTracker.getCurrentSession(), - Thread.currentThread()) + Thread.currentThread(), false) .severity(severity) .build(); notify(error, !BLOCKING); @@ -829,7 +829,7 @@ public void notify(@NonNull Throwable exception, Severity severity) { public void notify(@NonNull Throwable exception, @NonNull MetaData metaData) { Error error = new Error.Builder(config, exception, sessionTracker.getCurrentSession(), - Thread.currentThread()) + Thread.currentThread(), false) .metaData(metaData) .severityReasonType(HandledState.REASON_HANDLED_EXCEPTION) .build(); @@ -849,7 +849,7 @@ public void notify(@NonNull Throwable exception, public void notify(@NonNull Throwable exception, Severity severity, @NonNull MetaData metaData) { Error error = new Error.Builder(config, exception, sessionTracker.getCurrentSession(), - Thread.currentThread()) + Thread.currentThread(), false) .metaData(metaData) .severity(severity) .build(); @@ -1011,7 +1011,7 @@ public void run() { */ public void notifyBlocking(@NonNull Throwable exception) { Error error = new Error.Builder(config, exception, sessionTracker.getCurrentSession(), - Thread.currentThread()) + Thread.currentThread(), false) .severityReasonType(HandledState.REASON_HANDLED_EXCEPTION) .build(); notify(error, BLOCKING); @@ -1026,7 +1026,7 @@ public void notifyBlocking(@NonNull Throwable exception) { */ public void notifyBlocking(@NonNull Throwable exception, Callback callback) { Error error = new Error.Builder(config, exception, sessionTracker.getCurrentSession(), - Thread.currentThread()) + Thread.currentThread(), false) .severityReasonType(HandledState.REASON_HANDLED_EXCEPTION) .build(); notify(error, DeliveryStyle.SAME_THREAD, callback); @@ -1063,7 +1063,7 @@ public void notifyBlocking(@NonNull String name, public void notifyBlocking(@NonNull Throwable exception, @NonNull MetaData metaData) { Error error = new Error.Builder(config, exception, sessionTracker.getCurrentSession(), - Thread.currentThread()) + Thread.currentThread(), false) .severityReasonType(HandledState.REASON_HANDLED_EXCEPTION) .metaData(metaData) .build(); @@ -1083,7 +1083,7 @@ public void notifyBlocking(@NonNull Throwable exception, public void notifyBlocking(@NonNull Throwable exception, Severity severity, @NonNull MetaData metaData) { Error error = new Error.Builder(config, exception, sessionTracker.getCurrentSession(), - Thread.currentThread()) + Thread.currentThread(), false) .metaData(metaData) .severity(severity) .build(); @@ -1154,7 +1154,7 @@ public void notifyBlocking(@NonNull String name, */ public void notifyBlocking(@NonNull Throwable exception, Severity severity) { Error error = new Error.Builder(config, exception, - sessionTracker.getCurrentSession(), Thread.currentThread()) + sessionTracker.getCurrentSession(), Thread.currentThread(), false) .severity(severity) .build(); notify(error, BLOCKING); @@ -1183,7 +1183,7 @@ public void internalClientNotify(@NonNull Throwable exception, @SuppressWarnings("WrongConstant") Error error = new Error.Builder(config, exception, - sessionTracker.getCurrentSession(), Thread.currentThread()) + sessionTracker.getCurrentSession(), Thread.currentThread(), false) .severity(Severity.fromString(severity)) .severityReasonType(severityReason) .attributeValue(logLevel) @@ -1342,7 +1342,7 @@ void cacheAndNotify(@NonNull Throwable exception, Severity severity, MetaData me @HandledState.SeverityReason String severityReason, @Nullable String attributeValue, Thread thread) { Error error = new Error.Builder(config, exception, - sessionTracker.getCurrentSession(), thread) + sessionTracker.getCurrentSession(), thread, true) .severity(severity) .metaData(metaData) .severityReasonType(severityReason) diff --git a/sdk/src/main/java/com/bugsnag/android/Error.java b/sdk/src/main/java/com/bugsnag/android/Error.java index 15c90ae0b1..e968559495 100644 --- a/sdk/src/main/java/com/bugsnag/android/Error.java +++ b/sdk/src/main/java/com/bugsnag/android/Error.java @@ -401,9 +401,11 @@ static class Builder { Builder(@NonNull Configuration config, @NonNull Throwable exception, - Session session, - Thread thread) { - this.threadState = new ThreadState(config, thread, Thread.getAllStackTraces(), null); + @Nullable Session session, + @NonNull Thread thread, + boolean unhandled) { + Throwable exc = unhandled ? exception : null; + this.threadState = new ThreadState(config, thread, Thread.getAllStackTraces(), exc); this.config = config; this.exception = exception; this.severityReasonType = HandledState.REASON_USER_SPECIFIED; // default @@ -419,7 +421,7 @@ static class Builder { Builder(@NonNull Configuration config, @NonNull String name, @NonNull String message, @NonNull StackTraceElement[] frames, Session session, Thread thread) { - this(config, new BugsnagException(name, message, frames), session, thread); + this(config, new BugsnagException(name, message, frames), session, thread, false); } Builder severityReasonType(@HandledState.SeverityReason String severityReasonType) {