Skip to content

Commit 54ef748

Browse files
romtsnclaude
andcommitted
fix: Prevent SpotlightIntegration from being re-added after user removal
Use AtomicBoolean to ensure activate() only loads SpotlightIntegration once, so users can remove it in their configuration callback without it being re-added by the second activate() call from Sentry.init(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e39c7c2 commit 54ef748

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

sentry/src/main/java/io/sentry/SentryOptions.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.concurrent.ConcurrentHashMap;
4747
import java.util.concurrent.CopyOnWriteArrayList;
4848
import java.util.concurrent.CopyOnWriteArraySet;
49+
import java.util.concurrent.atomic.AtomicBoolean;
4950
import javax.net.ssl.SSLSocketFactory;
5051
import org.jetbrains.annotations.ApiStatus;
5152
import org.jetbrains.annotations.NotNull;
@@ -318,6 +319,12 @@ public class SentryOptions {
318319
/** Sentry Executor Service that sends cached events and envelopes on App. start. */
319320
private @NotNull ISentryExecutorService executorService = NoOpSentryExecutorService.getInstance();
320321

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+
321328
/** connection timeout in milliseconds. */
322329
private int connectionTimeoutMillis = 30_000;
323330

@@ -657,21 +664,15 @@ public void activate() {
657664
}
658665

659666
// 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");
671672
integrations.add((Integration) clazz.getConstructor().newInstance());
673+
} catch (Throwable ignored) {
674+
// SpotlightIntegration not available
672675
}
673-
} catch (Throwable ignored) {
674-
// SpotlightIntegration not available
675676
}
676677
}
677678

0 commit comments

Comments
 (0)