From 6da93a302ed489c7a52268f789825dd8b8569282 Mon Sep 17 00:00:00 2001 From: Ram N Date: Thu, 6 Sep 2018 23:45:05 -0700 Subject: [PATCH] Better error message when using getNativeModule(Class) Summary: Some of the native modules are accessed using `getNativeModule()` may not have an `ReactModule` annotation. As a result, such native modules cannot be found. This diff adds a better error message, and also adds the annotation to Mobile Home's `PushNotificationManager` that is accessed using the `getNativeModule()` Differential Revision: D9697256 fbshipit-source-id: 2e2f7d2f1eb705c9c515ff40d9acbc53055c26d8 --- .../com/facebook/react/bridge/NativeModuleRegistry.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModuleRegistry.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModuleRegistry.java index 1689a296f..ec695204e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModuleRegistry.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModuleRegistry.java @@ -10,6 +10,7 @@ package com.facebook.react.bridge; import com.facebook.infer.annotation.Assertions; import com.facebook.react.module.annotations.ReactModule; import com.facebook.systrace.Systrace; +import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -132,9 +133,12 @@ public class NativeModuleRegistry { } public T getModule(Class moduleInterface) { - String name = moduleInterface.getAnnotation(ReactModule.class).name(); + ReactModule annotation = moduleInterface.getAnnotation(ReactModule.class); + if (annotation == null) { + throw new IllegalArgumentException("Could not find @ReactModule annotation in class " + moduleInterface.getName()); + } return (T) Assertions.assertNotNull( - mModules.get(name), moduleInterface.getSimpleName()).getModule(); + mModules.get(annotation.name()), annotation.name() + " could not be found. Is it defined in " + moduleInterface.getName()).getModule(); } public List getAllModules() {