From 21e4584ad99ca1ad88fb37b5624612a2bee325ca Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Tue, 29 Oct 2024 06:46:20 -0700 Subject: [PATCH] Avoid null reference exception when fetching ReactRootView in bridgeless Summary: If the surface hasn't been set up yet, attempting to fetch the ReactRootView will throw a null reference exception. Since the result is already nullable, it's perhaps better to just return null when the surface has not yet been initialized. ## Changelog [Android][Fixed] Avoid null reference exception in bridgeless ReactDelegate Differential Revision: D65141137 --- .../src/main/java/com/facebook/react/ReactDelegate.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java index 090b55f59ee129..983526a5e36f61 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactDelegate.java @@ -319,7 +319,11 @@ public void unloadApp() { @Nullable public ReactRootView getReactRootView() { if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) { - return (ReactRootView) mReactSurface.getView(); + if (mReactSurface != null) { + return (ReactRootView) mReactSurface.getView(); + } else { + return null; + } } else { return mReactRootView; }