Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Check for nullability of instance to avoid NPEs (#111)
Browse files Browse the repository at this point in the history
* We have found some apps crashed due to a NPE in Dexter.
  The problem can be reproduced by following these steps:
    * Accept one permission
    * Request other permission and while the native dialog
      is on screen go to the settings page for your app
    * Manually change the previous accepted permission to
      denied
    * Open the application again and BOOM!
  This happens because Android will partially restart the
  app when changing permissions from the settings.
  DexterActivity will try to notify dexter of the changes
  and will find that the static instance has been cleaned up.
* The easiest solution for now is to just ignore events from
  the activity if the instance is null.
  • Loading branch information
Serchinastico authored Feb 1, 2017
1 parent 01fc043 commit 3a63bc5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions dexter/src/main/java/com/karumi/dexter/Dexter.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ private static void initialize(Context context) {
* used.
*/
static void onActivityReady(Activity activity) {
instance.onActivityReady(activity);
/* Check against null values because sometimes the DexterActivity can call these internal
methods when the DexterInstance has been cleaned up.
Refer to this commit message for a more detailed explanation of the issue.
*/
if (instance != null) {
instance.onActivityReady(activity);
}
}

/**
Expand All @@ -150,7 +156,13 @@ static void onActivityReady(Activity activity) {
*/
static void onPermissionsRequested(Collection<String> grantedPermissions,
Collection<String> deniedPermissions) {
instance.onPermissionRequestGranted(grantedPermissions);
instance.onPermissionRequestDenied(deniedPermissions);
/* Check against null values because sometimes the DexterActivity can call these internal
methods when the DexterInstance has been cleaned up.
Refer to this commit message for a more detailed explanation of the issue.
*/
if (instance != null) {
instance.onPermissionRequestGranted(grantedPermissions);
instance.onPermissionRequestDenied(deniedPermissions);
}
}
}

0 comments on commit 3a63bc5

Please sign in to comment.