From 7eacf2770e5acb805e342924e5ba0a22587895ce Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 24 Aug 2023 16:52:01 -0700 Subject: [PATCH] Make TurboReactPackage.getModule no nullable (#39140) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39140 TurboReactPackage.getModule is nullable, although the internals of ReactNative requires this method to be non null (otherwise there will a NPEs) I'm making TurboReactPackage.getModule no nullable, this is important to simplify API and future migration to kotlin changelog: [internal] internal/ Reviewed By: cortinico Differential Revision: D48588375 fbshipit-source-id: e510f76ea0271ff33ab2ebe6c76382c4781e1787 --- .../src/main/java/com/facebook/react/TurboReactPackage.java | 3 +-- .../main/java/com/facebook/react/shell/MainReactPackage.java | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/TurboReactPackage.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/TurboReactPackage.java index 67d4b05b4b2ba1..1483dfbedd2216 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/TurboReactPackage.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/TurboReactPackage.java @@ -41,8 +41,7 @@ public List createNativeModules(ReactApplicationContext reactConte * @param name name of the Native Module * @param reactContext {@link ReactApplicationContext} context for this */ - public abstract @Nullable NativeModule getModule( - String name, final ReactApplicationContext reactContext); + public abstract NativeModule getModule(String name, final ReactApplicationContext reactContext); /** * This is a temporary method till we implement TurboModules. Once we implement TurboModules, we diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java index da406d8bedb713..8bda9e47dfcdf6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java @@ -104,7 +104,7 @@ public MainReactPackage(MainPackageConfig config) { } @Override - public @Nullable NativeModule getModule(String name, ReactApplicationContext context) { + public NativeModule getModule(String name, ReactApplicationContext context) { switch (name) { case AccessibilityInfoModule.NAME: return new AccessibilityInfoModule(context); @@ -151,7 +151,8 @@ public MainReactPackage(MainPackageConfig config) { case DevToolsSettingsManagerModule.NAME: return new DevToolsSettingsManagerModule(context); default: - return null; + throw new IllegalArgumentException( + "Could not find Native module for " + name + " in MainReactPackage."); } }