Skip to content

Commit

Permalink
Support nullable returns NativeModule methods returning Boxed Primitives
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RSNara authored and facebook-github-bot committed Dec 7, 2019
1 parent 16e8a35 commit f57b0ca
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ReactAndroid/src/main/jni/react/jni/MethodInvoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,19 @@ MethodCallResult MethodInvoker::invoke(std::weak_ptr<Instance>& instance, alias_
#define OBJECT_CASE(JNI_CLASS, ACTIONS) { \
auto jobject = env->CallObjectMethodA(module.get(), method_, args); \
throwPendingJniExceptionAsCppException(); \
if (!jobject) { \
return folly::dynamic(nullptr); \
} \
auto result = adopt_local(static_cast<JNI_CLASS::javaobject>(jobject)); \
return folly::dynamic(result->ACTIONS()); \
}

#define OBJECT_CASE_CASTING(JNI_CLASS, ACTIONS, RESULT_TYPE) { \
auto jobject = env->CallObjectMethodA(module.get(), method_, args); \
throwPendingJniExceptionAsCppException(); \
if (!jobject) { \
return folly::dynamic(nullptr); \
} \
auto result = adopt_local(static_cast<JNI_CLASS::javaobject>(jobject)); \
return folly::dynamic(static_cast<RESULT_TYPE>(result->ACTIONS())); \
}
Expand Down

0 comments on commit f57b0ca

Please sign in to comment.