From 7aaf0cb3f1428bfd78b4a399b2ef235eee40f3c0 Mon Sep 17 00:00:00 2001 From: Gijs Weterings Date: Thu, 3 Apr 2025 08:01:59 -0700 Subject: [PATCH] Fix Nullsafe FIXMES for MountingManager.java and mark nullsafe (#50362) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50362 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 MountingManager.java nullsafe Reviewed By: cortinico Differential Revision: D71979607 fbshipit-source-id: 0a41e3a6405500c29ec4710ea3ed57e6705f1b4a --- .../fabric/mounting/MountingManager.java | 51 +++++++++---------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java index 586f9754f40..c31a91e33ef 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java @@ -12,10 +12,11 @@ import static com.facebook.infer.annotation.ThreadConfined.UI; import android.view.View; import androidx.annotation.AnyThread; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.UiThread; import com.facebook.common.logging.FLog; +import com.facebook.infer.annotation.Assertions; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.infer.annotation.ThreadConfined; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactSoftExceptionLogger; @@ -45,11 +46,11 @@ import java.util.concurrent.CopyOnWriteArrayList; * Class responsible for actually dispatching view updates enqueued via {@link * FabricUIManager#scheduleMountItem} on the UI thread. */ +@Nullsafe(Nullsafe.Mode.LOCAL) public class MountingManager { public static final String TAG = MountingManager.class.getSimpleName(); private static final int MAX_STOPPED_SURFACE_IDS_LENGTH = 15; - @NonNull private final ConcurrentHashMap mSurfaceIdToManager = new ConcurrentHashMap<>(); // any thread @@ -58,10 +59,10 @@ public class MountingManager { @Nullable private SurfaceMountingManager mMostRecentSurfaceMountingManager; @Nullable private SurfaceMountingManager mLastQueriedSurfaceMountingManager; - @NonNull private final JSResponderHandler mJSResponderHandler = new JSResponderHandler(); - @NonNull private final ViewManagerRegistry mViewManagerRegistry; - @NonNull private final MountItemExecutor mMountItemExecutor; - @NonNull private final RootViewManager mRootViewManager = new RootViewManager(); + private final JSResponderHandler mJSResponderHandler = new JSResponderHandler(); + private final ViewManagerRegistry mViewManagerRegistry; + private final MountItemExecutor mMountItemExecutor; + private final RootViewManager mRootViewManager = new RootViewManager(); public interface MountItemExecutor { @UiThread @@ -70,8 +71,7 @@ public class MountingManager { } public MountingManager( - @NonNull ViewManagerRegistry viewManagerRegistry, - @NonNull MountItemExecutor mountItemExecutor) { + ViewManagerRegistry viewManagerRegistry, MountItemExecutor mountItemExecutor) { mViewManagerRegistry = viewManagerRegistry; mMountItemExecutor = mountItemExecutor; } @@ -116,7 +116,7 @@ public class MountingManager { @AnyThread public void attachRootView( - final int surfaceId, @NonNull final View rootView, ThemedReactContext themedReactContext) { + final int surfaceId, final View rootView, ThemedReactContext themedReactContext) { SurfaceMountingManager surfaceMountingManager = getSurfaceManagerEnforced(surfaceId, "attachView"); @@ -136,10 +136,9 @@ public class MountingManager { // Maximum number of stopped surfaces to keep track of while (mStoppedSurfaceIds.size() >= MAX_STOPPED_SURFACE_IDS_LENGTH) { Integer staleStoppedId = mStoppedSurfaceIds.get(0); - // NULLSAFE_FIXME[Nullable Dereference] + Assertions.assertNotNull(staleStoppedId); mSurfaceIdToManager.remove(staleStoppedId.intValue()); mStoppedSurfaceIds.remove(staleStoppedId); - // NULLSAFE_FIXME[Nullable Dereference] FLog.d(TAG, "Removing stale SurfaceMountingManager: [%d]", staleStoppedId.intValue()); } mStoppedSurfaceIds.add(surfaceId); @@ -177,7 +176,6 @@ public class MountingManager { return surfaceMountingManager; } - @NonNull public SurfaceMountingManager getSurfaceManagerEnforced(int surfaceId, String context) { SurfaceMountingManager surfaceMountingManager = getSurfaceManager(surfaceId); @@ -252,7 +250,6 @@ public class MountingManager { return null; } - @NonNull @AnyThread public SurfaceMountingManager getSurfaceManagerForViewEnforced(int reactTag) { SurfaceMountingManager surfaceMountingManager = getSurfaceManagerForView(reactTag); @@ -278,7 +275,7 @@ public class MountingManager { } public void receiveCommand( - int surfaceId, int reactTag, @NonNull String commandId, @Nullable ReadableArray commandArgs) { + int surfaceId, int reactTag, String commandId, @Nullable ReadableArray commandArgs) { UiThreadUtil.assertOnUiThread(); getSurfaceManagerEnforced(surfaceId, "receiveCommand:string") .receiveCommand(reactTag, commandId, commandArgs); @@ -359,15 +356,15 @@ public class MountingManager { */ @AnyThread public long measure( - @NonNull ReactContext context, - @NonNull String componentName, - @NonNull ReadableMap localData, - @NonNull ReadableMap props, - @NonNull ReadableMap state, + ReactContext context, + String componentName, + ReadableMap localData, + ReadableMap props, + ReadableMap state, float width, - @NonNull YogaMeasureMode widthMode, + YogaMeasureMode widthMode, float height, - @NonNull YogaMeasureMode heightMode, + YogaMeasureMode heightMode, @Nullable float[] attachmentsPositions) { return mViewManagerRegistry @@ -402,15 +399,15 @@ public class MountingManager { */ @AnyThread public long measureMapBuffer( - @NonNull ReactContext context, - @NonNull String componentName, - @NonNull MapBuffer localData, - @NonNull MapBuffer props, + ReactContext context, + String componentName, + MapBuffer localData, + MapBuffer props, @Nullable MapBuffer state, float width, - @NonNull YogaMeasureMode widthMode, + YogaMeasureMode widthMode, float height, - @NonNull YogaMeasureMode heightMode, + YogaMeasureMode heightMode, @Nullable float[] attachmentsPositions) { return mViewManagerRegistry