Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,41 @@ class RNSentryStartTest {
assertEquals("android", result?.getTag("event.origin"))
assertEquals("java", result?.getTag("event.environment"))
}

@Test
fun `when enableNativeCrashHandling is false, native crash integrations are removed without ConcurrentModificationException`() {
val rnOptions = JavaOnlyMap.of("enableNativeCrashHandling", false)
val options = SentryAndroidOptions()

// This should not throw ConcurrentModificationException
RNSentryStart.getSentryAndroidOptions(options, rnOptions, logger)

// Verify integrations were removed
val integrations = options.getIntegrations()
assertFalse(
"UncaughtExceptionHandlerIntegration should be removed",
integrations.any { it is io.sentry.UncaughtExceptionHandlerIntegration },
)
assertFalse(
"AnrIntegration should be removed",
integrations.any { it is io.sentry.android.core.AnrIntegration },
)
assertFalse(
"NdkIntegration should be removed",
integrations.any { it is io.sentry.android.core.NdkIntegration },
)
}

@Test
fun `when enableNativeCrashHandling is true, native crash integrations are kept`() {
val rnOptions = JavaOnlyMap.of("enableNativeCrashHandling", true)
val options = SentryAndroidOptions()

RNSentryStart.getSentryAndroidOptions(options, rnOptions, logger)

// When enabled, the default integrations should still be present
// Note: This test verifies that we don't remove integrations when the flag is true
val integrations = options.getIntegrations()
assertNotNull("Integrations list should not be null", integrations)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.common.JavascriptException;
import io.sentry.ILogger;
import io.sentry.Integration;
import io.sentry.ProfileLifecycle;
import io.sentry.Sentry;
import io.sentry.SentryEvent;
Expand All @@ -25,7 +24,6 @@
import io.sentry.react.replay.RNSentryReplayUnmask;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -183,14 +181,13 @@ static void getSentryAndroidOptions(

if (rnOptions.hasKey("enableNativeCrashHandling")
&& !rnOptions.getBoolean("enableNativeCrashHandling")) {
final List<Integration> integrations = options.getIntegrations();
for (final Integration integration : integrations) {
if (integration instanceof UncaughtExceptionHandlerIntegration
|| integration instanceof AnrIntegration
|| integration instanceof NdkIntegration) {
integrations.remove(integration);
}
}
options
.getIntegrations()
.removeIf(
integration ->
integration instanceof UncaughtExceptionHandlerIntegration
|| integration instanceof AnrIntegration
|| integration instanceof NdkIntegration);
}
logger.log(
SentryLevel.INFO, String.format("Native Integrations '%s'", options.getIntegrations()));
Expand Down
Loading