Repository navigation
Fix NullPointerException in PromiseImpl.reject by allowing nullable code - #54731
ramanverse wants to merge 1 commit into
Conversation
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 react#54722
|
Hi @ramanverse! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
cortinico
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Fix NullPointerException in PromiseImpl.reject
Summary
This PR fixes a
NullPointerExceptionthat occurs whenPromise.rejectis called with anullcode from Java native modules.The issue arises because
Promise.ktandPromiseImpl.ktdefined thecodeparameter as non-nullableStringin several overloads. However,PromiseImpl's internal logic (specifically the catch-allrejectmethod) is designed to handlenullcodes by defaulting toEUNSPECIFIED.When a Java module (such as
react-native-ble-plx) callspromise.reject(null, message), Kotlin's generated null-checks throw aNullPointerExceptionbefore the method body is executed.Changelog
[Android] [Fixed] - Allow nullable
codeinPromise.rejectto prevent NPEs from Java modulesTest Plan
promise.reject(null, "Error message").java.lang.NullPointerException: Parameter specified as non-null is null: method com.facebook.react.bridge.PromiseImpl.reject, parameter code.EUNSPECIFIEDand the app does not crash.Related Issue
Fixes #54722