From 925209932aa20f6c70e9642c5ab8dec8ac83a1cd Mon Sep 17 00:00:00 2001 From: Subramanya Chakravarthy Date: Fri, 6 Oct 2023 04:19:08 -0700 Subject: [PATCH] Catch NullPointerException for `onRequestPermissionsResult` (#39715) Summary: On Android 13 Devices, we are seeing `NullPointerException`, which should be handled with this ## Changelog: [ANDROID] [FIXED] - Handle Crash for onRequestPermissionsResult Pull Request resolved: https://github.com/facebook/react-native/pull/39715 Reviewed By: NickGerleman Differential Revision: D49965583 Pulled By: javache fbshipit-source-id: 8a39049675510f9cca8141c893d93fdb04ba0e25 --- .../react/modules/permissions/PermissionsModule.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/permissions/PermissionsModule.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/permissions/PermissionsModule.java index db0d0941bb0f7e..7bd6dc90ed432b 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/permissions/PermissionsModule.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/permissions/PermissionsModule.java @@ -172,8 +172,13 @@ public void invoke(Object... args) { public boolean onRequestPermissionsResult( int requestCode, String[] permissions, int[] grantResults) { try { - 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 { + FLog.w("PermissionsModule", "Unable to find callback with requestCode %d", requestCode); + } return mCallbacks.size() == 0; } catch (IllegalStateException e) { FLog.e(