From e69be0ae555dad2bdec0ea7e4fc62a4ee349cc2d Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Wed, 27 Nov 2019 10:36:17 -0800 Subject: [PATCH] Give ReactContextBaseJavaModule a 0 arg ctor Summary: We need to make our ExceptionsManagers into TurboModules. To do so, we need to first make them type-safe. This requires extending the base class code-generated from the NativeModule JavaScript spec. That base class extends `ReactContextBaseJavaModule`, which requires `ReactApplicationContext` to instantiate. Unfortunatley, our ExceptionsManagers need to be created before the `ReactInstanceManager`. This means that the `ReactApplicationContext` isn't available by the time they're created. In this diff, I make the `ReactContextBaseJavaModule` have a 0 argument constructor that simply sets its ReactApplicationContext to null. This will allow us to eventually migrate our ExceptionsManagers to the TurboModule system. Changelog: [Android][Added] - Give ReactContextBaseJavaModule a 0 arg ctor Reviewed By: mdvacca Differential Revision: D18717908 fbshipit-source-id: 203ffc49f2ec0b32a809402801795879d3b3a64b --- .../react/bridge/ReactContextBaseJavaModule.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContextBaseJavaModule.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContextBaseJavaModule.java index 386a18674ae..ea6d366f9fe 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContextBaseJavaModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContextBaseJavaModule.java @@ -13,6 +13,7 @@ import android.app.Activity; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.facebook.common.logging.FLog; +import com.facebook.infer.annotation.Assertions; import com.facebook.infer.annotation.ThreadConfined; import com.facebook.react.common.build.ReactBuildConfig; @@ -21,7 +22,11 @@ import com.facebook.react.common.build.ReactBuildConfig; */ public abstract class ReactContextBaseJavaModule extends BaseJavaModule { - private final ReactApplicationContext mReactApplicationContext; + private final @Nullable ReactApplicationContext mReactApplicationContext; + + public ReactContextBaseJavaModule() { + mReactApplicationContext = null; + } public ReactContextBaseJavaModule(@NonNull ReactApplicationContext reactContext) { mReactApplicationContext = reactContext; @@ -29,7 +34,9 @@ public abstract class ReactContextBaseJavaModule extends BaseJavaModule { /** Subclasses can use this method to access catalyst context passed as a constructor. */ protected final ReactApplicationContext getReactApplicationContext() { - return mReactApplicationContext; + return Assertions.assertNotNull( + mReactApplicationContext, + "Tried to get ReactApplicationContext even though NativeModule wasn't instantiated with one"); } /**