Skip to content

Commit f57b0ca

Browse files
RSNarafacebook-github-bot
authored andcommitted
Support nullable returns NativeModule methods returning Boxed Primitives
Summary: Returning null from a NativeModule method that has a return type of `java.lang.Double` causes the program to crash. This diff instead makes that method call return `null` to JS. TurboModules already has this behaviour. Changelog: [Android][Fixed] - Support nullable returns NativeModule methods returning Boxed Primitives Reviewed By: PeteTheHeat Differential Revision: D18866872 fbshipit-source-id: 6049c4df6908f1d276c5674b7e06eb5e002a7976
1 parent 16e8a35 commit f57b0ca

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ReactAndroid/src/main/jni/react/jni/MethodInvoker.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,19 @@ MethodCallResult MethodInvoker::invoke(std::weak_ptr<Instance>& instance, alias_
223223
#define OBJECT_CASE(JNI_CLASS, ACTIONS) { \
224224
auto jobject = env->CallObjectMethodA(module.get(), method_, args); \
225225
throwPendingJniExceptionAsCppException(); \
226+
if (!jobject) { \
227+
return folly::dynamic(nullptr); \
228+
} \
226229
auto result = adopt_local(static_cast<JNI_CLASS::javaobject>(jobject)); \
227230
return folly::dynamic(result->ACTIONS()); \
228231
}
229232

230233
#define OBJECT_CASE_CASTING(JNI_CLASS, ACTIONS, RESULT_TYPE) { \
231234
auto jobject = env->CallObjectMethodA(module.get(), method_, args); \
232235
throwPendingJniExceptionAsCppException(); \
236+
if (!jobject) { \
237+
return folly::dynamic(nullptr); \
238+
} \
233239
auto result = adopt_local(static_cast<JNI_CLASS::javaobject>(jobject)); \
234240
return folly::dynamic(static_cast<RESULT_TYPE>(result->ACTIONS())); \
235241
}

0 commit comments

Comments
 (0)