Skip to content

fix: kotlin nullable-receiver compile errors in sdk-react-native android module - #1398

Open
ZayanKhan-12 wants to merge 2 commits into
MetaMask:mainfrom
ZayanKhan-12:fix/1308-kotlin-nullable-receivers
Open

fix: kotlin nullable-receiver compile errors in sdk-react-native android module#1398
ZayanKhan-12 wants to merge 2 commits into
MetaMask:mainfrom
ZayanKhan-12:fix/1308-kotlin-nullable-receivers

Conversation

@ZayanKhan-12

@ZayanKhan-12 ZayanKhan-12 commented Aug 4, 2026

Copy link
Copy Markdown

Description

@metamask/sdk-react-native fails to compile on Android with newer React Native versions (#1308):

MetaMaskReactNativeSdkModule.kt:140:29 Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type 'ReadableMap?'
MetaMaskReactNativeSdkModule.kt:141:35 …
MetaMaskReactNativeSdkModule.kt:182:45 … 'ReadableMap?'
MetaMaskReactNativeSdkModule.kt:183:49 … 'ReadableArray?'

Newer RN annotates ReadableArray.getMap(i) and Dynamic.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-method check, and lines 140–141 then operate on a non-null receiver
  • Dynamic.asAny(): safe calls (asMap()?.toHashMap(), asArray()?.toArrayList()) — the function already returns Any?

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 compileDebugKotlin locally — 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, and Dynamic.asArray are @Nullable, which broke Kotlin compilation in MetaMaskReactNativeSdkModule.

In batchRequest, a null entry from getMap(i) now throws IllegalArgumentException (aligned with existing validation for missing method). In Dynamic.asAny(), map/array branches use safe calls so nested params can resolve to null without 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.

ZayanKhan-12 and others added 2 commits August 3, 2026 20:23
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: unable to run SDK in a project, syntax issues from the SDK

1 participant