From 8aaccef2ee2d67756ce54f5819f0c3d8eab1fbf6 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 NativeModuleRegistry.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 NativeModuleRegistry.java nullsafe Reviewed By: javache Differential Revision: D72384075 fbshipit-source-id: bebc637a757c9f86d6260f9076010de9d7c80d4a --- .../facebook/react/bridge/NativeModuleRegistry.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModuleRegistry.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModuleRegistry.java index 0fb626da0f3..717fecc955b 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModuleRegistry.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModuleRegistry.java @@ -8,6 +8,7 @@ package com.facebook.react.bridge; import com.facebook.infer.annotation.Assertions; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.common.annotations.internal.LegacyArchitecture; import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel; import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger; @@ -20,6 +21,7 @@ import java.util.Map; /** A set of Java APIs to expose to a particular JavaScript instance. */ @LegacyArchitecture +@Nullsafe(Nullsafe.Mode.LOCAL) public class NativeModuleRegistry { private final ReactApplicationContext mReactApplicationContext; @@ -125,8 +127,12 @@ public class NativeModuleRegistry { } public boolean hasModule(Class moduleInterface) { - // NULLSAFE_FIXME[Nullable Dereference] - String name = moduleInterface.getAnnotation(ReactModule.class).name(); + ReactModule annotation = moduleInterface.getAnnotation(ReactModule.class); + if (annotation == null) { + throw new IllegalArgumentException( + "Could not find @ReactModule annotation in class " + moduleInterface.getName()); + } + String name = annotation.name(); return mModules.containsKey(name); }