Skip to content
Permalink
Browse files
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
  • Loading branch information
RSNara authored and facebook-github-bot committed Dec 7, 2019
1 parent 16e8a35 commit f57b0caaa4452c64006c159cd28a1a562b332c21
Showing 1 changed file with 6 additions and 0 deletions.
@@ -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())); \
}

0 comments on commit f57b0ca

Please sign in to comment.