Skip to content

Conversation

@ramanverse
Copy link
Contributor

Fix NullPointerException in PromiseImpl.reject

Summary

This PR fixes a NullPointerException that occurs when Promise.reject is called with a null code from Java native modules.

The issue arises because Promise.kt and PromiseImpl.kt defined the code parameter as non-nullable String in several overloads. However, PromiseImpl's internal logic (specifically the catch-all reject method) is designed to handle null codes by defaulting to EUNSPECIFIED.

When a Java module (such as react-native-ble-plx) calls promise.reject(null, message), Kotlin's generated null-checks throw a NullPointerException before the method body is executed.

Changelog

[Android] [Fixed] - Allow nullable code in Promise.reject to prevent NPEs from Java modules

Test Plan

  1. Create a native module in Java that calls promise.reject(null, "Error message").
  2. Before this fix, the app crashes with java.lang.NullPointerException: Parameter specified as non-null is null: method com.facebook.react.bridge.PromiseImpl.reject, parameter code.
  3. After this fix, the promise is rejected with code EUNSPECIFIED and the app does not crash.

Related Issue

Fixes #54722

This commit relaxes the nullability contract of the `Promise.reject` methods to allow a null `code` parameter.
This fixes a crash observed when native modules (like react-native-ble-plx) pass null for the error code, which was previously causing a NullPointerException due to Kotlin's non-null enforcement.

Fixes facebook#54722
@meta-cla
Copy link

meta-cla bot commented Nov 29, 2025

Hi @ramanverse!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 29, 2025
@meta-cla
Copy link

meta-cla bot commented Nov 29, 2025

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 29, 2025
@meta-codesync
Copy link

meta-codesync bot commented Dec 1, 2025

@javache has imported this pull request. If you are a Meta employee, you can view this in D88066375.

Copy link
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync bot closed this in 47c4568 Dec 1, 2025
@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Dec 1, 2025
@meta-codesync
Copy link

meta-codesync bot commented Dec 1, 2025

@javache merged this pull request in 47c4568.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

react-native-ble-plx BLE command fails with NullPointerException inside PromiseImpl.reject

3 participants