Log SoftExceptions when the legacy NativeModule system is used

Summary:
When ReactFeatureFlags.warnOnLegacyNativeModuleSystemUse is true, we will log a SoftException, whenever:
1. A Java/Cxx NativeModule is created by the legacy system.
2. Any method on the Java NativeModule is executed, including getConstants().

NOTE: Logs to CXXModule use incoming.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D30252953

fbshipit-source-id: 570929624d0114bb298c593ba909e5cdbd54bd6c
This commit is contained in:
Ramanpreet Nara
2021-08-13 13:53:44 -07:00
committed by Facebook GitHub Bot
parent 2b427f8692
commit f93d95e079
2 changed files with 59 additions and 0 deletions
@@ -21,6 +21,7 @@ public class NativeModuleRegistry {
private final ReactApplicationContext mReactApplicationContext;
private final Map<String, ModuleHolder> mModules;
private final String TAG = NativeModuleRegistry.class.getSimpleName();
public NativeModuleRegistry(
ReactApplicationContext reactApplicationContext, Map<String, ModuleHolder> modules) {
@@ -41,6 +42,17 @@ public class NativeModuleRegistry {
ArrayList<JavaModuleWrapper> javaModules = new ArrayList<>();
for (Map.Entry<String, ModuleHolder> entry : mModules.entrySet()) {
if (!entry.getValue().isCxxModule()) {
if (ReactFeatureFlags.warnOnLegacyNativeModuleSystemUse) {
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"Registering legacy NativeModule: Java NativeModule (name = \""
+ entry.getValue().getName()
+ "\", className = "
+ entry.getValue().getClassName()
+ ")."));
}
javaModules.add(new JavaModuleWrapper(jsInstance, entry.getValue()));
}
}
@@ -51,6 +63,16 @@ public class NativeModuleRegistry {
ArrayList<ModuleHolder> cxxModules = new ArrayList<>();
for (Map.Entry<String, ModuleHolder> entry : mModules.entrySet()) {
if (entry.getValue().isCxxModule()) {
if (ReactFeatureFlags.warnOnLegacyNativeModuleSystemUse) {
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"Registering legacy NativeModule: Cxx NativeModule (name = \""
+ entry.getValue().getName()
+ "\", className = "
+ entry.getValue().getClassName()
+ ")."));
}
cxxModules.add(entry.getValue());
}
}