From afdc8253df19f717e5c1a11b798eb3906a6b2f39 Mon Sep 17 00:00:00 2001 From: markushi Date: Mon, 26 May 2025 16:27:05 +0200 Subject: [PATCH 1/3] Fix GestureDetectorCompat crashes if initialized from background thread --- .../core/internal/gestures/SentryWindowCallback.java | 4 +++- sentry/src/main/java/io/sentry/Sentry.java | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryWindowCallback.java b/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryWindowCallback.java index 473a59b5b0..edb9c9f9da 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryWindowCallback.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryWindowCallback.java @@ -1,6 +1,8 @@ package io.sentry.android.core.internal.gestures; import android.content.Context; +import android.os.Handler; +import android.os.Looper; import android.view.MotionEvent; import android.view.Window; import androidx.core.view.GestureDetectorCompat; @@ -27,7 +29,7 @@ public SentryWindowCallback( final @Nullable SentryOptions options) { this( delegate, - new GestureDetectorCompat(context, gestureListener), + new GestureDetectorCompat(context, gestureListener, new Handler(Looper.getMainLooper())), gestureListener, options, new MotionEventObtainer() {}); diff --git a/sentry/src/main/java/io/sentry/Sentry.java b/sentry/src/main/java/io/sentry/Sentry.java index 5345178f3e..aa6d71e447 100644 --- a/sentry/src/main/java/io/sentry/Sentry.java +++ b/sentry/src/main/java/io/sentry/Sentry.java @@ -345,7 +345,16 @@ private static void init(final @NotNull SentryOptions options, final boolean glo // and Scopes was still NoOp. // Registering integrations here make sure that Scopes is already created. for (final Integration integration : options.getIntegrations()) { - integration.register(ScopesAdapter.getInstance(), options); + try { + integration.register(ScopesAdapter.getInstance(), options); + } catch (Throwable t) { + options + .getLogger() + .log( + SentryLevel.WARNING, + "Failed to register the integration " + integration.getClass().getName(), + t); + } } notifyOptionsObservers(options); From f43438c94054ea3e212b8094f9416b1200cacca4 Mon Sep 17 00:00:00 2001 From: markushi Date: Mon, 26 May 2025 16:36:52 +0200 Subject: [PATCH 2/3] Add tests --- sentry/src/test/java/io/sentry/SentryTest.kt | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sentry/src/test/java/io/sentry/SentryTest.kt b/sentry/src/test/java/io/sentry/SentryTest.kt index 9384d17167..311afce803 100644 --- a/sentry/src/test/java/io/sentry/SentryTest.kt +++ b/sentry/src/test/java/io/sentry/SentryTest.kt @@ -125,6 +125,27 @@ class SentryTest { verify(integration2).close() } + @Test + fun `if a single integration crashes, the SDK and other integrations are still initialized`() { + val goodIntegrationInitialized = AtomicBoolean(false) + val goodIntegration = Integration { scopes, options -> + // no-op + goodIntegrationInitialized.set(true) + } + + val badIntegration = Integration { scopes, options -> throw IllegalStateException("bad integration") } + + Sentry.init { + it.dsn = dsn + it.integrations.clear() + it.integrations.add(badIntegration) + it.integrations.add(goodIntegration) + } + + assertTrue(Sentry.isEnabled()) + assertTrue(goodIntegrationInitialized.get()) + } + interface CloseableIntegration : Integration, Closeable @Test From 37f3d57f5811c1523476dd76cac297f9affd555c Mon Sep 17 00:00:00 2001 From: markushi Date: Mon, 26 May 2025 16:39:06 +0200 Subject: [PATCH 3/3] Update Changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f20d0a8c8c..4f617f8e8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Features + +- Fix SDK init crash if initialized from background thread while an activiy is resumed ([#4449](https://github.com/getsentry/sentry-java/pull/4449)) + ## 8.13.0 ### Features pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy