|
46 | 46 | import java.util.concurrent.ConcurrentHashMap; |
47 | 47 | import java.util.concurrent.CopyOnWriteArrayList; |
48 | 48 | import java.util.concurrent.CopyOnWriteArraySet; |
| 49 | +import java.util.concurrent.atomic.AtomicBoolean; |
49 | 50 | import javax.net.ssl.SSLSocketFactory; |
50 | 51 | import org.jetbrains.annotations.ApiStatus; |
51 | 52 | import org.jetbrains.annotations.NotNull; |
@@ -318,6 +319,12 @@ public class SentryOptions { |
318 | 319 | /** Sentry Executor Service that sends cached events and envelopes on App. start. */ |
319 | 320 | private @NotNull ISentryExecutorService executorService = NoOpSentryExecutorService.getInstance(); |
320 | 321 |
|
| 322 | + /** |
| 323 | + * Whether SpotlightIntegration has already been loaded via reflection. This prevents re-adding it |
| 324 | + * if the user removed it in their configuration callback and activate() is called again. |
| 325 | + */ |
| 326 | + private final @NotNull AtomicBoolean spotlightIntegrationLoaded = new AtomicBoolean(false); |
| 327 | + |
321 | 328 | /** connection timeout in milliseconds. */ |
322 | 329 | private int connectionTimeoutMillis = 30_000; |
323 | 330 |
|
@@ -657,21 +664,15 @@ public void activate() { |
657 | 664 | } |
658 | 665 |
|
659 | 666 | // SpotlightIntegration is loaded via reflection to allow the sentry-spotlight module |
660 | | - // to be excluded from release builds, preventing insecure HTTP URLs from appearing in APKs |
661 | | - try { |
662 | | - final Class<?> clazz = Class.forName("io.sentry.spotlight.SpotlightIntegration"); |
663 | | - boolean alreadyRegistered = false; |
664 | | - for (final Integration integration : integrations) { |
665 | | - if (clazz.isInstance(integration)) { |
666 | | - alreadyRegistered = true; |
667 | | - break; |
668 | | - } |
669 | | - } |
670 | | - if (!alreadyRegistered) { |
| 667 | + // to be excluded from release builds, preventing insecure HTTP URLs from appearing in APKs. |
| 668 | + // Only attempt once to avoid re-adding after user removal in their configuration callback. |
| 669 | + if (spotlightIntegrationLoaded.compareAndSet(false, true)) { |
| 670 | + try { |
| 671 | + final Class<?> clazz = Class.forName("io.sentry.spotlight.SpotlightIntegration"); |
671 | 672 | integrations.add((Integration) clazz.getConstructor().newInstance()); |
| 673 | + } catch (Throwable ignored) { |
| 674 | + // SpotlightIntegration not available |
672 | 675 | } |
673 | | - } catch (Throwable ignored) { |
674 | | - // SpotlightIntegration not available |
675 | 676 | } |
676 | 677 | } |
677 | 678 |
|
|
0 commit comments