Catch NullPointerException for onRequestPermissionsResult#39715
Closed
chakrihacker wants to merge 3 commits into
Closed
Catch NullPointerException for onRequestPermissionsResult#39715chakrihacker wants to merge 3 commits into
onRequestPermissionsResult#39715chakrihacker wants to merge 3 commits into
Conversation
On Android 13 Devices, we are seeing `NullPointerException`, which should be handled with this
Base commit: bad027c |
Contributor
|
Generally catching a NullPointerException means you're masking an underlying error. What object is null? |
Contributor
|
Do you have a callstack? |
Contributor
Author
|
Here's the CallStack I am on react native 0.72.4 |
Contributor
Author
|
|
javache
requested changes
Oct 5, 2023
Comment on lines
175
to
176
| mCallbacks.get(requestCode).invoke(grantResults, getPermissionAwareActivity()); | ||
| mCallbacks.remove(requestCode); |
Contributor
There was a problem hiding this comment.
Instead add a null-check here.
Suggested change
| mCallbacks.get(requestCode).invoke(grantResults, getPermissionAwareActivity()); | |
| mCallbacks.remove(requestCode); | |
| Callback callback = mCallbacks.get(requestCode); | |
| if (callback != null) { | |
| callback.invoke(grantResults, getPermissionAwareActivity()); | |
| mCallbacks.remove(requestCode); | |
| } else { | |
| // Log warning. It's unexpected we're getting a response here we didn't ask for. | |
| } |
javache
reviewed
Oct 5, 2023
Comment on lines
+180
to
+181
| String message = "Unable to find callback with requestCode:" + requestCode; | ||
| FLog.w("PermissionsModule", message); |
Contributor
There was a problem hiding this comment.
nit: inline message
Suggested change
| String message = "Unable to find callback with requestCode:" + requestCode; | |
| FLog.w("PermissionsModule", message); | |
| FLog.w("PermissionsModule", "Unable to find callback with requestCode:" + requestCode); |
Contributor
There was a problem hiding this comment.
Actually, since this is FLog, you can do FLog.w("PermissionsModule", "Unable to find callback with requestCode %d", requestCode).
Contributor
Author
There was a problem hiding this comment.
Thank you updated
Contributor
|
@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Contributor
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:
On Android 13 Devices, we are seeing
NullPointerException, which should be handled with thisChangelog:
[ANDROID] [FIXED] - Handle Crash for onRequestPermissionsResult
Test Plan: