Add null check for instance manager (#45549)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45549

## Summary
Calling `getCurrentReactContext` on an unmounted `ReactRootView` could lead to a NPE. The method currently returns a nullable value so return type is the exact same. This change checks if the react instance manager is present and returns null early if not.

## Changelog:
[Android] [Fixed] - Adds a null check in react context getter

Reviewed By: zeyap

Differential Revision: D59982179

fbshipit-source-id: bac5c12e7dc4ee3296991063eb3746141b8446bc
This commit is contained in:
Peter Abbondanzo
2024-07-19 15:45:20 -07:00
committed by Facebook GitHub Bot
parent 123d7d4229
commit aeb020dfa3
@@ -817,6 +817,9 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
@Nullable
public ReactContext getCurrentReactContext() {
if (mReactInstanceManager == null) {
return null;
}
return mReactInstanceManager.getCurrentReactContext();
}