From 30da6ca84a704d38c03a62da43597ce769a8bf3a Mon Sep 17 00:00:00 2001 From: Gijs Weterings Date: Wed, 9 Apr 2025 09:07:30 -0700 Subject: [PATCH] fix nullsafe FIXMEs for JsonWriterHelper.java and mark nullsafe Summary: Gone trough all the FIXMEs added in the previous diff by the nullsafe tool, marked the class as nullsafe and ensured no remaining violations. Changelog: [Android][Fixed] Made JsonWriterHelper.java nullsafe Reviewed By: alanleedev Differential Revision: D72384060 fbshipit-source-id: ce41674cc5dbadcd70029396607ac046100e2be7 --- .../react/bridge/JsonWriterHelper.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/JsonWriterHelper.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/JsonWriterHelper.java index 472b8e9f2a9..1593a7f6365 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/JsonWriterHelper.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/JsonWriterHelper.java @@ -8,11 +8,14 @@ package com.facebook.react.bridge; import android.util.JsonWriter; +import com.facebook.infer.annotation.Assertions; +import com.facebook.infer.annotation.Nullsafe; import java.io.IOException; import java.util.List; import java.util.Map; /** Helper for generating JSON for lists and maps. */ +@Nullsafe(Nullsafe.Mode.LOCAL) public class JsonWriterHelper { public static void value(JsonWriter writer, Object value) throws IOException { if (value instanceof Map) { @@ -45,12 +48,14 @@ public class JsonWriterHelper { writer.value(value.asString()); break; case Map: - // NULLSAFE_FIXME[Parameter Not Nullable] - readableMapValue(writer, value.asMap()); + ReadableMap map = value.asMap(); + Assertions.assertNotNull(map); + readableMapValue(writer, map); break; case Array: - // NULLSAFE_FIXME[Parameter Not Nullable] - readableArrayValue(writer, value.asArray()); + ReadableArray array = value.asArray(); + Assertions.assertNotNull(array); + readableArrayValue(writer, array); break; default: throw new IllegalArgumentException("Unknown data type: " + value.getType()); @@ -78,12 +83,14 @@ public class JsonWriterHelper { writer.value(value.getString(key)); break; case Map: - // NULLSAFE_FIXME[Parameter Not Nullable] - readableMapValue(writer, value.getMap(key)); + ReadableMap map = value.getMap(key); + Assertions.assertNotNull(map); + readableMapValue(writer, map); break; case Array: - // NULLSAFE_FIXME[Parameter Not Nullable] - readableArrayValue(writer, value.getArray(key)); + ReadableArray array = value.getArray(key); + Assertions.assertNotNull(array); + readableArrayValue(writer, array); break; default: throw new IllegalArgumentException("Unknown data type: " + value.getType(key)); @@ -112,12 +119,14 @@ public class JsonWriterHelper { writer.value(value.getString(key)); break; case Map: - // NULLSAFE_FIXME[Parameter Not Nullable] - readableMapValue(writer, value.getMap(key)); + ReadableMap map = value.getMap(key); + Assertions.assertNotNull(map); + readableMapValue(writer, map); break; case Array: - // NULLSAFE_FIXME[Parameter Not Nullable] - readableArrayValue(writer, value.getArray(key)); + ReadableArray array = value.getArray(key); + Assertions.assertNotNull(array); + readableArrayValue(writer, array); break; default: throw new IllegalArgumentException("Unknown data type: " + value.getType(key));