From 4e6eba7a2dedaa855af0bff5df3bec73a95f0fc4 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Fri, 2 Feb 2024 10:22:02 -0800 Subject: [PATCH] Mark classes of package fabric as @Nullsafe (#42725) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/42725 All these classes are NullSafe, let's mark them as NullSafe(Local) to ensure lint detect errors in the future changelog: [internal] internal Reviewed By: NickGerleman Differential Revision: D53200097 fbshipit-source-id: dad54f5bf03967b5d4126757ab0d5424534af888 --- .../src/main/java/com/facebook/react/fabric/BindingImpl.java | 2 ++ .../main/java/com/facebook/react/fabric/ComponentFactory.java | 2 ++ .../java/com/facebook/react/fabric/CoreComponentsRegistry.java | 2 ++ .../java/com/facebook/react/fabric/DevToolsReactPerfLogger.java | 2 ++ .../main/java/com/facebook/react/fabric/FabricComponents.java | 2 ++ .../src/main/java/com/facebook/react/fabric/FabricSoLoader.java | 2 ++ .../java/com/facebook/react/fabric/GuardedFrameCallback.java | 2 ++ .../main/java/com/facebook/react/fabric/StateWrapperImpl.java | 2 ++ .../java/com/facebook/react/fabric/SurfaceHandlerBinding.java | 2 ++ .../java/com/facebook/react/fabric/events/EventBeatManager.java | 2 ++ .../com/facebook/react/fabric/events/FabricEventEmitter.java | 2 ++ .../react/fabric/mounting/LayoutMetricsConversions.java | 2 ++ .../fabric/mounting/mountitems/DispatchCommandMountItem.java | 2 ++ .../fabric/mounting/mountitems/DispatchIntCommandMountItem.java | 2 ++ .../mounting/mountitems/DispatchStringCommandMountItem.java | 2 ++ .../fabric/mounting/mountitems/FabricNameComponentMapping.java | 2 ++ .../react/fabric/mounting/mountitems/MountItemFactory.java | 2 ++ .../fabric/mounting/mountitems/PreAllocateViewMountItem.java | 2 ++ .../fabric/mounting/mountitems/SendAccessibilityEvent.java | 2 ++ .../mounting/mountitems/SendAccessibilityEventMountItem.java | 2 ++ 20 files changed, 40 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/BindingImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/BindingImpl.java index b3c203f5aab5e0..324a530abed008 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/BindingImpl.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/BindingImpl.java @@ -9,6 +9,7 @@ import android.annotation.SuppressLint; import androidx.annotation.NonNull; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.jni.HybridData; import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.bridge.NativeMap; @@ -20,6 +21,7 @@ import com.facebook.react.fabric.events.EventEmitterWrapper; import com.facebook.react.uimanager.PixelUtil; +@Nullsafe(Nullsafe.Mode.LOCAL) @DoNotStrip @SuppressLint("MissingNativeLoadLibrary") public class BindingImpl implements Binding { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentFactory.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentFactory.java index 1c9974ef76592a..f0be02df1e7831 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentFactory.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentFactory.java @@ -8,9 +8,11 @@ package com.facebook.react.fabric; import androidx.annotation.NonNull; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.jni.HybridData; import com.facebook.proguard.annotations.DoNotStrip; +@Nullsafe(Nullsafe.Mode.LOCAL) @DoNotStrip public class ComponentFactory { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/CoreComponentsRegistry.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/CoreComponentsRegistry.java index 797106872d6cda..7888ca2f191ee2 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/CoreComponentsRegistry.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/CoreComponentsRegistry.java @@ -7,9 +7,11 @@ package com.facebook.react.fabric; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.jni.HybridData; import com.facebook.proguard.annotations.DoNotStrip; +@Nullsafe(Nullsafe.Mode.LOCAL) @DoNotStrip public class CoreComponentsRegistry { static { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/DevToolsReactPerfLogger.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/DevToolsReactPerfLogger.java index 4288a457f8068a..45fe3ca1753aaa 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/DevToolsReactPerfLogger.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/DevToolsReactPerfLogger.java @@ -22,6 +22,7 @@ import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_UPDATE_UI_MAIN_THREAD_START; import androidx.annotation.Nullable; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.ReactMarker; import com.facebook.react.bridge.ReactMarkerConstants; import java.util.ArrayList; @@ -29,6 +30,7 @@ import java.util.List; import java.util.Map; +@Nullsafe(Nullsafe.Mode.LOCAL) public class DevToolsReactPerfLogger implements ReactMarker.FabricMarkerListener { private final Map mFabricCommitMarkers = new HashMap<>(); diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricComponents.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricComponents.java index bf6c6a2aaa36d8..cd4dc5f34e4656 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricComponents.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricComponents.java @@ -8,6 +8,7 @@ package com.facebook.react.fabric; import androidx.annotation.NonNull; +import com.facebook.infer.annotation.Nullsafe; import java.util.HashMap; import java.util.Map; @@ -17,6 +18,7 @@ *

TODO T97384889: remove this class when the component names are unified between JS - Android - * iOS - C++ */ +@Nullsafe(Nullsafe.Mode.LOCAL) public class FabricComponents { private static @NonNull final Map sComponentNames = new HashMap<>(); diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricSoLoader.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricSoLoader.java index 26526701c51ef4..e3a8da958beec6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricSoLoader.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricSoLoader.java @@ -9,11 +9,13 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.ReactMarker; import com.facebook.react.bridge.ReactMarkerConstants; import com.facebook.soloader.SoLoader; import com.facebook.systrace.Systrace; +@Nullsafe(Nullsafe.Mode.LOCAL) public class FabricSoLoader { private static volatile boolean sDidInit = false; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/GuardedFrameCallback.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/GuardedFrameCallback.java index 8e4bdfaa60e38a..e0bd43d219841d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/GuardedFrameCallback.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/GuardedFrameCallback.java @@ -9,9 +9,11 @@ import android.view.Choreographer; import androidx.annotation.NonNull; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.JSExceptionHandler; import com.facebook.react.bridge.ReactContext; +@Nullsafe(Nullsafe.Mode.LOCAL) public abstract class GuardedFrameCallback implements Choreographer.FrameCallback { @NonNull private final JSExceptionHandler mExceptionHandler; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/StateWrapperImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/StateWrapperImpl.java index c1e797f85d9cb8..66a2cc62d5071f 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/StateWrapperImpl.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/StateWrapperImpl.java @@ -11,6 +11,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.facebook.common.logging.FLog; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.jni.HybridData; import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.bridge.NativeMap; @@ -23,6 +24,7 @@ * This class holds reference to the C++ EventEmitter object. Instances of this class are created on * the Bindings.cpp, where the pointer to the C++ event emitter is set. */ +@Nullsafe(Nullsafe.Mode.LOCAL) @SuppressLint("MissingNativeLoadLibrary") @DoNotStrip public class StateWrapperImpl implements StateWrapper { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.java index 1d0a9bfa67486c..1dcb42123bf1b5 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/SurfaceHandlerBinding.java @@ -11,6 +11,7 @@ import static com.facebook.react.fabric.mounting.LayoutMetricsConversions.getMinSize; import androidx.annotation.IntDef; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.jni.HybridData; import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.bridge.NativeMap; @@ -18,6 +19,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +@Nullsafe(Nullsafe.Mode.LOCAL) public class SurfaceHandlerBinding implements SurfaceHandler { static { FabricSoLoader.staticInit(); diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/EventBeatManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/EventBeatManager.java index 4c4703d0ae7910..3de23f98a7945c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/EventBeatManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/EventBeatManager.java @@ -9,6 +9,7 @@ import android.annotation.SuppressLint; import androidx.annotation.NonNull; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.jni.HybridData; import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.bridge.ReactApplicationContext; @@ -18,6 +19,7 @@ /** * Class that acts as a proxy between the list of EventBeats registered in C++ and the Android side. */ +@Nullsafe(Nullsafe.Mode.LOCAL) @SuppressLint("MissingNativeLoadLibrary") public final class EventBeatManager implements BatchEventDispatchedListener { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/FabricEventEmitter.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/FabricEventEmitter.java index d5601632c0c134..f85937c886b643 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/FabricEventEmitter.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/events/FabricEventEmitter.java @@ -9,6 +9,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableMap; import com.facebook.react.fabric.FabricUIManager; @@ -18,6 +19,7 @@ import com.facebook.react.uimanager.events.TouchEvent; import com.facebook.systrace.Systrace; +@Nullsafe(Nullsafe.Mode.LOCAL) public class FabricEventEmitter implements RCTModernEventEmitter { @NonNull private final FabricUIManager mUIManager; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/LayoutMetricsConversions.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/LayoutMetricsConversions.java index 249e3b84f7c251..f875d34e8bf0db 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/LayoutMetricsConversions.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/LayoutMetricsConversions.java @@ -10,9 +10,11 @@ import static android.view.View.MeasureSpec.EXACTLY; import android.view.View; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.uimanager.PixelUtil; import com.facebook.yoga.YogaMeasureMode; +@Nullsafe(Nullsafe.Mode.LOCAL) public interface LayoutMetricsConversions { static float getMinSize(int viewMeasureSpec) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem.java index 43b6d7120b995d..feedcc4bc2f4cb 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem.java @@ -8,12 +8,14 @@ package com.facebook.react.fabric.mounting.mountitems; import androidx.annotation.UiThread; +import com.facebook.infer.annotation.Nullsafe; /** * This is a common interface for View Command operations. Once we delete the deprecated {@link * DispatchIntCommandMountItem}, we can delete this interface too. It provides a set of common * operations to simplify generic operations on all types of ViewCommands. */ +@Nullsafe(Nullsafe.Mode.LOCAL) public abstract class DispatchCommandMountItem implements MountItem { private int mNumRetries = 0; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.java index 89f69e1288853f..887ac2e1026b97 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.java @@ -9,9 +9,11 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.fabric.mounting.MountingManager; +@Nullsafe(Nullsafe.Mode.LOCAL) final class DispatchIntCommandMountItem extends DispatchCommandMountItem { private final int mSurfaceId; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.java index c86abde48e9fb3..4b68d18aef8e5c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.java @@ -9,9 +9,11 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.fabric.mounting.MountingManager; +@Nullsafe(Nullsafe.Mode.LOCAL) final class DispatchStringCommandMountItem extends DispatchCommandMountItem { private final int mSurfaceId; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/FabricNameComponentMapping.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/FabricNameComponentMapping.java index bd5e1488227c97..cfe711f94526a9 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/FabricNameComponentMapping.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/FabricNameComponentMapping.java @@ -8,6 +8,7 @@ package com.facebook.react.fabric.mounting.mountitems; import androidx.annotation.NonNull; +import com.facebook.infer.annotation.Nullsafe; import java.util.HashMap; import java.util.Map; @@ -17,6 +18,7 @@ *

TODO T97384889: remove this class when the component names are unified between JS - Android - * iOS - C++ */ +@Nullsafe(Nullsafe.Mode.LOCAL) class FabricNameComponentMapping { private static @NonNull final Map sComponentNames = new HashMap<>(); diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.java index b68adff51119f5..03f3da3909c7cf 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.java @@ -9,11 +9,13 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.fabric.events.EventEmitterWrapper; import com.facebook.react.uimanager.StateWrapper; /** Factory class that expose creation of {@link MountItem} */ +@Nullsafe(Nullsafe.Mode.LOCAL) public class MountItemFactory { /** @return a {@link DispatchCommandMountItem} for commands identified by an int */ diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.java index 8f4f6feab3c83e..ad56b510192f4e 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.java @@ -14,12 +14,14 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.facebook.common.logging.FLog; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.fabric.events.EventEmitterWrapper; import com.facebook.react.fabric.mounting.MountingManager; import com.facebook.react.fabric.mounting.SurfaceMountingManager; import com.facebook.react.uimanager.StateWrapper; /** {@link MountItem} that is used to pre-allocate views for JS components. */ +@Nullsafe(Nullsafe.Mode.LOCAL) final class PreAllocateViewMountItem implements MountItem { private final @NonNull String mComponent; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/SendAccessibilityEvent.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/SendAccessibilityEvent.java index 7acdc030099e75..37c85f9db6b762 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/SendAccessibilityEvent.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/SendAccessibilityEvent.java @@ -8,10 +8,12 @@ package com.facebook.react.fabric.mounting.mountitems; import androidx.annotation.NonNull; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.ReactSoftExceptionLogger; import com.facebook.react.bridge.RetryableMountingLayerException; import com.facebook.react.fabric.mounting.MountingManager; +@Nullsafe(Nullsafe.Mode.LOCAL) class SendAccessibilityEvent implements MountItem { private final String TAG = "Fabric.SendAccessibilityEvent"; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/SendAccessibilityEventMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/SendAccessibilityEventMountItem.java index 13e90ada6dd2cb..354d328a97c303 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/SendAccessibilityEventMountItem.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/SendAccessibilityEventMountItem.java @@ -8,10 +8,12 @@ package com.facebook.react.fabric.mounting.mountitems; import androidx.annotation.NonNull; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.ReactSoftExceptionLogger; import com.facebook.react.bridge.RetryableMountingLayerException; import com.facebook.react.fabric.mounting.MountingManager; +@Nullsafe(Nullsafe.Mode.LOCAL) final class SendAccessibilityEventMountItem implements MountItem { private final String TAG = "Fabric.SendAccessibilityEvent";