From f85e590f58f34edfe0c4e1dc974fd464aeb158ea Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Sat, 14 Nov 2026 10:29:42 -0800 Subject: [PATCH] Throw on unexpected return types for number TurboModule methods on Android Summary: In `JavaTurboModule::invokeJavaMethod`, the `NumberKind` case only handled boxed `Double`/`Float`/`Integer` and primitive `D`/`F`/`I` return types. Any other return type fell through into the `StringKind` case, which called the method as an object-returning method and converted the result as a string. Throw a `std::runtime_error` naming the method and its return type instead, matching how the `default` case reports an unknown method kind. Changelog: [Android][Fixed] - Throw an error instead of treating the result as a string when a number TurboModule method has an unexpected return type Differential Revision: D131835371 --- .../core/platform/android/ReactCommon/JavaTurboModule.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp index 4f3cf28d5cac..072d167935d7 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp @@ -864,6 +864,9 @@ jsi::Value JavaTurboModule::invokeJavaMethod( TMPL::syncMethodCallEnd(moduleName, methodName); return returnValue; } + throw std::runtime_error( + "Unexpected return type " + returnType + + " for number method: " + std::string(methodName)); } case StringKind: { auto returnString =