diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java index f227f0da062..9caaeff3508 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java @@ -63,6 +63,7 @@ public class ReactContext extends ContextWrapper { private @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler; private @Nullable NativeModuleCallExceptionHandler mExceptionHandlerWrapper; private @Nullable WeakReference mCurrentActivity; + private boolean mIsInitialized = false; public ReactContext(Context base) { super(base); @@ -101,6 +102,18 @@ public class ReactContext extends ContextWrapper { mUiMessageQueueThread = queueConfig.getUIQueueThread(); mNativeModulesMessageQueueThread = queueConfig.getNativeModulesQueueThread(); mJSMessageQueueThread = queueConfig.getJSQueueThread(); + + /** TODO(T85807990): Fail fast if any of the threads is null. */ + if (mUiMessageQueueThread == null) { + throw new IllegalStateException("UI thread is null"); + } + if (mNativeModulesMessageQueueThread == null) { + throw new IllegalStateException("NativeModules thread is null"); + } + if (mJSMessageQueueThread == null) { + throw new IllegalStateException("JavaScript thread is null"); + } + mIsInitialized = true; } public void resetPerfStats() { @@ -352,10 +365,20 @@ public class ReactContext extends ContextWrapper { } public void assertOnNativeModulesQueueThread() { + /** TODO(T85807990): Fail fast if the ReactContext isn't initialized */ + if (!mIsInitialized) { + throw new IllegalStateException( + "Tried to call assertOnNativeModulesQueueThread() on an uninitialized ReactContext"); + } Assertions.assertNotNull(mNativeModulesMessageQueueThread).assertIsOnThread(); } public void assertOnNativeModulesQueueThread(String message) { + /** TODO(T85807990): Fail fast if the ReactContext isn't initialized */ + if (!mIsInitialized) { + throw new IllegalStateException( + "Tried to call assertOnNativeModulesQueueThread(message) on an uninitialized ReactContext"); + } Assertions.assertNotNull(mNativeModulesMessageQueueThread).assertIsOnThread(message); }