fix: kotlin nullable-receiver compile errors in sdk-react-native android module - #1398
Open
ZayanKhan-12 wants to merge 2 commits into
Open
fix: kotlin nullable-receiver compile errors in sdk-react-native android module#1398ZayanKhan-12 wants to merge 2 commits into
ZayanKhan-12 wants to merge 2 commits into
Conversation
…oid module Newer React Native versions annotate ReadableArray.getMap and Dynamic.asMap/asArray as nullable, so the unsafe calls in MetaMaskReactNativeSdkModule.kt fail compileDebugKotlin with 'Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver'. Handle the nulls explicitly: reject batch entries that are not maps, and use safe calls in the Dynamic conversion. Both patterns also compile against older RN where these are platform types. Fixes MetaMask#1308 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Description
@metamask/sdk-react-nativefails to compile on Android with newer React Native versions (#1308):Newer RN annotates
ReadableArray.getMap(i)andDynamic.asMap()/asArray()as@Nullable, so Kotlin rejects the unsafe calls. This handles the nulls explicitly:batchRequest:reqArray.getMap(i) ?: throw IllegalArgumentException("Request at index $i must be a map")— same failure mode as the existing missing-methodcheck, and lines 140–141 then operate on a non-null receiverDynamic.asAny(): safe calls (asMap()?.toHashMap(),asArray()?.toArrayList()) — the function already returnsAny?Both patterns compile identically against older RN where these getters are platform types, so no behavior change for existing consumers.
Fixes #1308
Testing
Mechanical null-safety change verified against the compiler errors reported in the issue (the reporter's repro is at Arthur-Kamau/react-native-sample). I don't have an Android toolchain in this environment to run
compileDebugKotlinlocally — flagging that honestly; the change only touches the four reported lines.🤖 Generated with Claude Code
Note
Low Risk
Tiny compile-time null-handling change in the Android bridge; intended behavior unchanged on older RN, with slightly clearer errors for malformed batch entries.
Overview
Fixes Android build failures on newer React Native versions where
ReadableArray.getMap,Dynamic.asMap, andDynamic.asArrayare@Nullable, which broke Kotlin compilation inMetaMaskReactNativeSdkModule.In
batchRequest, a null entry fromgetMap(i)now throwsIllegalArgumentException(aligned with existing validation for missingmethod). InDynamic.asAny(), map/array branches use safe calls so nested params can resolve tonullwithout crashing the compiler.Changelog updated under Unreleased → Fixed.
Reviewed by Cursor Bugbot for commit c2177e5. Bugbot is set up for automated code reviews on this repo. Configure here.