Skip to content

Commit ed126ab

Browse files
antonisclaude
andcommitted
fix(android): Fix crash when spotlight is enabled without defaultSidecarUrl
The code attempted to read defaultSidecarUrl without checking if the key exists in the options map. This caused a NoSuchKeyException crash during startup when spotlight was set to true in sentry.options.json without providing defaultSidecarUrl. Added key existence check to match iOS implementation behavior and prevent the crash while maintaining backward compatibility. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 35aae51 commit ed126ab

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

packages/core/RNSentryAndroidTester/app/src/test/java/io/sentry/react/RNSentryStartTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ class RNSentryStartTest {
5858
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
5959
}
6060

61+
@Test
62+
fun `when the spotlight option is enabled without defaultSidecarUrl, the spotlight is enabled and does not crash`() {
63+
val options = JavaOnlyMap.of("spotlight", true)
64+
val actualOptions = SentryAndroidOptions()
65+
RNSentryStart.getSentryAndroidOptions(actualOptions, options, logger)
66+
assert(actualOptions.isEnableSpotlight)
67+
assertNull(actualOptions.spotlightConnectionUrl)
68+
}
69+
6170
@Test
6271
fun `when the spotlight option is disabled, the spotlight SentryAndroidOption is set to false`() {
6372
val options = JavaOnlyMap.of("spotlight", false)

packages/core/android/src/main/java/io/sentry/react/RNSentryStart.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ static void getSentryAndroidOptions(
148148
if (rnOptions.hasKey("spotlight")) {
149149
if (rnOptions.getType("spotlight") == ReadableType.Boolean) {
150150
options.setEnableSpotlight(rnOptions.getBoolean("spotlight"));
151-
options.setSpotlightConnectionUrl(rnOptions.getString("defaultSidecarUrl"));
151+
if (rnOptions.hasKey("defaultSidecarUrl")) {
152+
options.setSpotlightConnectionUrl(rnOptions.getString("defaultSidecarUrl"));
153+
}
152154
} else if (rnOptions.getType("spotlight") == ReadableType.String) {
153155
options.setEnableSpotlight(true);
154156
options.setSpotlightConnectionUrl(rnOptions.getString("spotlight"));

0 commit comments

Comments
 (0)