From d42e2f45e1d7a96825966112f045b54330a2ff19 Mon Sep 17 00:00:00 2001 From: richard elms Date: Fri, 14 Nov 2025 11:21:41 +0100 Subject: [PATCH 01/13] initial on error change --- bugsnag/src/main/java/com/bugsnag/Bugsnag.java | 10 +++++----- bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java | 6 +++--- .../main/java/com/bugsnag/callbacks/AppCallback.java | 2 +- .../src/main/java/com/bugsnag/callbacks/Callback.java | 2 +- .../java/com/bugsnag/callbacks/DeviceCallback.java | 2 +- .../com/bugsnag/callbacks/JakartaServletCallback.java | 2 +- bugsnag/src/test/java/com/bugsnag/AppenderTest.java | 2 +- .../test/java/com/bugsnag/ConcurrentCallbackTest.java | 7 ++++--- .../java/com/bugsnag/example/simple/ExampleApp.java | 4 ++-- .../bugsnag/mazerunner/scenarios/MetadataScenario.java | 2 +- .../scenarios/UnhandledThreadMetadataScenario.java | 2 +- .../mazerunner/scenarios/UserCallbackScenario.java | 2 +- 12 files changed, 22 insertions(+), 21 deletions(-) diff --git a/bugsnag/src/main/java/com/bugsnag/Bugsnag.java b/bugsnag/src/main/java/com/bugsnag/Bugsnag.java index 635a0439..13d328b8 100644 --- a/bugsnag/src/main/java/com/bugsnag/Bugsnag.java +++ b/bugsnag/src/main/java/com/bugsnag/Bugsnag.java @@ -452,16 +452,16 @@ public boolean notify(Report report, Callback reportCallback) { return false; } - // Run all client-wide beforeNotify callbacks + // Run all client-wide onError callbacks for (Callback callback : config.callbacks) { try { // Run the callback - callback.beforeNotify(report); + callback.onError(report); // Check if callback cancelled delivery if (report.getShouldCancel()) { LOGGER.debug("Error not reported to Bugsnag - " - + "cancelled by a client-wide beforeNotify callback"); + + "cancelled by a client-wide onError callback"); return false; } } catch (Throwable ex) { @@ -472,11 +472,11 @@ public boolean notify(Report report, Callback reportCallback) { // Add thread metadata to the report report.mergeMetadata(THREAD_METADATA.get()); - // Run the report-specific beforeNotify callback, if given + // Run the report-specific onError callback, if given if (reportCallback != null) { try { // Run the callback - reportCallback.beforeNotify(report); + reportCallback.onError(report); // Check if callback cancelled delivery if (report.getShouldCancel()) { diff --git a/bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java b/bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java index c65df317..f3bb5472 100644 --- a/bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java +++ b/bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java @@ -134,7 +134,7 @@ protected void append(final ILoggingEvent event) { calculateSeverity(event), new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { // Add some data from the logging event report.addToTab("Log event data", @@ -146,7 +146,7 @@ public void beforeNotify(Report report) { populateContextData(report, event); if (reportCallback != null) { - reportCallback.beforeNotify(report); + reportCallback.onError(report); } } }); @@ -270,7 +270,7 @@ private Bugsnag createBugsnag() { // Add a callback to put global metadata on every report bugsnag.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { for (LogbackMetadata metadata : globalMetadata) { for (LogbackMetadataTab tab : metadata.getTabs()) { diff --git a/bugsnag/src/main/java/com/bugsnag/callbacks/AppCallback.java b/bugsnag/src/main/java/com/bugsnag/callbacks/AppCallback.java index 1b3db326..59c7dd0d 100644 --- a/bugsnag/src/main/java/com/bugsnag/callbacks/AppCallback.java +++ b/bugsnag/src/main/java/com/bugsnag/callbacks/AppCallback.java @@ -11,7 +11,7 @@ public AppCallback(Configuration config) { } @Override - public void beforeNotify(Report report) { + public void onError(Report report) { if (config.appType != null) { report.setAppInfo("type", config.appType); } diff --git a/bugsnag/src/main/java/com/bugsnag/callbacks/Callback.java b/bugsnag/src/main/java/com/bugsnag/callbacks/Callback.java index 8ba80297..88096c68 100644 --- a/bugsnag/src/main/java/com/bugsnag/callbacks/Callback.java +++ b/bugsnag/src/main/java/com/bugsnag/callbacks/Callback.java @@ -8,5 +8,5 @@ public interface Callback { * * @param report the report to perform changes on. */ - void beforeNotify(Report report); + void onError(Report report); } diff --git a/bugsnag/src/main/java/com/bugsnag/callbacks/DeviceCallback.java b/bugsnag/src/main/java/com/bugsnag/callbacks/DeviceCallback.java index e6d21297..8969fbcb 100644 --- a/bugsnag/src/main/java/com/bugsnag/callbacks/DeviceCallback.java +++ b/bugsnag/src/main/java/com/bugsnag/callbacks/DeviceCallback.java @@ -84,7 +84,7 @@ public void run() { } @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report .addToTab("device", "osArch", System.getProperty("os.arch")) .addToTab("device", "locale", Locale.getDefault()) diff --git a/bugsnag/src/main/java/com/bugsnag/callbacks/JakartaServletCallback.java b/bugsnag/src/main/java/com/bugsnag/callbacks/JakartaServletCallback.java index 17c4f67c..4e0d8492 100644 --- a/bugsnag/src/main/java/com/bugsnag/callbacks/JakartaServletCallback.java +++ b/bugsnag/src/main/java/com/bugsnag/callbacks/JakartaServletCallback.java @@ -26,7 +26,7 @@ public static boolean isAvailable() { } @Override - public void beforeNotify(Report report) { + public void onError(Report report) { // Check if we have any servlet request data available HttpServletRequest request = BugsnagServletRequestListener.getServletRequest(); if (request == null) { diff --git a/bugsnag/src/test/java/com/bugsnag/AppenderTest.java b/bugsnag/src/test/java/com/bugsnag/AppenderTest.java index 248e50e1..eba20ba3 100644 --- a/bugsnag/src/test/java/com/bugsnag/AppenderTest.java +++ b/bugsnag/src/test/java/com/bugsnag/AppenderTest.java @@ -298,7 +298,7 @@ public void testCallback() { // Setup a callback to set the user appender.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setUserName("User Name"); report.setUserEmail("user@example.com"); report.setUserId("12345"); diff --git a/bugsnag/src/test/java/com/bugsnag/ConcurrentCallbackTest.java b/bugsnag/src/test/java/com/bugsnag/ConcurrentCallbackTest.java index dfbe2d31..4858166f 100644 --- a/bugsnag/src/test/java/com/bugsnag/ConcurrentCallbackTest.java +++ b/bugsnag/src/test/java/com/bugsnag/ConcurrentCallbackTest.java @@ -30,11 +30,12 @@ public void testClientNotifyModification() { config.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { - // modify the callback collection, when iterating to the next callback this should not crash + public void onError(Report report) { + // modify the callback collection, when iterating to the next callback this + // should not crash config.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { } }); } diff --git a/examples/simple/src/main/java/com/bugsnag/example/simple/ExampleApp.java b/examples/simple/src/main/java/com/bugsnag/example/simple/ExampleApp.java index cfb24441..a8185175 100644 --- a/examples/simple/src/main/java/com/bugsnag/example/simple/ExampleApp.java +++ b/examples/simple/src/main/java/com/bugsnag/example/simple/ExampleApp.java @@ -22,7 +22,7 @@ public static void main(String[] args) throws InterruptedException { // the lifecyle of your application bugsnag.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.addToTab("diagnostics", "timestamp", new Date()); report.addToTab("customer", "name", "acme-inc"); report.addToTab("customer", "paying", true); @@ -53,7 +53,7 @@ public void beforeNotify(Report report) { } catch (RuntimeException e) { bugsnag.notify(e, new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setSeverity(Severity.WARNING); report.addToTab("report", "something", "that happened"); report.setContext("the context"); diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/MetadataScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/MetadataScenario.java index e639c540..2d309e00 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/MetadataScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/MetadataScenario.java @@ -17,7 +17,7 @@ public MetadataScenario(Bugsnag bugsnag) { public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.addToTab("Custom", "foo", "Hello World!"); } }); diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UnhandledThreadMetadataScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UnhandledThreadMetadataScenario.java index c8c3dbba..0a6f9086 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UnhandledThreadMetadataScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UnhandledThreadMetadataScenario.java @@ -18,7 +18,7 @@ public void run() { // Global callback metadata has lowest precedence bugsnag.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.addToTab("Custom", "test", "Global value"); report.addToTab("Custom", "foo", "Global value to be overwritten"); } diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UserCallbackScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UserCallbackScenario.java index 52289a2b..7b58d88a 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UserCallbackScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UserCallbackScenario.java @@ -17,7 +17,7 @@ public UserCallbackScenario(Bugsnag bugsnag) { public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setUser("Agent Pink", "bob@example.com", "Zebedee"); } }); From 223695efdc8af74759a7dc43826126fae8792132 Mon Sep 17 00:00:00 2001 From: richard elms Date: Fri, 14 Nov 2025 11:31:29 +0100 Subject: [PATCH 02/13] further usages --- .../bugsnag/BugsnagSpringConfiguration.java | 2 +- .../com/bugsnag/ExceptionClassCallback.java | 2 +- .../com/bugsnag/SpringBootConfiguration.java | 2 +- .../test/java/com/bugsnag/SpringMvcTest.java | 2 +- .../testapp/springboot/TestController.java | 2 +- .../com/bugsnag/AppenderMetadataTest.java | 2 +- .../test/java/com/bugsnag/BugsnagTest.java | 20 +++++++++---------- .../test/java/com/bugsnag/ExceptionTest.java | 2 +- .../bugsnag/JakartaServletCallbackTest.java | 6 +++--- .../src/test/java/com/bugsnag/MarkerTest.java | 2 +- .../spring/web/ApplicationRestController.java | 2 +- .../bugsnag/example/spring/web/Config.java | 2 +- .../cli/ApplicationCommandLineRunner.java | 2 +- .../bugsnag/example/spring/cli/Config.java | 2 +- .../ScheduledTaskExecutorScenario.java | 2 +- .../scenarios/AutoRedactScenario.java | 2 +- .../scenarios/LogbackMetadataScenario.java | 2 +- .../scenarios/ManualContextScenario.java | 2 +- .../scenarios/ManualRedactScenario.java | 2 +- .../scenarios/ThreadMetadataScenario.java | 4 ++-- 20 files changed, 32 insertions(+), 32 deletions(-) diff --git a/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java b/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java index 36f70550..6bc7546d 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java @@ -28,7 +28,7 @@ public class BugsnagSpringConfiguration implements InitializingBean { Callback springVersionErrorCallback() { Callback callback = new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { addSpringRuntimeVersion(report.getDevice()); } }; diff --git a/bugsnag-spring/src/main/java/com/bugsnag/ExceptionClassCallback.java b/bugsnag-spring/src/main/java/com/bugsnag/ExceptionClassCallback.java index 3c93b35b..7addc1e8 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/ExceptionClassCallback.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/ExceptionClassCallback.java @@ -111,7 +111,7 @@ class ExceptionClassCallback implements Callback { } @Override - public void beforeNotify(Report report) { + public void onError(Report report) { HandledState handledState = report.getHandledState(); diff --git a/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java b/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java index f8f71ab0..f399d425 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java @@ -19,7 +19,7 @@ public class SpringBootConfiguration { Callback springBootVersionErrorCallback() { Callback callback = new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { addSpringRuntimeVersion(report.getDevice()); } }; diff --git a/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java b/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java index 6acb31a1..ce8f3c16 100644 --- a/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java +++ b/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java @@ -190,7 +190,7 @@ public void unhandledTypeMismatchExceptionCallbackSeverity() Report report; Callback callback = new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setSeverity(Severity.WARNING); } }; diff --git a/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java index 86e064bf..51da1e18 100644 --- a/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java +++ b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java @@ -67,7 +67,7 @@ public void handledTypeMismatchExceptionCallbackSeverity() { } catch (TypeMismatchException ex) { bugsnag.notify(ex, new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setSeverity(Severity.WARNING); } }); diff --git a/bugsnag/src/test/java/com/bugsnag/AppenderMetadataTest.java b/bugsnag/src/test/java/com/bugsnag/AppenderMetadataTest.java index 4ba4dc0a..65b1dcff 100644 --- a/bugsnag/src/test/java/com/bugsnag/AppenderMetadataTest.java +++ b/bugsnag/src/test/java/com/bugsnag/AppenderMetadataTest.java @@ -111,7 +111,7 @@ public void testMetadataRemoval() { // Send three test logs, the first one with report metadata added LOGGER.warn(new BugsnagMarker(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.addToTab("report", "some key", "some report value"); } }), "Test exception", new RuntimeException("test")); diff --git a/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java b/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java index e075be43..3bd5d10d 100644 --- a/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java +++ b/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java @@ -188,7 +188,7 @@ public void close() { }); assertTrue(bugsnag.notify(new Throwable(), new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.addToTab("firsttab", "testredact1", "secretpassword"); report.addToTab("firsttab", "testredact2", "secretpassword"); report.addToTab("firsttab", "testredact3", "secretpassword"); @@ -223,7 +223,7 @@ public void close() { assertTrue(bugsnag.notify(new Throwable(), new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { Map headers = new HashMap(); headers.put("Authorization", "User:Password"); headers.put("authorization", "User:Password"); @@ -252,7 +252,7 @@ public void close() { }); assertTrue(bugsnag.notify(new Throwable(), new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setUser("123", "test@example.com", "test name"); } })); @@ -262,7 +262,7 @@ public void beforeNotify(Report report) { public void testContext() { bugsnag.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setContext("the context"); } }); @@ -284,7 +284,7 @@ public void close() { public void testGroupingHash() { bugsnag.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setGroupingHash("the grouping hash"); } }); @@ -306,7 +306,7 @@ public void close() { public void testSingleCallback() { bugsnag.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setApiKey("newapikey"); } }); @@ -340,7 +340,7 @@ public void close() { assertTrue(bugsnag.notify(new Throwable(), new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setApiKey("newapikey"); } })); @@ -350,13 +350,13 @@ public void beforeNotify(Report report) { public void testCallbackOrder() { bugsnag.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setApiKey("newapikey"); } }); bugsnag.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setApiKey("secondnewapikey"); } }); @@ -379,7 +379,7 @@ public void testCallbackCancel() { bugsnag.setDelivery(BugsnagTestUtils.generateDelivery()); bugsnag.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.cancel(); } }); diff --git a/bugsnag/src/test/java/com/bugsnag/ExceptionTest.java b/bugsnag/src/test/java/com/bugsnag/ExceptionTest.java index 861e1e36..9ae7e107 100644 --- a/bugsnag/src/test/java/com/bugsnag/ExceptionTest.java +++ b/bugsnag/src/test/java/com/bugsnag/ExceptionTest.java @@ -62,7 +62,7 @@ public void close() { }); assertTrue(bugsnag.notify(ogThrowable, new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { try { assertEquals(ogThrowable, report.getException()); assertEquals("Test", report.getExceptionMessage()); diff --git a/bugsnag/src/test/java/com/bugsnag/JakartaServletCallbackTest.java b/bugsnag/src/test/java/com/bugsnag/JakartaServletCallbackTest.java index 00ad7997..f71d0a61 100644 --- a/bugsnag/src/test/java/com/bugsnag/JakartaServletCallbackTest.java +++ b/bugsnag/src/test/java/com/bugsnag/JakartaServletCallbackTest.java @@ -83,7 +83,7 @@ public void closeBugsnag() { public void testRequestMetadataAdded() { Report report = generateReport(new java.lang.Exception("Spline reticulation failed")); JakartaServletCallback callback = new JakartaServletCallback(); - callback.beforeNotify(report); + callback.onError(report); Map metadata = report.getMetadata(); assertTrue(metadata.containsKey("request")); @@ -120,7 +120,7 @@ public void testRequestMetadataAdded() { public void testRequestContextSet() { Report report = generateReport(new java.lang.Exception("Spline reticulation failed")); JakartaServletCallback callback = new JakartaServletCallback(); - callback.beforeNotify(report); + callback.onError(report); assertEquals("PATCH /foo/bar", report.getContext()); } @@ -130,7 +130,7 @@ public void testExistingContextNotOverridden() { Report report = generateReport(new java.lang.Exception("Spline reticulation failed")); report.setContext("Honey nut corn flakes"); JakartaServletCallback callback = new JakartaServletCallback(); - callback.beforeNotify(report); + callback.onError(report); assertEquals("Honey nut corn flakes", report.getContext()); } diff --git a/bugsnag/src/test/java/com/bugsnag/MarkerTest.java b/bugsnag/src/test/java/com/bugsnag/MarkerTest.java index f746cedd..a2af0dc0 100644 --- a/bugsnag/src/test/java/com/bugsnag/MarkerTest.java +++ b/bugsnag/src/test/java/com/bugsnag/MarkerTest.java @@ -29,7 +29,7 @@ public class MarkerTest { public void createMarker() { callback = new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { } }; diff --git a/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/ApplicationRestController.java b/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/ApplicationRestController.java index df5a5796..4d141355 100644 --- a/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/ApplicationRestController.java +++ b/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/ApplicationRestController.java @@ -71,7 +71,7 @@ public String sendHandledExceptionWithMetadata() { } catch (RuntimeException e) { bugsnag.notify(e, new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setSeverity(Severity.WARNING); report.addToTab("report", "something", "that happened"); report.setContext("the context"); diff --git a/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/Config.java b/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/Config.java index 0481f59f..cc50bc4c 100644 --- a/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/Config.java +++ b/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/Config.java @@ -31,7 +31,7 @@ public Bugsnag bugsnag() { // the lifecyle of your application bugsnag.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.addToTab("diagnostics", "timestamp", new Date()); report.addToTab("customer", "name", "acme-inc"); report.addToTab("customer", "paying", true); diff --git a/examples/spring/src/main/java/com/bugsnag/example/spring/cli/ApplicationCommandLineRunner.java b/examples/spring/src/main/java/com/bugsnag/example/spring/cli/ApplicationCommandLineRunner.java index 6e201859..896edb7d 100644 --- a/examples/spring/src/main/java/com/bugsnag/example/spring/cli/ApplicationCommandLineRunner.java +++ b/examples/spring/src/main/java/com/bugsnag/example/spring/cli/ApplicationCommandLineRunner.java @@ -50,7 +50,7 @@ public void run(final String... args) throws Exception { } catch (RuntimeException e) { bugsnag.notify(e, new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setSeverity(Severity.WARNING); report.addToTab("report", "something", "that happened"); report.setContext("the context"); diff --git a/examples/spring/src/main/java/com/bugsnag/example/spring/cli/Config.java b/examples/spring/src/main/java/com/bugsnag/example/spring/cli/Config.java index 7921655a..e60f0553 100644 --- a/examples/spring/src/main/java/com/bugsnag/example/spring/cli/Config.java +++ b/examples/spring/src/main/java/com/bugsnag/example/spring/cli/Config.java @@ -31,7 +31,7 @@ public Bugsnag bugsnag() { // the lifecyle of your application bugsnag.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.addToTab("diagnostics", "timestamp", new Date()); report.addToTab("customer", "name", "acme-inc"); report.addToTab("customer", "paying", true); diff --git a/features/fixtures/mazerunnerspringboot3/src/main/java/com/bugsnag/mazerunner/scenarios/ScheduledTaskExecutorScenario.java b/features/fixtures/mazerunnerspringboot3/src/main/java/com/bugsnag/mazerunner/scenarios/ScheduledTaskExecutorScenario.java index 5dc877b2..1abd25eb 100644 --- a/features/fixtures/mazerunnerspringboot3/src/main/java/com/bugsnag/mazerunner/scenarios/ScheduledTaskExecutorScenario.java +++ b/features/fixtures/mazerunnerspringboot3/src/main/java/com/bugsnag/mazerunner/scenarios/ScheduledTaskExecutorScenario.java @@ -27,7 +27,7 @@ public void run() { final Collection threadnames = ScheduledTaskExecutorService.getThreadNames(); bugsnag.notify(new RuntimeException("Whoops"), new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.addToTab("executor", "multiThreaded", threadnames.size() > 1); report.addToTab("executor", "names", threadnames); } diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/AutoRedactScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/AutoRedactScenario.java index bfafab71..f3b91b5f 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/AutoRedactScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/AutoRedactScenario.java @@ -17,7 +17,7 @@ public AutoRedactScenario(Bugsnag bugsnag) { public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.addToTab("user", "password", "hunter2"); report.addToTab("custom", "password", "hunter2"); report.addToTab("custom", "foo", "hunter2"); diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/LogbackMetadataScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/LogbackMetadataScenario.java index 37bd1ad7..ef764a42 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/LogbackMetadataScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/LogbackMetadataScenario.java @@ -23,7 +23,7 @@ public LogbackMetadataScenario(Bugsnag bugsnag) { public void run() { LOGGER.warn(new BugsnagMarker(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.addToTab("user", "foo", "hunter2"); report.addToTab("custom", "foo", "hunter2"); report.addToTab("custom", "bar", "hunter2"); diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualContextScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualContextScenario.java index 2f518812..f8818f8f 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualContextScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualContextScenario.java @@ -17,7 +17,7 @@ public ManualContextScenario(Bugsnag bugsnag) { public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.setContext("FooContext"); } }); diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualRedactScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualRedactScenario.java index 22685510..653e949b 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualRedactScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualRedactScenario.java @@ -20,7 +20,7 @@ public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.addToTab("user", "foo", "hunter2"); report.addToTab("custom", "foo", "hunter2"); report.addToTab("custom", "bar", "hunter2"); diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ThreadMetadataScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ThreadMetadataScenario.java index 254718fa..a9cf7466 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ThreadMetadataScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ThreadMetadataScenario.java @@ -18,7 +18,7 @@ public void run() { // Global callback metadata has lowest precedence bugsnag.addCallback(new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.addToTab("Custom", "test", "Global value"); report.addToTab("Custom", "foo", "Global value to be overwritten"); } @@ -47,7 +47,7 @@ public void run() { // Report-specific metadata should merge with global + thread metadata and overwrite when duplicate key bugsnag.notify(generateException(), new Callback() { @Override - public void beforeNotify(Report report) { + public void onError(Report report) { report.addToTab("Custom", "bar", "Hello World!"); } }); From 1f6a32473ffee3614c9a464211c38b0750655a73 Mon Sep 17 00:00:00 2001 From: richard elms Date: Fri, 14 Nov 2025 13:30:44 +0100 Subject: [PATCH 03/13] initial session change --- .../main/java/com/bugsnag/BugsnagSpringConfiguration.java | 2 +- .../main/java/com/bugsnag/SpringBootConfiguration.java | 2 +- bugsnag/src/main/java/com/bugsnag/BeforeSendSession.java | 2 +- bugsnag/src/main/java/com/bugsnag/SessionTracker.java | 8 +++----- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java b/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java index 6bc7546d..11c1f0f7 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java @@ -40,7 +40,7 @@ public void onError(Report report) { BeforeSendSession springVersionSessionCallback() { BeforeSendSession beforeSendSession = new BeforeSendSession() { @Override - public void beforeSendSession(SessionPayload payload) { + public void onSession(SessionPayload payload) { addSpringRuntimeVersion(payload.getDevice()); } }; diff --git a/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java b/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java index f399d425..efa358a0 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java @@ -31,7 +31,7 @@ public void onError(Report report) { BeforeSendSession springBootVersionSessionCallback() { BeforeSendSession beforeSendSession = new BeforeSendSession() { @Override - public void beforeSendSession(SessionPayload payload) { + public void onSession(SessionPayload payload) { addSpringRuntimeVersion(payload.getDevice()); } }; diff --git a/bugsnag/src/main/java/com/bugsnag/BeforeSendSession.java b/bugsnag/src/main/java/com/bugsnag/BeforeSendSession.java index dcd6a50d..14c333c4 100644 --- a/bugsnag/src/main/java/com/bugsnag/BeforeSendSession.java +++ b/bugsnag/src/main/java/com/bugsnag/BeforeSendSession.java @@ -1,5 +1,5 @@ package com.bugsnag; interface BeforeSendSession { - void beforeSendSession(SessionPayload payload); + void onSession(SessionPayload payload); } diff --git a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java index d0a50472..6348670f 100644 --- a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java +++ b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java @@ -16,8 +16,7 @@ class SessionTracker { private final Configuration config; private final ThreadLocal session = new ThreadLocal(); private final AtomicReference batchCount = new AtomicReference(); - private final Collection - enqueuedSessionCounts = new ConcurrentLinkedQueue(); + private final Collection enqueuedSessionCounts = new ConcurrentLinkedQueue(); private final Semaphore flushingRequest = new Semaphore(1); private final AtomicBoolean shuttingDown = new AtomicBoolean(); @@ -86,12 +85,11 @@ private void sendSessions(Date now) { if (!enqueuedSessionCounts.isEmpty() && flushingRequest.tryAcquire(1)) { try { - Collection requestValues - = new ArrayList(enqueuedSessionCounts); + Collection requestValues = new ArrayList(enqueuedSessionCounts); SessionPayload payload = new SessionPayload(requestValues, config); for (BeforeSendSession callback : sessionCallbacks) { - callback.beforeSendSession(payload); + callback.onSession(payload); } Delivery delivery = config.sessionDelivery; From 28f5303d9b67fb12aaa1e8eb832b76aa34479b1f Mon Sep 17 00:00:00 2001 From: richard elms Date: Fri, 14 Nov 2025 13:40:04 +0100 Subject: [PATCH 04/13] onSession --- .../main/java/com/bugsnag/BugsnagSpringConfiguration.java | 8 ++++---- .../main/java/com/bugsnag/SpringBootConfiguration.java | 8 ++++---- bugsnag/src/main/java/com/bugsnag/Bugsnag.java | 4 ++-- .../bugsnag/{BeforeSendSession.java => OnSession.java} | 2 +- bugsnag/src/main/java/com/bugsnag/SessionTracker.java | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) rename bugsnag/src/main/java/com/bugsnag/{BeforeSendSession.java => OnSession.java} (69%) diff --git a/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java b/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java index 11c1f0f7..1cdba559 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java @@ -37,15 +37,15 @@ public void onError(Report report) { } @Bean - BeforeSendSession springVersionSessionCallback() { - BeforeSendSession beforeSendSession = new BeforeSendSession() { + OnSession springVersionSessionCallback() { + OnSession onSession = new OnSession() { @Override public void onSession(SessionPayload payload) { addSpringRuntimeVersion(payload.getDevice()); } }; - bugsnag.addBeforeSendSession(beforeSendSession); - return beforeSendSession; + bugsnag.addOnSession(onSession); + return onSession; } private void addSpringRuntimeVersion(Map device) { diff --git a/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java b/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java index efa358a0..57840152 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java @@ -28,15 +28,15 @@ public void onError(Report report) { } @Bean - BeforeSendSession springBootVersionSessionCallback() { - BeforeSendSession beforeSendSession = new BeforeSendSession() { + OnSession springBootVersionSessionCallback() { + OnSession onSession = new OnSession() { @Override public void onSession(SessionPayload payload) { addSpringRuntimeVersion(payload.getDevice()); } }; - bugsnag.addBeforeSendSession(beforeSendSession); - return beforeSendSession; + bugsnag.addOnSession(onSession); + return onSession; } private void addSpringRuntimeVersion(Map device) { diff --git a/bugsnag/src/main/java/com/bugsnag/Bugsnag.java b/bugsnag/src/main/java/com/bugsnag/Bugsnag.java index 13d328b8..2c0ab89f 100644 --- a/bugsnag/src/main/java/com/bugsnag/Bugsnag.java +++ b/bugsnag/src/main/java/com/bugsnag/Bugsnag.java @@ -676,7 +676,7 @@ public static Set uncaughtExceptionClients() { return Collections.emptySet(); } - void addBeforeSendSession(BeforeSendSession beforeSendSession) { - sessionTracker.addBeforeSendSession(beforeSendSession); + void addOnSession(OnSession onSession) { + sessionTracker.addOnSession(onSession); } } diff --git a/bugsnag/src/main/java/com/bugsnag/BeforeSendSession.java b/bugsnag/src/main/java/com/bugsnag/OnSession.java similarity index 69% rename from bugsnag/src/main/java/com/bugsnag/BeforeSendSession.java rename to bugsnag/src/main/java/com/bugsnag/OnSession.java index 14c333c4..d591bc90 100644 --- a/bugsnag/src/main/java/com/bugsnag/BeforeSendSession.java +++ b/bugsnag/src/main/java/com/bugsnag/OnSession.java @@ -1,5 +1,5 @@ package com.bugsnag; -interface BeforeSendSession { +interface OnSession { void onSession(SessionPayload payload); } diff --git a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java index 6348670f..21daf29f 100644 --- a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java +++ b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java @@ -20,7 +20,7 @@ class SessionTracker { private final Semaphore flushingRequest = new Semaphore(1); private final AtomicBoolean shuttingDown = new AtomicBoolean(); - private final Collection sessionCallbacks = new ConcurrentLinkedQueue(); + private final Collection sessionCallbacks = new ConcurrentLinkedQueue(); SessionTracker(Configuration configuration) { this.config = configuration; @@ -88,7 +88,7 @@ private void sendSessions(Date now) { Collection requestValues = new ArrayList(enqueuedSessionCounts); SessionPayload payload = new SessionPayload(requestValues, config); - for (BeforeSendSession callback : sessionCallbacks) { + for (OnSession callback : sessionCallbacks) { callback.onSession(payload); } @@ -107,7 +107,7 @@ void shutdown() { } } - void addBeforeSendSession(BeforeSendSession beforeSendSession) { - sessionCallbacks.add(beforeSendSession); + void addOnSession(OnSession onSession) { + sessionCallbacks.add(onSession); } } From 0df177990332f65e1895fc218f6ed4457a4624b3 Mon Sep 17 00:00:00 2001 From: richard elms Date: Mon, 17 Nov 2025 12:44:40 +0100 Subject: [PATCH 05/13] change session callbacks to use bool send flag --- .../bugsnag/BugsnagSpringConfiguration.java | 3 +- .../com/bugsnag/SpringBootConfiguration.java | 3 +- .../src/main/java/com/bugsnag/OnSession.java | 3 +- .../main/java/com/bugsnag/SessionTracker.java | 32 +++++++++++++++---- .../java/com/bugsnag/SessionTrackerTest.java | 29 +++++++++++++++++ 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java b/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java index 1cdba559..4f77f15a 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java @@ -40,8 +40,9 @@ public void onError(Report report) { OnSession springVersionSessionCallback() { OnSession onSession = new OnSession() { @Override - public void onSession(SessionPayload payload) { + public Boolean onSession(SessionPayload payload) { addSpringRuntimeVersion(payload.getDevice()); + return true; } }; bugsnag.addOnSession(onSession); diff --git a/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java b/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java index 57840152..652b12f4 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java @@ -31,8 +31,9 @@ public void onError(Report report) { OnSession springBootVersionSessionCallback() { OnSession onSession = new OnSession() { @Override - public void onSession(SessionPayload payload) { + public Boolean onSession(SessionPayload payload) { addSpringRuntimeVersion(payload.getDevice()); + return true; } }; bugsnag.addOnSession(onSession); diff --git a/bugsnag/src/main/java/com/bugsnag/OnSession.java b/bugsnag/src/main/java/com/bugsnag/OnSession.java index d591bc90..bf85f08a 100644 --- a/bugsnag/src/main/java/com/bugsnag/OnSession.java +++ b/bugsnag/src/main/java/com/bugsnag/OnSession.java @@ -1,5 +1,6 @@ package com.bugsnag; +@FunctionalInterface interface OnSession { - void onSession(SessionPayload payload); + Boolean onSession(SessionPayload payload); } diff --git a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java index 21daf29f..e4d22e62 100644 --- a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java +++ b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java @@ -85,16 +85,36 @@ private void sendSessions(Date now) { if (!enqueuedSessionCounts.isEmpty() && flushingRequest.tryAcquire(1)) { try { - Collection requestValues = new ArrayList(enqueuedSessionCounts); - SessionPayload payload = new SessionPayload(requestValues, config); + Collection requestValues = + new ArrayList(enqueuedSessionCounts); - for (OnSession callback : sessionCallbacks) { - callback.onSession(payload); + Collection approvedSessions = new ArrayList(); + + for (SessionCount sessionCount : requestValues) { + SessionPayload singlePayload = + new SessionPayload(Collections.singleton(sessionCount), config); + + boolean sendThisSession = true; + for (OnSession callback : sessionCallbacks) { + if (!callback.onSession(singlePayload)) { + sendThisSession = false; + break; + } + } + + if (sendThisSession) { + approvedSessions.add(sessionCount); + } + } + + if (!approvedSessions.isEmpty()) { + SessionPayload payload = new SessionPayload(approvedSessions, config); + Delivery delivery = config.sessionDelivery; + delivery.deliver(config.serializer, payload, config.getSessionApiHeaders()); } - Delivery delivery = config.sessionDelivery; - delivery.deliver(config.serializer, payload, config.getSessionApiHeaders()); enqueuedSessionCounts.removeAll(requestValues); + } finally { flushingRequest.release(1); } diff --git a/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java b/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java index d1dcf9ec..0adc29d3 100644 --- a/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java +++ b/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java @@ -321,6 +321,35 @@ public void testMultiShutdown() { assertEquals(1, delivery.count.get()); } + @Test + public void sessionDeliverySuppressedByCallback() { + // Set up a delivery stub which SHOULD NOT be invoked + CustomDelivery delivery = new CustomDelivery() { + @Override + public void deliver(Serializer serializer, Object object, Map headers) { + super.deliver(serializer, object, headers); + fail("Delivery should be suppressed by OnSession callback returning false"); + } + }; + configuration.sessionDelivery = delivery; + + // Add callback which returns false to suppress sending + sessionTracker.addOnSession(new OnSession() { + @Override + public Boolean onSession(SessionPayload payload) { + return false; // suppress delivery + } + }); + + // Start a session and flush far enough in future to trigger send attempt + sessionTracker.startSession(new Date(10000000L), false); + sessionTracker.flushSessions(new Date(13600000L)); // different batch period + + // Verify delivery was NOT performed + assertFalse(delivery.delivered); + assertEquals(0, delivery.count.get()); + } + abstract static class CustomDelivery implements Delivery { boolean delivered; AtomicInteger count = new AtomicInteger(0); From 8307c3eb0de5311d14f8729dc52bdc2222e71c83 Mon Sep 17 00:00:00 2001 From: richard elms Date: Mon, 17 Nov 2025 13:06:27 +0100 Subject: [PATCH 06/13] change onError callbacks to use booleans --- .../bugsnag/BugsnagSpringConfiguration.java | 3 +- .../com/bugsnag/ExceptionClassCallback.java | 5 +- .../com/bugsnag/SpringBootConfiguration.java | 3 +- .../test/java/com/bugsnag/SpringMvcTest.java | 3 +- .../testapp/springboot/TestController.java | 3 +- .../src/main/java/com/bugsnag/Bugsnag.java | 20 ++----- .../java/com/bugsnag/BugsnagAppender.java | 11 +++- .../main/java/com/bugsnag/SessionTracker.java | 1 + .../com/bugsnag/callbacks/AppCallback.java | 3 +- .../java/com/bugsnag/callbacks/Callback.java | 6 +- .../com/bugsnag/callbacks/DeviceCallback.java | 3 +- .../callbacks/JakartaServletCallback.java | 5 +- .../com/bugsnag/AppenderMetadataTest.java | 4 +- .../test/java/com/bugsnag/AppenderTest.java | 4 +- .../test/java/com/bugsnag/BugsnagTest.java | 30 ++++++---- .../com/bugsnag/CallbackSuppressionTest.java | 57 +++++++++++++++++++ .../com/bugsnag/ConcurrentCallbackTest.java | 6 +- .../test/java/com/bugsnag/ExceptionTest.java | 4 +- .../src/test/java/com/bugsnag/MarkerTest.java | 5 +- .../bugsnag/example/simple/ExampleApp.java | 6 +- .../spring/web/ApplicationRestController.java | 3 +- .../bugsnag/example/spring/web/Config.java | 3 +- .../cli/ApplicationCommandLineRunner.java | 3 +- .../ScheduledTaskExecutorScenario.java | 3 +- .../scenarios/AutoRedactScenario.java | 3 +- .../scenarios/LogbackMetadataScenario.java | 15 ++--- .../scenarios/ManualContextScenario.java | 3 +- .../scenarios/ManualRedactScenario.java | 3 +- .../scenarios/MetadataScenario.java | 3 +- .../scenarios/ThreadMetadataScenario.java | 6 +- .../UnhandledThreadMetadataScenario.java | 3 +- .../scenarios/UserCallbackScenario.java | 3 +- 32 files changed, 163 insertions(+), 70 deletions(-) create mode 100644 bugsnag/src/test/java/com/bugsnag/CallbackSuppressionTest.java diff --git a/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java b/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java index 4f77f15a..6ecb2a6e 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java @@ -28,8 +28,9 @@ public class BugsnagSpringConfiguration implements InitializingBean { Callback springVersionErrorCallback() { Callback callback = new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { addSpringRuntimeVersion(report.getDevice()); + return true; } }; bugsnag.addCallback(callback); diff --git a/bugsnag-spring/src/main/java/com/bugsnag/ExceptionClassCallback.java b/bugsnag-spring/src/main/java/com/bugsnag/ExceptionClassCallback.java index 7addc1e8..b7c899e1 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/ExceptionClassCallback.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/ExceptionClassCallback.java @@ -111,7 +111,7 @@ class ExceptionClassCallback implements Callback { } @Override - public void onError(Report report) { + public Boolean onError(Report report) { HandledState handledState = report.getHandledState(); @@ -119,7 +119,7 @@ public void onError(Report report) { SeverityReasonType severityReasonType = handledState.calculateSeverityReasonType(); if (severityReasonType == SeverityReasonType.REASON_USER_SPECIFIED || severityReasonType == SeverityReasonType.REASON_CALLBACK_SPECIFIED) { - return; + return true; // do not change delivery decision } Class exceptionClass = report.getException().getClass(); @@ -133,5 +133,6 @@ public void onError(Report report) { severity, handledState.isUnhandled())); } + return true; } } diff --git a/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java b/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java index 652b12f4..145a4b90 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java @@ -19,8 +19,9 @@ public class SpringBootConfiguration { Callback springBootVersionErrorCallback() { Callback callback = new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { addSpringRuntimeVersion(report.getDevice()); + return true; } }; bugsnag.addCallback(callback); diff --git a/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java b/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java index ce8f3c16..72c49dc9 100644 --- a/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java +++ b/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java @@ -190,8 +190,9 @@ public void unhandledTypeMismatchExceptionCallbackSeverity() Report report; Callback callback = new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setSeverity(Severity.WARNING); + return true; } }; diff --git a/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java index 51da1e18..99824277 100644 --- a/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java +++ b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java @@ -67,8 +67,9 @@ public void handledTypeMismatchExceptionCallbackSeverity() { } catch (TypeMismatchException ex) { bugsnag.notify(ex, new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setSeverity(Severity.WARNING); + return true; } }); } diff --git a/bugsnag/src/main/java/com/bugsnag/Bugsnag.java b/bugsnag/src/main/java/com/bugsnag/Bugsnag.java index 2c0ab89f..d6a45bab 100644 --- a/bugsnag/src/main/java/com/bugsnag/Bugsnag.java +++ b/bugsnag/src/main/java/com/bugsnag/Bugsnag.java @@ -455,13 +455,9 @@ public boolean notify(Report report, Callback reportCallback) { // Run all client-wide onError callbacks for (Callback callback : config.callbacks) { try { - // Run the callback - callback.onError(report); - - // Check if callback cancelled delivery - if (report.getShouldCancel()) { - LOGGER.debug("Error not reported to Bugsnag - " - + "cancelled by a client-wide onError callback"); + Boolean proceed = callback.onError(report); + if (Boolean.FALSE.equals(proceed) || report.getShouldCancel()) { + LOGGER.debug("Error not reported to Bugsnag - cancelled by a client-wide onError callback"); return false; } } catch (Throwable ex) { @@ -475,13 +471,9 @@ public boolean notify(Report report, Callback reportCallback) { // Run the report-specific onError callback, if given if (reportCallback != null) { try { - // Run the callback - reportCallback.onError(report); - - // Check if callback cancelled delivery - if (report.getShouldCancel()) { - LOGGER.debug( - "Error not reported to Bugsnag - cancelled by a report-specific callback"); + Boolean proceed = reportCallback.onError(report); + if (Boolean.FALSE.equals(proceed) || report.getShouldCancel()) { + LOGGER.debug("Error not reported to Bugsnag - cancelled by a report-specific callback"); return false; } } catch (Throwable ex) { diff --git a/bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java b/bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java index f3bb5472..9c81a146 100644 --- a/bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java +++ b/bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java @@ -134,7 +134,7 @@ protected void append(final ILoggingEvent event) { calculateSeverity(event), new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { // Add some data from the logging event report.addToTab("Log event data", @@ -146,8 +146,12 @@ public void onError(Report report) { populateContextData(report, event); if (reportCallback != null) { - reportCallback.onError(report); + Boolean proceed = reportCallback.onError(report); + if (Boolean.FALSE.equals(proceed)) { + return false; // suppress delivery + } } + return true; } }); } @@ -270,7 +274,7 @@ private Bugsnag createBugsnag() { // Add a callback to put global metadata on every report bugsnag.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { for (LogbackMetadata metadata : globalMetadata) { for (LogbackMetadataTab tab : metadata.getTabs()) { @@ -282,6 +286,7 @@ public void onError(Report report) { } } + return true; } }); diff --git a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java index e4d22e62..9b412987 100644 --- a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java +++ b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java @@ -3,6 +3,7 @@ import com.bugsnag.delivery.Delivery; import java.util.ArrayList; +import java.util.Collections; import java.util.Collection; import java.util.Date; import java.util.UUID; diff --git a/bugsnag/src/main/java/com/bugsnag/callbacks/AppCallback.java b/bugsnag/src/main/java/com/bugsnag/callbacks/AppCallback.java index 59c7dd0d..f4fea441 100644 --- a/bugsnag/src/main/java/com/bugsnag/callbacks/AppCallback.java +++ b/bugsnag/src/main/java/com/bugsnag/callbacks/AppCallback.java @@ -11,7 +11,7 @@ public AppCallback(Configuration config) { } @Override - public void onError(Report report) { + public Boolean onError(Report report) { if (config.appType != null) { report.setAppInfo("type", config.appType); } @@ -23,5 +23,6 @@ public void onError(Report report) { if (config.releaseStage != null) { report.setAppInfo("releaseStage", config.releaseStage); } + return true; } } diff --git a/bugsnag/src/main/java/com/bugsnag/callbacks/Callback.java b/bugsnag/src/main/java/com/bugsnag/callbacks/Callback.java index 88096c68..a0f06ffd 100644 --- a/bugsnag/src/main/java/com/bugsnag/callbacks/Callback.java +++ b/bugsnag/src/main/java/com/bugsnag/callbacks/Callback.java @@ -5,8 +5,12 @@ public interface Callback { /** * Perform changes to the report before delivery. + * Return {@code true} to continue sending, or {@code false} to cancel delivery. + * Implementations may also call {@code report.cancel()} for backward + * compatibility. * * @param report the report to perform changes on. + * @return true to send, false to suppress delivery */ - void onError(Report report); + Boolean onError(Report report); } diff --git a/bugsnag/src/main/java/com/bugsnag/callbacks/DeviceCallback.java b/bugsnag/src/main/java/com/bugsnag/callbacks/DeviceCallback.java index 8969fbcb..dc3868c9 100644 --- a/bugsnag/src/main/java/com/bugsnag/callbacks/DeviceCallback.java +++ b/bugsnag/src/main/java/com/bugsnag/callbacks/DeviceCallback.java @@ -84,12 +84,13 @@ public void run() { } @Override - public void onError(Report report) { + public Boolean onError(Report report) { report .addToTab("device", "osArch", System.getProperty("os.arch")) .addToTab("device", "locale", Locale.getDefault()) .setDeviceInfo("hostname", getHostnameValue()) .setDeviceInfo("osName", System.getProperty("os.name")) .setDeviceInfo("osVersion", System.getProperty("os.version")); + return true; } } diff --git a/bugsnag/src/main/java/com/bugsnag/callbacks/JakartaServletCallback.java b/bugsnag/src/main/java/com/bugsnag/callbacks/JakartaServletCallback.java index 4e0d8492..1e1bca80 100644 --- a/bugsnag/src/main/java/com/bugsnag/callbacks/JakartaServletCallback.java +++ b/bugsnag/src/main/java/com/bugsnag/callbacks/JakartaServletCallback.java @@ -26,11 +26,11 @@ public static boolean isAvailable() { } @Override - public void onError(Report report) { + public Boolean onError(Report report) { // Check if we have any servlet request data available HttpServletRequest request = BugsnagServletRequestListener.getServletRequest(); if (request == null) { - return; + return true; // nothing to add, but do not cancel } // Add request information to metadata @@ -46,6 +46,7 @@ public void onError(Report report) { if (report.getContext() == null) { report.setContext(request.getMethod() + " " + request.getRequestURI()); } + return true; } private String getClientIp(HttpServletRequest request) { diff --git a/bugsnag/src/test/java/com/bugsnag/AppenderMetadataTest.java b/bugsnag/src/test/java/com/bugsnag/AppenderMetadataTest.java index 65b1dcff..62ba0359 100644 --- a/bugsnag/src/test/java/com/bugsnag/AppenderMetadataTest.java +++ b/bugsnag/src/test/java/com/bugsnag/AppenderMetadataTest.java @@ -111,12 +111,12 @@ public void testMetadataRemoval() { // Send three test logs, the first one with report metadata added LOGGER.warn(new BugsnagMarker(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.addToTab("report", "some key", "some report value"); + return true; } }), "Test exception", new RuntimeException("test")); - LOGGER.warn("Test exception", new RuntimeException("test")); Bugsnag.clearThreadMetadata(); LOGGER.warn("Test exception", new RuntimeException("test")); diff --git a/bugsnag/src/test/java/com/bugsnag/AppenderTest.java b/bugsnag/src/test/java/com/bugsnag/AppenderTest.java index eba20ba3..4d020538 100644 --- a/bugsnag/src/test/java/com/bugsnag/AppenderTest.java +++ b/bugsnag/src/test/java/com/bugsnag/AppenderTest.java @@ -298,7 +298,7 @@ public void testCallback() { // Setup a callback to set the user appender.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setUserName("User Name"); report.setUserEmail("user@example.com"); report.setUserId("12345"); @@ -306,8 +306,8 @@ public void onError(Report report) { report.setContext("the context"); report.setGroupingHash("the grouping hash"); - report.setApiKey("newapikey"); + return true; } }); diff --git a/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java b/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java index 3bd5d10d..0330d3dc 100644 --- a/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java +++ b/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java @@ -188,11 +188,12 @@ public void close() { }); assertTrue(bugsnag.notify(new Throwable(), new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.addToTab("firsttab", "testredact1", "secretpassword"); report.addToTab("firsttab", "testredact2", "secretpassword"); report.addToTab("firsttab", "testredact3", "secretpassword"); report.addToTab("secondtab", "testredact1", "secretpassword"); + return true; } })); } @@ -223,7 +224,7 @@ public void close() { assertTrue(bugsnag.notify(new Throwable(), new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { Map headers = new HashMap(); headers.put("Authorization", "User:Password"); headers.put("authorization", "User:Password"); @@ -231,6 +232,7 @@ public void onError(Report report) { headers.put("cookie", "123456ABCDEF"); report.addToTab("request", "headers", headers); + return true; } })); } @@ -252,8 +254,9 @@ public void close() { }); assertTrue(bugsnag.notify(new Throwable(), new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setUser("123", "test@example.com", "test name"); + return true; } })); } @@ -262,8 +265,9 @@ public void onError(Report report) { public void testContext() { bugsnag.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setContext("the context"); + return true; } }); bugsnag.setDelivery(new Delivery() { @@ -284,8 +288,9 @@ public void close() { public void testGroupingHash() { bugsnag.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setGroupingHash("the grouping hash"); + return true; } }); bugsnag.setDelivery(new Delivery() { @@ -306,8 +311,9 @@ public void close() { public void testSingleCallback() { bugsnag.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setApiKey("newapikey"); + return true; } }); bugsnag.setDelivery(new Delivery() { @@ -340,8 +346,9 @@ public void close() { assertTrue(bugsnag.notify(new Throwable(), new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setApiKey("newapikey"); + return true; } })); } @@ -350,14 +357,16 @@ public void onError(Report report) { public void testCallbackOrder() { bugsnag.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setApiKey("newapikey"); + return true; } }); bugsnag.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setApiKey("secondnewapikey"); + return true; } }); bugsnag.setDelivery(new Delivery() { @@ -379,8 +388,9 @@ public void testCallbackCancel() { bugsnag.setDelivery(BugsnagTestUtils.generateDelivery()); bugsnag.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.cancel(); + return true; // cancellation flag respected } }); // Test the report is not sent diff --git a/bugsnag/src/test/java/com/bugsnag/CallbackSuppressionTest.java b/bugsnag/src/test/java/com/bugsnag/CallbackSuppressionTest.java new file mode 100644 index 00000000..6ad8a6e2 --- /dev/null +++ b/bugsnag/src/test/java/com/bugsnag/CallbackSuppressionTest.java @@ -0,0 +1,57 @@ +package com.bugsnag; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import com.bugsnag.callbacks.Callback; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class CallbackSuppressionTest { + + private Bugsnag bugsnag; + private StubNotificationDelivery delivery; + + @Before + public void setUp() { + bugsnag = new Bugsnag("apikey"); + delivery = new StubNotificationDelivery(); + bugsnag.setDelivery(delivery); + } + + @After + public void tearDown() { + bugsnag.close(); + } + + @Test + public void callbackReturningFalseSuppressesDelivery() { + bugsnag.addCallback(new Callback() { + @Override + public Boolean onError(Report report) { + return false; // explicit suppression + } + }); + + boolean result = bugsnag.notify(new RuntimeException("Suppressed")); + assertFalse("notify should return false when suppressed", result); + assertEquals("No notifications should be delivered", 0, delivery.getNotifications().size()); + } + + @Test + public void callbackReturningTrueAllowsDelivery() { + bugsnag.addCallback(new Callback() { + @Override + public Boolean onError(Report report) { + return true; // allow + } + }); + + boolean result = bugsnag.notify(new RuntimeException("Allowed")); + assertTrue(result); + assertEquals(1, delivery.getNotifications().size()); + } +} \ No newline at end of file diff --git a/bugsnag/src/test/java/com/bugsnag/ConcurrentCallbackTest.java b/bugsnag/src/test/java/com/bugsnag/ConcurrentCallbackTest.java index 4858166f..da00b9c2 100644 --- a/bugsnag/src/test/java/com/bugsnag/ConcurrentCallbackTest.java +++ b/bugsnag/src/test/java/com/bugsnag/ConcurrentCallbackTest.java @@ -30,14 +30,16 @@ public void testClientNotifyModification() { config.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { // modify the callback collection, when iterating to the next callback this // should not crash config.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { + return true; } }); + return true; } }); bugsnag.notify(new RuntimeException()); diff --git a/bugsnag/src/test/java/com/bugsnag/ExceptionTest.java b/bugsnag/src/test/java/com/bugsnag/ExceptionTest.java index 9ae7e107..26188965 100644 --- a/bugsnag/src/test/java/com/bugsnag/ExceptionTest.java +++ b/bugsnag/src/test/java/com/bugsnag/ExceptionTest.java @@ -62,7 +62,7 @@ public void close() { }); assertTrue(bugsnag.notify(ogThrowable, new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { try { assertEquals(ogThrowable, report.getException()); assertEquals("Test", report.getExceptionMessage()); @@ -71,7 +71,6 @@ public void onError(Report report) { report.setExceptionName("Foo"); assertEquals("Foo", report.getExceptionName()); - List exceptions = report.getExceptions(); assertEquals(1, exceptions.size()); @@ -82,6 +81,7 @@ public void onError(Report report) { } catch (Throwable throwable) { report.cancel(); } + return !report.getShouldCancel(); } })); diff --git a/bugsnag/src/test/java/com/bugsnag/MarkerTest.java b/bugsnag/src/test/java/com/bugsnag/MarkerTest.java index a2af0dc0..d7214ddc 100644 --- a/bugsnag/src/test/java/com/bugsnag/MarkerTest.java +++ b/bugsnag/src/test/java/com/bugsnag/MarkerTest.java @@ -13,7 +13,6 @@ import java.util.Iterator; - /** * Tests for the Bugsnag Marker internal logic */ @@ -29,8 +28,8 @@ public class MarkerTest { public void createMarker() { callback = new Callback() { @Override - public void onError(Report report) { - + public Boolean onError(Report report) { + return true; } }; diff --git a/examples/simple/src/main/java/com/bugsnag/example/simple/ExampleApp.java b/examples/simple/src/main/java/com/bugsnag/example/simple/ExampleApp.java index a8185175..8f74427c 100644 --- a/examples/simple/src/main/java/com/bugsnag/example/simple/ExampleApp.java +++ b/examples/simple/src/main/java/com/bugsnag/example/simple/ExampleApp.java @@ -22,7 +22,7 @@ public static void main(String[] args) throws InterruptedException { // the lifecyle of your application bugsnag.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.addToTab("diagnostics", "timestamp", new Date()); report.addToTab("customer", "name", "acme-inc"); report.addToTab("customer", "paying", true); @@ -30,6 +30,7 @@ public void onError(Report report) { report.setUserName("User Name"); report.setUserEmail("user@example.com"); report.setUserId("12345"); + return true; } }); @@ -53,10 +54,11 @@ public void onError(Report report) { } catch (RuntimeException e) { bugsnag.notify(e, new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setSeverity(Severity.WARNING); report.addToTab("report", "something", "that happened"); report.setContext("the context"); + return true; } }); } diff --git a/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/ApplicationRestController.java b/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/ApplicationRestController.java index 4d141355..bb4816cf 100644 --- a/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/ApplicationRestController.java +++ b/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/ApplicationRestController.java @@ -71,10 +71,11 @@ public String sendHandledExceptionWithMetadata() { } catch (RuntimeException e) { bugsnag.notify(e, new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setSeverity(Severity.WARNING); report.addToTab("report", "something", "that happened"); report.setContext("the context"); + return true; } }); } diff --git a/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/Config.java b/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/Config.java index cc50bc4c..23a49d74 100644 --- a/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/Config.java +++ b/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/Config.java @@ -31,7 +31,7 @@ public Bugsnag bugsnag() { // the lifecyle of your application bugsnag.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.addToTab("diagnostics", "timestamp", new Date()); report.addToTab("customer", "name", "acme-inc"); report.addToTab("customer", "paying", true); @@ -39,6 +39,7 @@ public void onError(Report report) { report.setUserName("User Name"); report.setUserEmail("user@example.com"); report.setUserId("12345"); + return true; } }); diff --git a/examples/spring/src/main/java/com/bugsnag/example/spring/cli/ApplicationCommandLineRunner.java b/examples/spring/src/main/java/com/bugsnag/example/spring/cli/ApplicationCommandLineRunner.java index 896edb7d..ae0cb580 100644 --- a/examples/spring/src/main/java/com/bugsnag/example/spring/cli/ApplicationCommandLineRunner.java +++ b/examples/spring/src/main/java/com/bugsnag/example/spring/cli/ApplicationCommandLineRunner.java @@ -50,10 +50,11 @@ public void run(final String... args) throws Exception { } catch (RuntimeException e) { bugsnag.notify(e, new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setSeverity(Severity.WARNING); report.addToTab("report", "something", "that happened"); report.setContext("the context"); + return true; } }); } diff --git a/features/fixtures/mazerunnerspringboot3/src/main/java/com/bugsnag/mazerunner/scenarios/ScheduledTaskExecutorScenario.java b/features/fixtures/mazerunnerspringboot3/src/main/java/com/bugsnag/mazerunner/scenarios/ScheduledTaskExecutorScenario.java index 1abd25eb..8ae4e7e0 100644 --- a/features/fixtures/mazerunnerspringboot3/src/main/java/com/bugsnag/mazerunner/scenarios/ScheduledTaskExecutorScenario.java +++ b/features/fixtures/mazerunnerspringboot3/src/main/java/com/bugsnag/mazerunner/scenarios/ScheduledTaskExecutorScenario.java @@ -27,9 +27,10 @@ public void run() { final Collection threadnames = ScheduledTaskExecutorService.getThreadNames(); bugsnag.notify(new RuntimeException("Whoops"), new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.addToTab("executor", "multiThreaded", threadnames.size() > 1); report.addToTab("executor", "names", threadnames); + return true; } }); } diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/AutoRedactScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/AutoRedactScenario.java index f3b91b5f..e2b162af 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/AutoRedactScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/AutoRedactScenario.java @@ -17,10 +17,11 @@ public AutoRedactScenario(Bugsnag bugsnag) { public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.addToTab("user", "password", "hunter2"); report.addToTab("custom", "password", "hunter2"); report.addToTab("custom", "foo", "hunter2"); + return true; } }); } diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/LogbackMetadataScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/LogbackMetadataScenario.java index ef764a42..c341ac66 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/LogbackMetadataScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/LogbackMetadataScenario.java @@ -22,12 +22,13 @@ public LogbackMetadataScenario(Bugsnag bugsnag) { @Override public void run() { LOGGER.warn(new BugsnagMarker(new Callback() { - @Override - public void onError(Report report) { - report.addToTab("user", "foo", "hunter2"); - report.addToTab("custom", "foo", "hunter2"); - report.addToTab("custom", "bar", "hunter2"); - } - }),"Error sent to Bugsnag using the logback appender", generateException()); + @Override + public Boolean onError(Report report) { + report.addToTab("user", "foo", "hunter2"); + report.addToTab("custom", "foo", "hunter2"); + report.addToTab("custom", "bar", "hunter2"); + return true; + } + }), "Error sent to Bugsnag using the logback appender", generateException()); } } diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualContextScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualContextScenario.java index f8818f8f..4b26c466 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualContextScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualContextScenario.java @@ -17,8 +17,9 @@ public ManualContextScenario(Bugsnag bugsnag) { public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setContext("FooContext"); + return true; } }); } diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualRedactScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualRedactScenario.java index 653e949b..40584019 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualRedactScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualRedactScenario.java @@ -20,10 +20,11 @@ public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.addToTab("user", "foo", "hunter2"); report.addToTab("custom", "foo", "hunter2"); report.addToTab("custom", "bar", "hunter2"); + return true; } }); } diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/MetadataScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/MetadataScenario.java index 2d309e00..81ea6936 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/MetadataScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/MetadataScenario.java @@ -17,8 +17,9 @@ public MetadataScenario(Bugsnag bugsnag) { public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.addToTab("Custom", "foo", "Hello World!"); + return true; } }); } diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ThreadMetadataScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ThreadMetadataScenario.java index a9cf7466..12700edf 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ThreadMetadataScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ThreadMetadataScenario.java @@ -18,9 +18,10 @@ public void run() { // Global callback metadata has lowest precedence bugsnag.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.addToTab("Custom", "test", "Global value"); report.addToTab("Custom", "foo", "Global value to be overwritten"); + return true; } }); @@ -47,8 +48,9 @@ public void run() { // Report-specific metadata should merge with global + thread metadata and overwrite when duplicate key bugsnag.notify(generateException(), new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.addToTab("Custom", "bar", "Hello World!"); + return true; } }); } diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UnhandledThreadMetadataScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UnhandledThreadMetadataScenario.java index 0a6f9086..43980ebc 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UnhandledThreadMetadataScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UnhandledThreadMetadataScenario.java @@ -18,9 +18,10 @@ public void run() { // Global callback metadata has lowest precedence bugsnag.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.addToTab("Custom", "test", "Global value"); report.addToTab("Custom", "foo", "Global value to be overwritten"); + return true; } }); diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UserCallbackScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UserCallbackScenario.java index 7b58d88a..b4de2fd9 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UserCallbackScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UserCallbackScenario.java @@ -17,8 +17,9 @@ public UserCallbackScenario(Bugsnag bugsnag) { public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.setUser("Agent Pink", "bob@example.com", "Zebedee"); + return true; } }); } From 6ad361208df775ab5a4d68dd2b78c7cdd5fe7020 Mon Sep 17 00:00:00 2001 From: richard elms Date: Mon, 17 Nov 2025 13:41:25 +0100 Subject: [PATCH 07/13] correct import order --- .../java/com/bugsnag/SessionTrackerTest.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java b/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java index 0adc29d3..11d9b90e 100644 --- a/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java +++ b/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java @@ -10,17 +10,14 @@ import com.bugsnag.delivery.Delivery; import com.bugsnag.serialization.Serializer; - -import org.junit.Before; -import org.junit.Test; - import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; - +import java.util.concurrent.CountDownLatch; +import org.junit.Before; +import org.junit.Test; public class SessionTrackerTest { @@ -185,7 +182,6 @@ public void deliver(Serializer serializer, Object object, Map he super.deliver(serializer, object, headers); SessionPayload payload = (SessionPayload) object; - List sessionCounts = (List) payload.getSessionCounts(); assertEquals(3, sessionCounts.size()); @@ -284,7 +280,8 @@ public void deliver(Serializer serializer, Object object, Map he @Test public void zeroSessionCount() { - CustomDelivery sessionDelivery = new CustomDelivery() {}; + CustomDelivery sessionDelivery = new CustomDelivery() { + }; configuration.sessionDelivery = sessionDelivery; sessionTracker.flushSessions(new Date(10120000L)); sessionTracker.flushSessions(new Date(14000000L)); @@ -300,7 +297,8 @@ public void testSessionShutdownStartSession() { @Test public void testSessionShutdownDelivers() { - CustomDelivery delivery = new CustomDelivery() {}; + CustomDelivery delivery = new CustomDelivery() { + }; configuration.sessionDelivery = delivery; sessionTracker.startSession(new Date(), true); @@ -311,7 +309,8 @@ public void testSessionShutdownDelivers() { @Test public void testMultiShutdown() { - CustomDelivery delivery = new CustomDelivery() {}; + CustomDelivery delivery = new CustomDelivery() { + }; configuration.sessionDelivery = delivery; sessionTracker.startSession(new Date(), true); From 62401da44ab99450421d8f1b691e94601d26468a Mon Sep 17 00:00:00 2001 From: richard elms Date: Mon, 17 Nov 2025 19:10:34 +0100 Subject: [PATCH 08/13] e2e fix --- bugsnag/src/main/java/com/bugsnag/SessionTracker.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java index 9b412987..d5919299 100644 --- a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java +++ b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java @@ -86,14 +86,12 @@ private void sendSessions(Date now) { if (!enqueuedSessionCounts.isEmpty() && flushingRequest.tryAcquire(1)) { try { - Collection requestValues = - new ArrayList(enqueuedSessionCounts); + Collection requestValues = new ArrayList(enqueuedSessionCounts); Collection approvedSessions = new ArrayList(); for (SessionCount sessionCount : requestValues) { - SessionPayload singlePayload = - new SessionPayload(Collections.singleton(sessionCount), config); + SessionPayload singlePayload = new SessionPayload(Collections.singleton(sessionCount), config); boolean sendThisSession = true; for (OnSession callback : sessionCallbacks) { From 403d507d74358448411fdaac5a2ebec8b2e40751 Mon Sep 17 00:00:00 2001 From: richard elms Date: Tue, 18 Nov 2025 08:35:34 +0100 Subject: [PATCH 09/13] session payload fix --- .../main/java/com/bugsnag/SessionPayload.java | 15 +++++++++++++-- .../main/java/com/bugsnag/SessionTracker.java | 16 +++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/bugsnag/src/main/java/com/bugsnag/SessionPayload.java b/bugsnag/src/main/java/com/bugsnag/SessionPayload.java index ac259dab..f7ef93d9 100644 --- a/bugsnag/src/main/java/com/bugsnag/SessionPayload.java +++ b/bugsnag/src/main/java/com/bugsnag/SessionPayload.java @@ -9,10 +9,21 @@ final class SessionPayload { private final Collection sessionCounts; private final Diagnostics diagnostics; + private final Map device; + private final Map app; SessionPayload(Collection sessionCounts, Configuration configuration) { this.sessionCounts = sessionCounts; diagnostics = new Diagnostics(configuration); + this.device = null; + this.app = null; + } + + SessionPayload(Collection sessionCounts, Map device, Map app) { + this.sessionCounts = sessionCounts; + this.diagnostics = null; + this.device = device; + this.app = app; } @Expose @@ -22,12 +33,12 @@ Notifier getNotifier() { @Expose Map getDevice() { - return diagnostics.device; + return device != null ? device : diagnostics.device; } @Expose Map getApp() { - return diagnostics.app; + return app != null ? app : diagnostics.app; } @Expose diff --git a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java index d5919299..67c02d8c 100644 --- a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java +++ b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java @@ -87,15 +87,15 @@ private void sendSessions(Date now) { if (!enqueuedSessionCounts.isEmpty() && flushingRequest.tryAcquire(1)) { try { Collection requestValues = new ArrayList(enqueuedSessionCounts); - Collection approvedSessions = new ArrayList(); + SessionPayload firstPayload = null; for (SessionCount sessionCount : requestValues) { - SessionPayload singlePayload = new SessionPayload(Collections.singleton(sessionCount), config); + SessionPayload payload = new SessionPayload(Collections.singleton(sessionCount), config); boolean sendThisSession = true; for (OnSession callback : sessionCallbacks) { - if (!callback.onSession(singlePayload)) { + if (!callback.onSession(payload)) { sendThisSession = false; break; } @@ -103,13 +103,19 @@ private void sendSessions(Date now) { if (sendThisSession) { approvedSessions.add(sessionCount); + if (firstPayload == null) { + firstPayload = payload; + } } } if (!approvedSessions.isEmpty()) { - SessionPayload payload = new SessionPayload(approvedSessions, config); + // Reuse the device/app from the first approved payload to preserve runtime + // versions + SessionPayload batchPayload = new SessionPayload(approvedSessions, firstPayload.getDevice(), + firstPayload.getApp()); Delivery delivery = config.sessionDelivery; - delivery.deliver(config.serializer, payload, config.getSessionApiHeaders()); + delivery.deliver(config.serializer, batchPayload, config.getSessionApiHeaders()); } enqueuedSessionCounts.removeAll(requestValues); From 9f24d9d556540a7ebfe219494bc4f386d3ca37ee Mon Sep 17 00:00:00 2001 From: richard elms Date: Tue, 18 Nov 2025 08:39:57 +0100 Subject: [PATCH 10/13] import order --- bugsnag/src/main/java/com/bugsnag/SessionTracker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java index 67c02d8c..65ab82a6 100644 --- a/bugsnag/src/main/java/com/bugsnag/SessionTracker.java +++ b/bugsnag/src/main/java/com/bugsnag/SessionTracker.java @@ -3,8 +3,8 @@ import com.bugsnag.delivery.Delivery; import java.util.ArrayList; -import java.util.Collections; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.UUID; import java.util.concurrent.ConcurrentLinkedQueue; From b861c9b64a2b0143daa1da4db3442f8a6e37c981 Mon Sep 17 00:00:00 2001 From: richard elms Date: Tue, 18 Nov 2025 08:49:48 +0100 Subject: [PATCH 11/13] update example --- .../test/java/com/bugsnag/CallbackSuppressionTest.java | 5 ++++- bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java | 8 +++++--- .../java/com/bugsnag/example/logback/cli/Application.java | 8 ++++++-- .../main/java/com/bugsnag/example/spring/cli/Config.java | 6 ++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/bugsnag/src/test/java/com/bugsnag/CallbackSuppressionTest.java b/bugsnag/src/test/java/com/bugsnag/CallbackSuppressionTest.java index 6ad8a6e2..70a0e235 100644 --- a/bugsnag/src/test/java/com/bugsnag/CallbackSuppressionTest.java +++ b/bugsnag/src/test/java/com/bugsnag/CallbackSuppressionTest.java @@ -15,6 +15,9 @@ public class CallbackSuppressionTest { private Bugsnag bugsnag; private StubNotificationDelivery delivery; + /** + * Set up test fixtures. + */ @Before public void setUp() { bugsnag = new Bugsnag("apikey"); @@ -54,4 +57,4 @@ public Boolean onError(Report report) { assertTrue(result); assertEquals(1, delivery.getNotifications().size()); } -} \ No newline at end of file +} diff --git a/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java b/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java index 11d9b90e..cc282997 100644 --- a/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java +++ b/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java @@ -10,14 +10,16 @@ import com.bugsnag.delivery.Delivery; import com.bugsnag.serialization.Serializer; + +import org.junit.Before; +import org.junit.Test; + import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.CountDownLatch; -import org.junit.Before; -import org.junit.Test; +import java.util.concurrent.atomic.AtomicInteger; public class SessionTrackerTest { diff --git a/examples/logback/src/main/java/com/bugsnag/example/logback/cli/Application.java b/examples/logback/src/main/java/com/bugsnag/example/logback/cli/Application.java index 08b77577..a15208c1 100644 --- a/examples/logback/src/main/java/com/bugsnag/example/logback/cli/Application.java +++ b/examples/logback/src/main/java/com/bugsnag/example/logback/cli/Application.java @@ -16,7 +16,8 @@ public class Application { public static void main(String[] args) throws Exception { - ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); + ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory + .getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); Appender appender = rootLogger.getAppender("BUGSNAG"); if (appender instanceof BugsnagAppender) { // Set some global meta data (added to each report) @@ -28,6 +29,7 @@ public static void main(String[] args) throws Exception { report.setUserName("User Name"); report.setUserEmail("user@example.com"); report.setUserId("12345"); + return true; }); } @@ -58,6 +60,7 @@ public static void main(String[] args) throws Exception { LOGGER.warn(new BugsnagMarker((report) -> { report.addToTab("report tab", "data key 1", "data value 1"); report.addToTab("report tab", "data key 2", "data value 2"); + return true; }), "Something bad happened", e); } @@ -76,7 +79,8 @@ public void run() { // Wait for unhandled exception thread to finish before exiting thread.join(); - // Remove the thread metadata so it won't be added to future reports on this thread + // Remove the thread metadata so it won't be added to future reports on this + // thread Bugsnag.clearThreadMetadata(); // Exit the application diff --git a/examples/spring/src/main/java/com/bugsnag/example/spring/cli/Config.java b/examples/spring/src/main/java/com/bugsnag/example/spring/cli/Config.java index e60f0553..5ad01d53 100644 --- a/examples/spring/src/main/java/com/bugsnag/example/spring/cli/Config.java +++ b/examples/spring/src/main/java/com/bugsnag/example/spring/cli/Config.java @@ -15,7 +15,8 @@ @Import(BugsnagSpringConfiguration.class) public class Config { - // Define singleton bean "bugsnag" which can be injected into any Spring managed class with @Autowired. + // Define singleton bean "bugsnag" which can be injected into any Spring managed + // class with @Autowired. @Bean public Bugsnag bugsnag() { // Create a Bugsnag client @@ -31,7 +32,7 @@ public Bugsnag bugsnag() { // the lifecyle of your application bugsnag.addCallback(new Callback() { @Override - public void onError(Report report) { + public Boolean onError(Report report) { report.addToTab("diagnostics", "timestamp", new Date()); report.addToTab("customer", "name", "acme-inc"); report.addToTab("customer", "paying", true); @@ -39,6 +40,7 @@ public void onError(Report report) { report.setUserName("User Name"); report.setUserEmail("user@example.com"); report.setUserId("12345"); + return true; } }); From 1ac77b03ea8ee97bf05c87f84a6661da1ec2d9d7 Mon Sep 17 00:00:00 2001 From: richard elms Date: Tue, 18 Nov 2025 13:24:28 +0100 Subject: [PATCH 12/13] lambdas --- .../com/bugsnag/AppenderMetadataTest.java | 10 +- .../test/java/com/bugsnag/AppenderTest.java | 24 ++-- .../test/java/com/bugsnag/BugsnagTest.java | 107 +++++++----------- .../com/bugsnag/CallbackSuppressionTest.java | 16 +-- .../com/bugsnag/ConcurrentCallbackTest.java | 20 +--- .../test/java/com/bugsnag/ExceptionTest.java | 42 ++++--- .../src/test/java/com/bugsnag/MarkerTest.java | 7 +- 7 files changed, 78 insertions(+), 148 deletions(-) diff --git a/bugsnag/src/test/java/com/bugsnag/AppenderMetadataTest.java b/bugsnag/src/test/java/com/bugsnag/AppenderMetadataTest.java index 62ba0359..682087c5 100644 --- a/bugsnag/src/test/java/com/bugsnag/AppenderMetadataTest.java +++ b/bugsnag/src/test/java/com/bugsnag/AppenderMetadataTest.java @@ -6,7 +6,6 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import com.bugsnag.callbacks.Callback; import com.bugsnag.delivery.Delivery; import com.bugsnag.logback.BugsnagMarker; @@ -109,12 +108,9 @@ public void testMetadataRemoval() { Bugsnag.addThreadMetadata("thread", "some key", "some thread value"); // Send three test logs, the first one with report metadata added - LOGGER.warn(new BugsnagMarker(new Callback() { - @Override - public Boolean onError(Report report) { - report.addToTab("report", "some key", "some report value"); - return true; - } + LOGGER.warn(new BugsnagMarker(report -> { + report.addToTab("report", "some key", "some report value"); + return true; }), "Test exception", new RuntimeException("test")); LOGGER.warn("Test exception", new RuntimeException("test")); diff --git a/bugsnag/src/test/java/com/bugsnag/AppenderTest.java b/bugsnag/src/test/java/com/bugsnag/AppenderTest.java index 4d020538..e09d41af 100644 --- a/bugsnag/src/test/java/com/bugsnag/AppenderTest.java +++ b/bugsnag/src/test/java/com/bugsnag/AppenderTest.java @@ -5,7 +5,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import com.bugsnag.callbacks.Callback; import com.bugsnag.delivery.Delivery; import com.bugsnag.logback.ProxyConfiguration; @@ -296,19 +295,16 @@ public void testRedactedKeys() { public void testCallback() { // Setup a callback to set the user - appender.addCallback(new Callback() { - @Override - public Boolean onError(Report report) { - report.setUserName("User Name"); - report.setUserEmail("user@example.com"); - report.setUserId("12345"); - - report.setContext("the context"); - - report.setGroupingHash("the grouping hash"); - report.setApiKey("newapikey"); - return true; - } + appender.addCallback(report -> { + report.setUserName("User Name"); + report.setUserEmail("user@example.com"); + report.setUserId("12345"); + + report.setContext("the context"); + + report.setGroupingHash("the grouping hash"); + report.setApiKey("newapikey"); + return true; }); // Send a log message diff --git a/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java b/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java index 0330d3dc..10d19d49 100644 --- a/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java +++ b/bugsnag/src/test/java/com/bugsnag/BugsnagTest.java @@ -6,7 +6,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import com.bugsnag.callbacks.Callback; import com.bugsnag.delivery.Delivery; import com.bugsnag.delivery.HttpDelivery; import com.bugsnag.delivery.OutputStreamDelivery; @@ -186,15 +185,12 @@ public void deliver(Serializer serializer, Object object, Map he public void close() { } }); - assertTrue(bugsnag.notify(new Throwable(), new Callback() { - @Override - public Boolean onError(Report report) { - report.addToTab("firsttab", "testredact1", "secretpassword"); - report.addToTab("firsttab", "testredact2", "secretpassword"); - report.addToTab("firsttab", "testredact3", "secretpassword"); - report.addToTab("secondtab", "testredact1", "secretpassword"); - return true; - } + assertTrue(bugsnag.notify(new Throwable(), report -> { + report.addToTab("firsttab", "testredact1", "secretpassword"); + report.addToTab("firsttab", "testredact2", "secretpassword"); + report.addToTab("firsttab", "testredact3", "secretpassword"); + report.addToTab("secondtab", "testredact1", "secretpassword"); + return true; })); } @@ -222,18 +218,15 @@ public void close() { } }); - assertTrue(bugsnag.notify(new Throwable(), new Callback() { - @Override - public Boolean onError(Report report) { - Map headers = new HashMap(); - headers.put("Authorization", "User:Password"); - headers.put("authorization", "User:Password"); - headers.put("Cookie", "123456ABCDEF"); - headers.put("cookie", "123456ABCDEF"); + assertTrue(bugsnag.notify(new Throwable(), report -> { + Map headers = new HashMap(); + headers.put("Authorization", "User:Password"); + headers.put("authorization", "User:Password"); + headers.put("Cookie", "123456ABCDEF"); + headers.put("cookie", "123456ABCDEF"); - report.addToTab("request", "headers", headers); - return true; - } + report.addToTab("request", "headers", headers); + return true; })); } @@ -252,23 +245,17 @@ public void deliver(Serializer serializer, Object object, Map he public void close() { } }); - assertTrue(bugsnag.notify(new Throwable(), new Callback() { - @Override - public Boolean onError(Report report) { - report.setUser("123", "test@example.com", "test name"); - return true; - } + assertTrue(bugsnag.notify(new Throwable(), report -> { + report.setUser("123", "test@example.com", "test name"); + return true; })); } @Test public void testContext() { - bugsnag.addCallback(new Callback() { - @Override - public Boolean onError(Report report) { - report.setContext("the context"); - return true; - } + bugsnag.addCallback(report -> { + report.setContext("the context"); + return true; }); bugsnag.setDelivery(new Delivery() { @Override @@ -286,12 +273,9 @@ public void close() { @Test public void testGroupingHash() { - bugsnag.addCallback(new Callback() { - @Override - public Boolean onError(Report report) { - report.setGroupingHash("the grouping hash"); - return true; - } + bugsnag.addCallback(report -> { + report.setGroupingHash("the grouping hash"); + return true; }); bugsnag.setDelivery(new Delivery() { @Override @@ -309,12 +293,9 @@ public void close() { @Test public void testSingleCallback() { - bugsnag.addCallback(new Callback() { - @Override - public Boolean onError(Report report) { - report.setApiKey("newapikey"); - return true; - } + bugsnag.addCallback(report -> { + report.setApiKey("newapikey"); + return true; }); bugsnag.setDelivery(new Delivery() { @Override @@ -344,30 +325,21 @@ public void close() { } }); - assertTrue(bugsnag.notify(new Throwable(), new Callback() { - @Override - public Boolean onError(Report report) { - report.setApiKey("newapikey"); - return true; - } + assertTrue(bugsnag.notify(new Throwable(), report -> { + report.setApiKey("newapikey"); + return true; })); } @Test public void testCallbackOrder() { - bugsnag.addCallback(new Callback() { - @Override - public Boolean onError(Report report) { - report.setApiKey("newapikey"); - return true; - } + bugsnag.addCallback(report -> { + report.setApiKey("newapikey"); + return true; }); - bugsnag.addCallback(new Callback() { - @Override - public Boolean onError(Report report) { - report.setApiKey("secondnewapikey"); - return true; - } + bugsnag.addCallback(report -> { + report.setApiKey("secondnewapikey"); + return true; }); bugsnag.setDelivery(new Delivery() { @Override @@ -386,12 +358,9 @@ public void close() { @Test public void testCallbackCancel() { bugsnag.setDelivery(BugsnagTestUtils.generateDelivery()); - bugsnag.addCallback(new Callback() { - @Override - public Boolean onError(Report report) { - report.cancel(); - return true; // cancellation flag respected - } + bugsnag.addCallback(report -> { + report.cancel(); + return true; // cancellation flag respected }); // Test the report is not sent assertFalse(bugsnag.notify(new Throwable())); diff --git a/bugsnag/src/test/java/com/bugsnag/CallbackSuppressionTest.java b/bugsnag/src/test/java/com/bugsnag/CallbackSuppressionTest.java index 70a0e235..3de59d54 100644 --- a/bugsnag/src/test/java/com/bugsnag/CallbackSuppressionTest.java +++ b/bugsnag/src/test/java/com/bugsnag/CallbackSuppressionTest.java @@ -4,8 +4,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import com.bugsnag.callbacks.Callback; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -32,12 +30,7 @@ public void tearDown() { @Test public void callbackReturningFalseSuppressesDelivery() { - bugsnag.addCallback(new Callback() { - @Override - public Boolean onError(Report report) { - return false; // explicit suppression - } - }); + bugsnag.addCallback(report -> false); // explicit suppression boolean result = bugsnag.notify(new RuntimeException("Suppressed")); assertFalse("notify should return false when suppressed", result); @@ -46,12 +39,7 @@ public Boolean onError(Report report) { @Test public void callbackReturningTrueAllowsDelivery() { - bugsnag.addCallback(new Callback() { - @Override - public Boolean onError(Report report) { - return true; // allow - } - }); + bugsnag.addCallback(report -> true); // allow boolean result = bugsnag.notify(new RuntimeException("Allowed")); assertTrue(result); diff --git a/bugsnag/src/test/java/com/bugsnag/ConcurrentCallbackTest.java b/bugsnag/src/test/java/com/bugsnag/ConcurrentCallbackTest.java index da00b9c2..ce6f8f50 100644 --- a/bugsnag/src/test/java/com/bugsnag/ConcurrentCallbackTest.java +++ b/bugsnag/src/test/java/com/bugsnag/ConcurrentCallbackTest.java @@ -1,7 +1,5 @@ package com.bugsnag; -import com.bugsnag.callbacks.Callback; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -28,19 +26,11 @@ public void closeBugsnag() { public void testClientNotifyModification() { final Configuration config = bugsnag.getConfig(); - config.addCallback(new Callback() { - @Override - public Boolean onError(Report report) { - // modify the callback collection, when iterating to the next callback this - // should not crash - config.addCallback(new Callback() { - @Override - public Boolean onError(Report report) { - return true; - } - }); - return true; - } + config.addCallback(report -> { + // modify the callback collection, when iterating to the next callback this + // should not crash + config.addCallback(r -> true); + return true; }); bugsnag.notify(new RuntimeException()); } diff --git a/bugsnag/src/test/java/com/bugsnag/ExceptionTest.java b/bugsnag/src/test/java/com/bugsnag/ExceptionTest.java index 26188965..918e04e9 100644 --- a/bugsnag/src/test/java/com/bugsnag/ExceptionTest.java +++ b/bugsnag/src/test/java/com/bugsnag/ExceptionTest.java @@ -5,7 +5,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import com.bugsnag.callbacks.Callback; import com.bugsnag.delivery.Delivery; import com.bugsnag.serialization.Serializer; @@ -60,29 +59,26 @@ public void deliver(Serializer serializer, Object object, Map he public void close() { } }); - assertTrue(bugsnag.notify(ogThrowable, new Callback() { - @Override - public Boolean onError(Report report) { - try { - assertEquals(ogThrowable, report.getException()); - assertEquals("Test", report.getExceptionMessage()); - assertEquals("java.lang.RuntimeException", report.getExceptionName()); - - report.setExceptionName("Foo"); - assertEquals("Foo", report.getExceptionName()); - - List exceptions = report.getExceptions(); - assertEquals(1, exceptions.size()); - - Exception exception = exceptions.get(0); - assertNotNull(exception); - assertEquals("Foo", exception.getErrorClass()); - assertEquals("Test", exception.getMessage()); - } catch (Throwable throwable) { - report.cancel(); - } - return !report.getShouldCancel(); + assertTrue(bugsnag.notify(ogThrowable, report -> { + try { + assertEquals(ogThrowable, report.getException()); + assertEquals("Test", report.getExceptionMessage()); + assertEquals("java.lang.RuntimeException", report.getExceptionName()); + + report.setExceptionName("Foo"); + assertEquals("Foo", report.getExceptionName()); + + List exceptions = report.getExceptions(); + assertEquals(1, exceptions.size()); + + Exception exception = exceptions.get(0); + assertNotNull(exception); + assertEquals("Foo", exception.getErrorClass()); + assertEquals("Test", exception.getMessage()); + } catch (Throwable throwable) { + report.cancel(); } + return !report.getShouldCancel(); })); bugsnag.close(); diff --git a/bugsnag/src/test/java/com/bugsnag/MarkerTest.java b/bugsnag/src/test/java/com/bugsnag/MarkerTest.java index d7214ddc..69f62666 100644 --- a/bugsnag/src/test/java/com/bugsnag/MarkerTest.java +++ b/bugsnag/src/test/java/com/bugsnag/MarkerTest.java @@ -26,12 +26,7 @@ public class MarkerTest { */ @Before public void createMarker() { - callback = new Callback() { - @Override - public Boolean onError(Report report) { - return true; - } - }; + callback = report -> true; marker = new BugsnagMarker(callback); } From ce3754e42c7e708240bbfb46c657c09b2ad141a4 Mon Sep 17 00:00:00 2001 From: richard elms Date: Tue, 18 Nov 2025 13:32:47 +0100 Subject: [PATCH 13/13] switch to boolean --- .../main/java/com/bugsnag/BugsnagSpringConfiguration.java | 4 ++-- .../src/main/java/com/bugsnag/ExceptionClassCallback.java | 2 +- .../main/java/com/bugsnag/SpringBootConfiguration.java | 4 ++-- .../src/test/java/com/bugsnag/SpringMvcTest.java | 2 +- .../com/bugsnag/testapp/springboot/TestController.java | 2 +- bugsnag/src/main/java/com/bugsnag/Bugsnag.java | 8 ++++---- bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java | 8 ++++---- bugsnag/src/main/java/com/bugsnag/OnSession.java | 2 +- .../src/main/java/com/bugsnag/callbacks/AppCallback.java | 2 +- bugsnag/src/main/java/com/bugsnag/callbacks/Callback.java | 2 +- .../main/java/com/bugsnag/callbacks/DeviceCallback.java | 2 +- .../com/bugsnag/callbacks/JakartaServletCallback.java | 2 +- bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java | 2 +- .../main/java/com/bugsnag/example/simple/ExampleApp.java | 4 ++-- .../example/spring/web/ApplicationRestController.java | 2 +- .../main/java/com/bugsnag/example/spring/web/Config.java | 2 +- .../example/spring/cli/ApplicationCommandLineRunner.java | 2 +- .../main/java/com/bugsnag/example/spring/cli/Config.java | 2 +- .../scenarios/ScheduledTaskExecutorScenario.java | 2 +- .../bugsnag/mazerunner/scenarios/AutoRedactScenario.java | 2 +- .../mazerunner/scenarios/LogbackMetadataScenario.java | 2 +- .../mazerunner/scenarios/ManualContextScenario.java | 2 +- .../mazerunner/scenarios/ManualRedactScenario.java | 2 +- .../bugsnag/mazerunner/scenarios/MetadataScenario.java | 2 +- .../mazerunner/scenarios/ThreadMetadataScenario.java | 4 ++-- .../scenarios/UnhandledThreadMetadataScenario.java | 2 +- .../mazerunner/scenarios/UserCallbackScenario.java | 2 +- 27 files changed, 37 insertions(+), 37 deletions(-) diff --git a/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java b/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java index 6ecb2a6e..88aeae99 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/BugsnagSpringConfiguration.java @@ -28,7 +28,7 @@ public class BugsnagSpringConfiguration implements InitializingBean { Callback springVersionErrorCallback() { Callback callback = new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { addSpringRuntimeVersion(report.getDevice()); return true; } @@ -41,7 +41,7 @@ public Boolean onError(Report report) { OnSession springVersionSessionCallback() { OnSession onSession = new OnSession() { @Override - public Boolean onSession(SessionPayload payload) { + public boolean onSession(SessionPayload payload) { addSpringRuntimeVersion(payload.getDevice()); return true; } diff --git a/bugsnag-spring/src/main/java/com/bugsnag/ExceptionClassCallback.java b/bugsnag-spring/src/main/java/com/bugsnag/ExceptionClassCallback.java index b7c899e1..008f09d1 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/ExceptionClassCallback.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/ExceptionClassCallback.java @@ -111,7 +111,7 @@ class ExceptionClassCallback implements Callback { } @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { HandledState handledState = report.getHandledState(); diff --git a/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java b/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java index 145a4b90..aa5509ec 100644 --- a/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java +++ b/bugsnag-spring/src/main/java/com/bugsnag/SpringBootConfiguration.java @@ -19,7 +19,7 @@ public class SpringBootConfiguration { Callback springBootVersionErrorCallback() { Callback callback = new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { addSpringRuntimeVersion(report.getDevice()); return true; } @@ -32,7 +32,7 @@ public Boolean onError(Report report) { OnSession springBootVersionSessionCallback() { OnSession onSession = new OnSession() { @Override - public Boolean onSession(SessionPayload payload) { + public boolean onSession(SessionPayload payload) { addSpringRuntimeVersion(payload.getDevice()); return true; } diff --git a/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java b/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java index 72c49dc9..fcded466 100644 --- a/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java +++ b/bugsnag-spring/src/test/java/com/bugsnag/SpringMvcTest.java @@ -190,7 +190,7 @@ public void unhandledTypeMismatchExceptionCallbackSeverity() Report report; Callback callback = new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.setSeverity(Severity.WARNING); return true; } diff --git a/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java index 99824277..650bbf98 100644 --- a/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java +++ b/bugsnag-spring/src/test/java/com/bugsnag/testapp/springboot/TestController.java @@ -67,7 +67,7 @@ public void handledTypeMismatchExceptionCallbackSeverity() { } catch (TypeMismatchException ex) { bugsnag.notify(ex, new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.setSeverity(Severity.WARNING); return true; } diff --git a/bugsnag/src/main/java/com/bugsnag/Bugsnag.java b/bugsnag/src/main/java/com/bugsnag/Bugsnag.java index d6a45bab..21758962 100644 --- a/bugsnag/src/main/java/com/bugsnag/Bugsnag.java +++ b/bugsnag/src/main/java/com/bugsnag/Bugsnag.java @@ -455,8 +455,8 @@ public boolean notify(Report report, Callback reportCallback) { // Run all client-wide onError callbacks for (Callback callback : config.callbacks) { try { - Boolean proceed = callback.onError(report); - if (Boolean.FALSE.equals(proceed) || report.getShouldCancel()) { + boolean proceed = callback.onError(report); + if (!proceed || report.getShouldCancel()) { LOGGER.debug("Error not reported to Bugsnag - cancelled by a client-wide onError callback"); return false; } @@ -471,8 +471,8 @@ public boolean notify(Report report, Callback reportCallback) { // Run the report-specific onError callback, if given if (reportCallback != null) { try { - Boolean proceed = reportCallback.onError(report); - if (Boolean.FALSE.equals(proceed) || report.getShouldCancel()) { + boolean proceed = reportCallback.onError(report); + if (!proceed || report.getShouldCancel()) { LOGGER.debug("Error not reported to Bugsnag - cancelled by a report-specific callback"); return false; } diff --git a/bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java b/bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java index 9c81a146..7fe93bfd 100644 --- a/bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java +++ b/bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java @@ -134,7 +134,7 @@ protected void append(final ILoggingEvent event) { calculateSeverity(event), new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { // Add some data from the logging event report.addToTab("Log event data", @@ -146,8 +146,8 @@ public Boolean onError(Report report) { populateContextData(report, event); if (reportCallback != null) { - Boolean proceed = reportCallback.onError(report); - if (Boolean.FALSE.equals(proceed)) { + boolean proceed = reportCallback.onError(report); + if (!proceed) { return false; // suppress delivery } } @@ -274,7 +274,7 @@ private Bugsnag createBugsnag() { // Add a callback to put global metadata on every report bugsnag.addCallback(new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { for (LogbackMetadata metadata : globalMetadata) { for (LogbackMetadataTab tab : metadata.getTabs()) { diff --git a/bugsnag/src/main/java/com/bugsnag/OnSession.java b/bugsnag/src/main/java/com/bugsnag/OnSession.java index bf85f08a..b3349f54 100644 --- a/bugsnag/src/main/java/com/bugsnag/OnSession.java +++ b/bugsnag/src/main/java/com/bugsnag/OnSession.java @@ -2,5 +2,5 @@ @FunctionalInterface interface OnSession { - Boolean onSession(SessionPayload payload); + boolean onSession(SessionPayload payload); } diff --git a/bugsnag/src/main/java/com/bugsnag/callbacks/AppCallback.java b/bugsnag/src/main/java/com/bugsnag/callbacks/AppCallback.java index f4fea441..bcdc3b3b 100644 --- a/bugsnag/src/main/java/com/bugsnag/callbacks/AppCallback.java +++ b/bugsnag/src/main/java/com/bugsnag/callbacks/AppCallback.java @@ -11,7 +11,7 @@ public AppCallback(Configuration config) { } @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { if (config.appType != null) { report.setAppInfo("type", config.appType); } diff --git a/bugsnag/src/main/java/com/bugsnag/callbacks/Callback.java b/bugsnag/src/main/java/com/bugsnag/callbacks/Callback.java index a0f06ffd..1ef45428 100644 --- a/bugsnag/src/main/java/com/bugsnag/callbacks/Callback.java +++ b/bugsnag/src/main/java/com/bugsnag/callbacks/Callback.java @@ -12,5 +12,5 @@ public interface Callback { * @param report the report to perform changes on. * @return true to send, false to suppress delivery */ - Boolean onError(Report report); + boolean onError(Report report); } diff --git a/bugsnag/src/main/java/com/bugsnag/callbacks/DeviceCallback.java b/bugsnag/src/main/java/com/bugsnag/callbacks/DeviceCallback.java index dc3868c9..59005e59 100644 --- a/bugsnag/src/main/java/com/bugsnag/callbacks/DeviceCallback.java +++ b/bugsnag/src/main/java/com/bugsnag/callbacks/DeviceCallback.java @@ -84,7 +84,7 @@ public void run() { } @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report .addToTab("device", "osArch", System.getProperty("os.arch")) .addToTab("device", "locale", Locale.getDefault()) diff --git a/bugsnag/src/main/java/com/bugsnag/callbacks/JakartaServletCallback.java b/bugsnag/src/main/java/com/bugsnag/callbacks/JakartaServletCallback.java index 1e1bca80..b11dd73b 100644 --- a/bugsnag/src/main/java/com/bugsnag/callbacks/JakartaServletCallback.java +++ b/bugsnag/src/main/java/com/bugsnag/callbacks/JakartaServletCallback.java @@ -26,7 +26,7 @@ public static boolean isAvailable() { } @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { // Check if we have any servlet request data available HttpServletRequest request = BugsnagServletRequestListener.getServletRequest(); if (request == null) { diff --git a/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java b/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java index cc282997..872b0956 100644 --- a/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java +++ b/bugsnag/src/test/java/com/bugsnag/SessionTrackerTest.java @@ -337,7 +337,7 @@ public void deliver(Serializer serializer, Object object, Map he // Add callback which returns false to suppress sending sessionTracker.addOnSession(new OnSession() { @Override - public Boolean onSession(SessionPayload payload) { + public boolean onSession(SessionPayload payload) { return false; // suppress delivery } }); diff --git a/examples/simple/src/main/java/com/bugsnag/example/simple/ExampleApp.java b/examples/simple/src/main/java/com/bugsnag/example/simple/ExampleApp.java index 8f74427c..41059c11 100644 --- a/examples/simple/src/main/java/com/bugsnag/example/simple/ExampleApp.java +++ b/examples/simple/src/main/java/com/bugsnag/example/simple/ExampleApp.java @@ -22,7 +22,7 @@ public static void main(String[] args) throws InterruptedException { // the lifecyle of your application bugsnag.addCallback(new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.addToTab("diagnostics", "timestamp", new Date()); report.addToTab("customer", "name", "acme-inc"); report.addToTab("customer", "paying", true); @@ -54,7 +54,7 @@ public Boolean onError(Report report) { } catch (RuntimeException e) { bugsnag.notify(e, new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.setSeverity(Severity.WARNING); report.addToTab("report", "something", "that happened"); report.setContext("the context"); diff --git a/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/ApplicationRestController.java b/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/ApplicationRestController.java index bb4816cf..584934d8 100644 --- a/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/ApplicationRestController.java +++ b/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/ApplicationRestController.java @@ -71,7 +71,7 @@ public String sendHandledExceptionWithMetadata() { } catch (RuntimeException e) { bugsnag.notify(e, new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.setSeverity(Severity.WARNING); report.addToTab("report", "something", "that happened"); report.setContext("the context"); diff --git a/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/Config.java b/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/Config.java index 23a49d74..e7385514 100644 --- a/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/Config.java +++ b/examples/spring-web/src/main/java/com/bugsnag/example/spring/web/Config.java @@ -31,7 +31,7 @@ public Bugsnag bugsnag() { // the lifecyle of your application bugsnag.addCallback(new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.addToTab("diagnostics", "timestamp", new Date()); report.addToTab("customer", "name", "acme-inc"); report.addToTab("customer", "paying", true); diff --git a/examples/spring/src/main/java/com/bugsnag/example/spring/cli/ApplicationCommandLineRunner.java b/examples/spring/src/main/java/com/bugsnag/example/spring/cli/ApplicationCommandLineRunner.java index ae0cb580..2f26233d 100644 --- a/examples/spring/src/main/java/com/bugsnag/example/spring/cli/ApplicationCommandLineRunner.java +++ b/examples/spring/src/main/java/com/bugsnag/example/spring/cli/ApplicationCommandLineRunner.java @@ -50,7 +50,7 @@ public void run(final String... args) throws Exception { } catch (RuntimeException e) { bugsnag.notify(e, new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.setSeverity(Severity.WARNING); report.addToTab("report", "something", "that happened"); report.setContext("the context"); diff --git a/examples/spring/src/main/java/com/bugsnag/example/spring/cli/Config.java b/examples/spring/src/main/java/com/bugsnag/example/spring/cli/Config.java index 5ad01d53..3aff0375 100644 --- a/examples/spring/src/main/java/com/bugsnag/example/spring/cli/Config.java +++ b/examples/spring/src/main/java/com/bugsnag/example/spring/cli/Config.java @@ -32,7 +32,7 @@ public Bugsnag bugsnag() { // the lifecyle of your application bugsnag.addCallback(new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.addToTab("diagnostics", "timestamp", new Date()); report.addToTab("customer", "name", "acme-inc"); report.addToTab("customer", "paying", true); diff --git a/features/fixtures/mazerunnerspringboot3/src/main/java/com/bugsnag/mazerunner/scenarios/ScheduledTaskExecutorScenario.java b/features/fixtures/mazerunnerspringboot3/src/main/java/com/bugsnag/mazerunner/scenarios/ScheduledTaskExecutorScenario.java index 8ae4e7e0..3ab87cd8 100644 --- a/features/fixtures/mazerunnerspringboot3/src/main/java/com/bugsnag/mazerunner/scenarios/ScheduledTaskExecutorScenario.java +++ b/features/fixtures/mazerunnerspringboot3/src/main/java/com/bugsnag/mazerunner/scenarios/ScheduledTaskExecutorScenario.java @@ -27,7 +27,7 @@ public void run() { final Collection threadnames = ScheduledTaskExecutorService.getThreadNames(); bugsnag.notify(new RuntimeException("Whoops"), new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.addToTab("executor", "multiThreaded", threadnames.size() > 1); report.addToTab("executor", "names", threadnames); return true; diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/AutoRedactScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/AutoRedactScenario.java index e2b162af..3615278c 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/AutoRedactScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/AutoRedactScenario.java @@ -17,7 +17,7 @@ public AutoRedactScenario(Bugsnag bugsnag) { public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.addToTab("user", "password", "hunter2"); report.addToTab("custom", "password", "hunter2"); report.addToTab("custom", "foo", "hunter2"); diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/LogbackMetadataScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/LogbackMetadataScenario.java index c341ac66..4f19a002 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/LogbackMetadataScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/LogbackMetadataScenario.java @@ -23,7 +23,7 @@ public LogbackMetadataScenario(Bugsnag bugsnag) { public void run() { LOGGER.warn(new BugsnagMarker(new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.addToTab("user", "foo", "hunter2"); report.addToTab("custom", "foo", "hunter2"); report.addToTab("custom", "bar", "hunter2"); diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualContextScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualContextScenario.java index 4b26c466..b25b8425 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualContextScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualContextScenario.java @@ -17,7 +17,7 @@ public ManualContextScenario(Bugsnag bugsnag) { public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.setContext("FooContext"); return true; } diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualRedactScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualRedactScenario.java index 40584019..b518d3dd 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualRedactScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ManualRedactScenario.java @@ -20,7 +20,7 @@ public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.addToTab("user", "foo", "hunter2"); report.addToTab("custom", "foo", "hunter2"); report.addToTab("custom", "bar", "hunter2"); diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/MetadataScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/MetadataScenario.java index 81ea6936..afe44e3e 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/MetadataScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/MetadataScenario.java @@ -17,7 +17,7 @@ public MetadataScenario(Bugsnag bugsnag) { public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.addToTab("Custom", "foo", "Hello World!"); return true; } diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ThreadMetadataScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ThreadMetadataScenario.java index 12700edf..81252d8c 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ThreadMetadataScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/ThreadMetadataScenario.java @@ -18,7 +18,7 @@ public void run() { // Global callback metadata has lowest precedence bugsnag.addCallback(new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.addToTab("Custom", "test", "Global value"); report.addToTab("Custom", "foo", "Global value to be overwritten"); return true; @@ -48,7 +48,7 @@ public void run() { // Report-specific metadata should merge with global + thread metadata and overwrite when duplicate key bugsnag.notify(generateException(), new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.addToTab("Custom", "bar", "Hello World!"); return true; } diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UnhandledThreadMetadataScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UnhandledThreadMetadataScenario.java index 43980ebc..f4b9afe4 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UnhandledThreadMetadataScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UnhandledThreadMetadataScenario.java @@ -18,7 +18,7 @@ public void run() { // Global callback metadata has lowest precedence bugsnag.addCallback(new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.addToTab("Custom", "test", "Global value"); report.addToTab("Custom", "foo", "Global value to be overwritten"); return true; diff --git a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UserCallbackScenario.java b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UserCallbackScenario.java index b4de2fd9..61ad3ce7 100644 --- a/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UserCallbackScenario.java +++ b/features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunner/scenarios/UserCallbackScenario.java @@ -17,7 +17,7 @@ public UserCallbackScenario(Bugsnag bugsnag) { public void run() { bugsnag.notify(generateException(), new Callback() { @Override - public Boolean onError(Report report) { + public boolean onError(Report report) { report.setUser("Agent Pink", "bob@example.com", "Zebedee"); return true; }