From fa9fed9b849600a6f8babd1dbca70480a58eac0d Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Mon, 15 Mar 2010 16:31:45 -0700 Subject: [PATCH] Fix NPE in stopPing (when account has been deleted) * Check for null when retrieving Mailbox * Fix other two spots where we needed checks; thanks, Makoto! Bug: 2516857 Change-Id: I56ccca16b5f85521e67ef6f92d1cd8f10e5f4a44 --- src/com/android/exchange/SyncManager.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/com/android/exchange/SyncManager.java b/src/com/android/exchange/SyncManager.java index 3cd8190b2..d4501b8ea 100644 --- a/src/com/android/exchange/SyncManager.java +++ b/src/com/android/exchange/SyncManager.java @@ -299,6 +299,7 @@ public class SyncManager extends Service implements Runnable { if (syncManager == null) return; checkSyncManagerServiceRunning(); Mailbox m = Mailbox.restoreMailboxWithId(syncManager, mailboxId); + if (m == null) return; if (m.mType == Mailbox.TYPE_OUTBOX) { // We're using SERVER_ID to indicate an error condition (it has no other use for // sent mail) Upon request to sync the Outbox, we clear this so that all messages @@ -1358,6 +1359,7 @@ public class SyncManager extends Service implements Runnable { Email.EXCHANGE_ACCOUNT_MANAGER_TYPE); // Get the mailbox; this happens rarely so it's ok to get it all Mailbox mailbox = Mailbox.restoreMailboxWithId(this, mailboxId); + if (mailbox == null) return; int syncInterval = mailbox.mSyncInterval; // If we're syncable, look further... if (ContentResolver.getIsSyncable(acct, authority) > 0) { @@ -1558,11 +1560,13 @@ public class SyncManager extends Service implements Runnable { // Go through our active mailboxes looking for the right one for (long mailboxId: mServiceMap.keySet()) { Mailbox m = Mailbox.restoreMailboxWithId(this, mailboxId); - if (m.mAccountKey == accountId && - m.mServerId.startsWith(Eas.ACCOUNT_MAILBOX_PREFIX)) { - // Here's our account mailbox; reset him (stopping pings) - AbstractSyncService svc = mServiceMap.get(mailboxId); - svc.reset(); + if (m != null) { + if (m.mAccountKey == accountId && + m.mServerId.startsWith(Eas.ACCOUNT_MAILBOX_PREFIX)) { + // Here's our account mailbox; reset him (stopping pings) + AbstractSyncService svc = mServiceMap.get(mailboxId); + svc.reset(); + } } } }