|
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 |
|
@@ -655,6 +662,18 @@ public void activate() { |
655 | 662 | executorService = new SentryExecutorService(this); |
656 | 663 | executorService.prewarm(); |
657 | 664 | } |
| 665 | + |
| 666 | + // SpotlightIntegration is loaded via reflection to allow the sentry-spotlight module |
| 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"); |
| 672 | + integrations.add((Integration) clazz.getConstructor().newInstance()); |
| 673 | + } catch (Throwable ignored) { |
| 674 | + // SpotlightIntegration not available |
| 675 | + } |
| 676 | + } |
658 | 677 | } |
659 | 678 |
|
660 | 679 | /** |
@@ -3340,16 +3359,6 @@ private SentryOptions(final boolean empty) { |
3340 | 3359 |
|
3341 | 3360 | integrations.add(new ShutdownHookIntegration()); |
3342 | 3361 |
|
3343 | | - // SpotlightIntegration is loaded via reflection to allow the sentry-spotlight module |
3344 | | - // to be excluded from release builds, preventing insecure HTTP URLs from appearing in APKs |
3345 | | - try { |
3346 | | - final Class<?> clazz = Class.forName("io.sentry.spotlight.SpotlightIntegration"); |
3347 | | - final Integration spotlight = (Integration) clazz.getConstructor().newInstance(); |
3348 | | - integrations.add(spotlight); |
3349 | | - } catch (Throwable ignored) { |
3350 | | - // SpotlightIntegration not available |
3351 | | - } |
3352 | | - |
3353 | 3362 | eventProcessors.add(new MainEventProcessor(this)); |
3354 | 3363 | eventProcessors.add(new DuplicateEventDetectionEventProcessor(this)); |
3355 | 3364 |
|
|
0 commit comments