From 2cc3ba1f19739baa866bd11c2c4e80d2100219d0 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 14 May 2024 00:08:56 -0700 Subject: [PATCH] Mark IntBufferBatchMountItem as nullsafe (#44540) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44540 Noticed when running `arc nn` > Advice xplat/js/react-native-github/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java:39 > [Class has 0 issues and can be marked Nullsafe] Congrats! `IntBufferBatchMountItem` is free of nullability issues. Mark it `Nullsafe(Nullsafe.Mode.LOCAL)` to prevent regressions. Changelog: [Internal] Reviewed By: rshest Differential Revision: D57249958 fbshipit-source-id: d38559a3fafae0ad778c19dd85c5da610a650d7c --- .../com/facebook/react/fabric/FabricUIManager.java | 7 +++++-- .../mountitems/IntBufferBatchMountItem.java | 13 +++++++------ .../fabric/mounting/mountitems/MountItemFactory.kt | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index a6fd6c05875..d2c4732b854 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -776,9 +776,12 @@ public class FabricUIManager @AnyThread @ThreadConfined(ANY) private MountItem createIntBufferBatchMountItem( - int rootTag, int[] intBuffer, Object[] objBuffer, int commitNumber) { + int rootTag, @Nullable int[] intBuffer, @Nullable Object[] objBuffer, int commitNumber) { return MountItemFactory.createIntBufferBatchMountItem( - rootTag, intBuffer, objBuffer, commitNumber); + rootTag, + intBuffer == null ? new int[0] : intBuffer, + objBuffer == null ? new Object[0] : objBuffer, + commitNumber); } /** diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java index 03cdf0d6dbf..45621a90dad 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java @@ -11,8 +11,8 @@ import static com.facebook.react.fabric.FabricUIManager.ENABLE_FABRIC_LOGS; import static com.facebook.react.fabric.FabricUIManager.IS_DEVELOPMENT_ENVIRONMENT; import static com.facebook.react.fabric.mounting.mountitems.FabricNameComponentMapping.getFabricComponentName; -import androidx.annotation.NonNull; import com.facebook.common.logging.FLog; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.bridge.ReactMarker; import com.facebook.react.bridge.ReactMarkerConstants; @@ -35,6 +35,7 @@ import com.facebook.systrace.Systrace; * allocations in C++ and JNI round-trips. */ @DoNotStrip +@Nullsafe(Nullsafe.Mode.LOCAL) final class IntBufferBatchMountItem implements BatchMountItem { static final String TAG = IntBufferBatchMountItem.class.getSimpleName(); @@ -55,8 +56,8 @@ final class IntBufferBatchMountItem implements BatchMountItem { private final int mSurfaceId; private final int mCommitNumber; - private final @NonNull int[] mIntBuffer; - private final @NonNull Object[] mObjBuffer; + private final int[] mIntBuffer; + private final Object[] mObjBuffer; private final int mIntBufferLen; private final int mObjBufferLen; @@ -68,8 +69,8 @@ final class IntBufferBatchMountItem implements BatchMountItem { mIntBuffer = intBuf; mObjBuffer = objBuf; - mIntBufferLen = mIntBuffer != null ? mIntBuffer.length : 0; - mObjBufferLen = mObjBuffer != null ? mObjBuffer.length : 0; + mIntBufferLen = mIntBuffer.length; + mObjBufferLen = mObjBuffer.length; } private void beginMarkers(String reason) { @@ -91,7 +92,7 @@ final class IntBufferBatchMountItem implements BatchMountItem { } @Override - public void execute(@NonNull MountingManager mountingManager) { + public void execute(MountingManager mountingManager) { SurfaceMountingManager surfaceMountingManager = mountingManager.getSurfaceManager(mSurfaceId); if (surfaceMountingManager == null) { FLog.e( diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.kt index 15ab152d1ee..80b72746444 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.kt @@ -63,8 +63,8 @@ public object MountItemFactory { @JvmStatic public fun createIntBufferBatchMountItem( surfaceId: Int, - intBuf: IntArray?, - objBuf: Array?, + intBuf: IntArray, + objBuf: Array, commitNumber: Int ): MountItem = IntBufferBatchMountItem(surfaceId, intBuf, objBuf, commitNumber) }