Skip to content

Commit 22998d0

Browse files
antonisclaude
andauthored
fix(android): Handle boolean values in JSON options converter (#6130)
* fix(android): Handle boolean values in JSON options converter `RNSentryJsonConverter.convertToWritable()` did not handle `Boolean` values from `sentry.options.json`, silently dropping them. This caused all boolean options (e.g. `maskAllText`, `debug`, `attachScreenshot`) to fall back to defaults when using `RNSentrySDK.init()`. Fixes #6122 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: Add changelog entry for boolean options fix Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f88a7d1 commit 22998d0

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
- The existing `record` prop is unchanged BUT it is now deprecated in favor of `ready`.
1616
- Extract text content from children of touched components as a label fallback for touch breadcrumbs ([#6106](https://github.com/getsentry/sentry-react-native/pull/6106))
1717

18+
### Fixes
19+
20+
- Fix boolean options from `sentry.options.json` being ignored on Android when using `RNSentrySDK.init` ([#6130](https://github.com/getsentry/sentry-react-native/pull/6130))
21+
1822
### Dependencies
1923

2024
- Bump JavaScript SDK from v10.51.0 to v10.52.0 ([#6108](https://github.com/getsentry/sentry-react-native/pull/6108))

packages/core/RNSentryAndroidTester/app/src/androidTest/java/io/sentry/react/RNSentryJsonConverterTest.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class RNSentryJsonConverterTest {
2222
put("doubleKey", 12.3)
2323
put("intKey", 123)
2424
put("stringKey", "test")
25+
put("boolTrueKey", true)
26+
put("boolFalseKey", false)
2527
put("nullKey", JSONObject.NULL)
2628
}
2729

@@ -32,6 +34,8 @@ class RNSentryJsonConverterTest {
3234
assertEquals(12.3, result.getDouble("doubleKey"), 0.0)
3335
assertEquals(123, result.getInt("intKey"))
3436
assertEquals("test", result.getString("stringKey"))
37+
assertEquals(true, result.getBoolean("boolTrueKey"))
38+
assertEquals(false, result.getBoolean("boolFalseKey"))
3539
assertNull(result.getString("nullKey"))
3640
}
3741

@@ -62,6 +66,8 @@ class RNSentryJsonConverterTest {
6266
put(1)
6367
put(2.5)
6468
put("string")
69+
put(true)
70+
put(false)
6571
put(JSONObject.NULL)
6672
}
6773

@@ -70,7 +76,9 @@ class RNSentryJsonConverterTest {
7076
assertEquals(1, result.getInt(0))
7177
assertEquals(2.5, result.getDouble(1), 0.0)
7278
assertEquals("string", result.getString(2))
73-
assertNull(result.getString(3))
79+
assertEquals(true, result.getBoolean(3))
80+
assertEquals(false, result.getBoolean(4))
81+
assertNull(result.getString(5))
7482
}
7583

7684
@Test

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ static WritableMap convertToWritable(@NotNull JSONObject jsonObject) {
3131
while (iterator.hasNext()) {
3232
String key = iterator.next();
3333
Object value = jsonObject.get(key);
34-
if (value instanceof Float || value instanceof Double) {
34+
if (value instanceof Boolean) {
35+
writableMap.putBoolean(key, jsonObject.getBoolean(key));
36+
} else if (value instanceof Float || value instanceof Double) {
3537
writableMap.putDouble(key, jsonObject.getDouble(key));
3638
} else if (value instanceof Number) {
3739
writableMap.putInt(key, jsonObject.getInt(key));
@@ -57,7 +59,9 @@ static WritableArray convertToWritable(@NotNull JSONArray jsonArray) throws JSON
5759
WritableArray writableArray = new JavaOnlyArray();
5860
for (int i = 0; i < jsonArray.length(); i++) {
5961
Object value = jsonArray.get(i);
60-
if (value instanceof Float || value instanceof Double) {
62+
if (value instanceof Boolean) {
63+
writableArray.pushBoolean(jsonArray.getBoolean(i));
64+
} else if (value instanceof Float || value instanceof Double) {
6165
writableArray.pushDouble(jsonArray.getDouble(i));
6266
} else if (value instanceof Number) {
6367
writableArray.pushInt(jsonArray.getInt(i));

0 commit comments

Comments
 (0)