From e1c72cf242bdbfdd84efe68bbc37920fc05b5acf Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Thu, 11 Nov 2021 13:20:55 +0100 Subject: [PATCH] Fix: Do not crash when event processors throw a lower level Throwable class (#1800) --- CHANGELOG.md | 1 + .../core/PerformanceAndroidEventProcessor.java | 17 +++++++++++++++++ .../src/main/java/io/sentry/SentryClient.java | 4 ++-- .../src/test/java/io/sentry/SentryClientTest.kt | 3 +-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba47c8fedd..6246456017 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased * Feat: Add `graphql-java` instrumentation (#1777) +* Fix: Do not crash when event processors throw a lower level Throwable class (#1800) * Fix: ActivityFramesTracker does not throw if Activity has no observers (#1799) ## 5.3.0 diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java b/sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java index 5b9061b8fa..543d10746a 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java @@ -5,6 +5,7 @@ import static io.sentry.android.core.ActivityLifecycleIntegration.UI_LOAD_OP; import io.sentry.EventProcessor; +import io.sentry.SentryEvent; import io.sentry.SpanContext; import io.sentry.protocol.MeasurementValue; import io.sentry.protocol.SentryId; @@ -32,6 +33,22 @@ final class PerformanceAndroidEventProcessor implements EventProcessor { Objects.requireNonNull(activityFramesTracker, "ActivityFramesTracker is required"); } + /** + * Returns the event itself + * + * @param event the SentryEvent the SentryEvent + * @param hint the Hint the Hint + * @return returns the event itself + */ + @Override + @Nullable + public SentryEvent process(@NotNull SentryEvent event, @Nullable Object hint) { + // that's only necessary because on newer versions of Unity, if not overriding this method, it's + // throwing 'java.lang.AbstractMethodError: abstract method' and the reason is probably + // compilation mismatch. + return event; + } + @Override public synchronized @NotNull SentryTransaction process( @NotNull SentryTransaction transaction, @Nullable Object hint) { diff --git a/sentry/src/main/java/io/sentry/SentryClient.java b/sentry/src/main/java/io/sentry/SentryClient.java index aba4b105ba..c5a2fa43d3 100644 --- a/sentry/src/main/java/io/sentry/SentryClient.java +++ b/sentry/src/main/java/io/sentry/SentryClient.java @@ -204,7 +204,7 @@ private SentryEvent processEvent( for (final EventProcessor processor : eventProcessors) { try { event = processor.process(event, hint); - } catch (Exception e) { + } catch (Throwable e) { options .getLogger() .log( @@ -235,7 +235,7 @@ private SentryTransaction processTransaction( for (final EventProcessor processor : eventProcessors) { try { transaction = processor.process(transaction, hint); - } catch (Exception e) { + } catch (Throwable e) { options .getLogger() .log( diff --git a/sentry/src/test/java/io/sentry/SentryClientTest.kt b/sentry/src/test/java/io/sentry/SentryClientTest.kt index d8bd219db0..c7975f1b90 100644 --- a/sentry/src/test/java/io/sentry/SentryClientTest.kt +++ b/sentry/src/test/java/io/sentry/SentryClientTest.kt @@ -32,7 +32,6 @@ import java.io.IOException import java.io.InputStreamReader import java.lang.IllegalArgumentException import java.lang.IllegalStateException -import java.lang.RuntimeException import java.nio.charset.Charset import java.util.Arrays import java.util.UUID @@ -1299,7 +1298,7 @@ class SentryClientTest { private fun eventProcessorThrows(): EventProcessor { return object : EventProcessor { override fun process(event: SentryEvent, hint: Any?): SentryEvent? { - throw RuntimeException() + throw Throwable() } } }