Bug 1505720 - Crash [@ java.lang.NullPointerException: at org.mozilla.gecko.fxa.authenticator.AndroidFxAccount.renameAccountIfNecessary(AndroidFxAccount.java)]. r=Grisha, a=RyanVM
authorAndrei Lazar <andrei.a.lazar@softvision.ro>
Tue, 08 Jan 2019 10:28:20 +0000
changeset 509422 35180dd24536b073adc5fb42946a80c556f6a5d0
parent 509421 1d823b3ee5adc7541d54e1484d4bdd8ef963de35
child 509423 9a0b078546bd21aabdc056dfb6a08e8594565d88
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGrisha, RyanVM
bugs1505720
milestone65.0
Bug 1505720 - Crash [@ java.lang.NullPointerException: at org.mozilla.gecko.fxa.authenticator.AndroidFxAccount.renameAccountIfNecessary(AndroidFxAccount.java)]. r=Grisha, a=RyanVM Refreshing account (triggered by signing in) can cause a NullPointerException after quickly signing out. This defect consists in bad sync between the signing in state and signing out state. Differential Revision: https://phabricator.services.mozilla.com/D14269
mobile/android/services/src/main/java/org/mozilla/gecko/fxa/authenticator/AndroidFxAccount.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/authenticator/AndroidFxAccount.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/authenticator/AndroidFxAccount.java
@@ -1072,22 +1072,25 @@ public class AndroidFxAccount {
     protected void onReceiveResult(int resultCode, Bundle bundle) {
       super.onReceiveResult(resultCode, bundle);
       switch (resultCode) {
         case Activity.RESULT_OK:
           Logger.info(LOG_TAG, "Profile JSON fetch succeeded!");
           final String resultData = bundle.getString(FxAccountProfileService.KEY_RESULT_STRING);
           FxAccountUtils.pii(LOG_TAG, "Profile JSON fetch returned: " + resultData);
 
-          renameAccountIfNecessary(resultData, new Runnable() {
-            @Override
-            public void run() {
-              updateBundleValues(BUNDLE_KEY_PROFILE_JSON, resultData);
-              LocalBroadcastManager.getInstance(context).sendBroadcast(makeProfileJSONUpdatedIntent());
-            }
+          // We may get at this point due to a bad sync between states (e.g we sign in then we quickly sign out)
+          // Nothing else we can do but log an error.
+          if (!FirefoxAccounts.firefoxAccountsExist(context)) {
+            Logger.error(LOG_TAG, "ProfileResultReceiver: received result when no account exists!");
+            return;
+          }
+          renameAccountIfNecessary(resultData, () -> {
+            updateBundleValues(BUNDLE_KEY_PROFILE_JSON, resultData);
+            LocalBroadcastManager.getInstance(context).sendBroadcast(makeProfileJSONUpdatedIntent());
           });
           break;
         case Activity.RESULT_CANCELED:
           Logger.warn(LOG_TAG, "Failed to fetch profile JSON; ignoring.");
           break;
         default:
           Logger.warn(LOG_TAG, "Invalid result code received; ignoring.");
           break;