Repository navigation
Conversation
…tive map or array Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tomekzaw
marked this pull request as ready for review
October 30, 2026 22:04
javache
requested changes
Oct 30, 2026
| name_ + "." + methodName + | ||
| "() must return a native map, such as one from Arguments.createMap()"); | ||
| } | ||
| auto result = jni::static_ref_cast<NativeMap::jhybridobject>(jResult); |
Contributor
There was a problem hiding this comment.
If we want to type-check this unconditionally, we should use dynamic_ref_cast instead. Alternatively, we could only do the type-check in debug?
Contributor
Author
There was a problem hiding this comment.
Switched to dynamic_ref_cast in 1cbf1b1. The crash happens in release builds, so I kept the check unconditional. Rechecked on a Galaxy A16: a JavaOnlyMap/JavaOnlyArray result now throws a ClassCastException as a JS error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
For a synchronous method that returns an object or an array,
JavaTurboModulecasts the result toNativeMaporNativeArrayand reads its C++ part. A module can return anyWritableMap/WritableArray, for example aJavaOnlyMaporJavaOnlyArray. JNI then reads an unrelated field of that object as the native pointer, and the app crashes on the JS thread with a SIGSEGV inNativeMap::consume().This casts the result with
dynamic_ref_castinstead ofstatic_ref_cast, so a result that isn't a native map or array throws aClassCastException, which becomes a JS error.Changelog:
[ANDROID] [FIXED] - Throw a JS error instead of crashing when a synchronous TurboModule method returns a map or array that isn't a native one
Test Plan:
Release RNTester (
./gradlew :packages:rn-tester:android:app:assembleRelease -PreactNativeArchitectures=arm64-v8a) with these temporary, uncommitted changes:SampleTurboModule.getObjectreturnsJavaOnlyMap.of("a", 1.0)andgetArrayreturnsJavaOnlyArray.of("a")when given a marker argument.SampleTurboModulecan't initialize in a minified build, which is a separate issue.On a Galaxy A16 (Android 16):
maingetObjectreturning aJavaOnlyMap#00 NativeMap::consume(),#01 JavaTurboModule::invokeJavaMethodjava.lang.ClassCastException: Tried to cast from class com.facebook.react.bridge.JavaOnlyMap to com/facebook/react/bridge/NativeMap.getArrayreturning aJavaOnlyArrayjava.lang.ClassCastException: Tried to cast from class com.facebook.react.bridge.JavaOnlyArray to com/facebook/react/bridge/NativeArray.getObject({a: 1, b: 'two'}),getArray([1, 'two', {three: 3}]),getConstants()Not run: an automated test.
JavaTurboModulehas no host-side tests, and Fantom doesn't load Java modules.🤖 Generated with Claude Code