From b3eefca0e1c7fffe1b015e18050aee6867bfbcdd Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Fri, 11 Jun 2010 11:37:10 -0700 Subject: [PATCH] DO NOT MERGE: Fix NPE in Controller and MessagingController. Bug 2553401 Bug 2186777 Bug 2721133 Bug 2684365 Bug 2530534 Backport of I5185d9196deab5ba3a9866e2de2a9be04a04ca03 Change-Id: I192267d7d48d377fe1fc083797cb199f8e94c0c4 --- src/com/android/email/Controller.java | 24 +++++++++++++++++++ .../android/email/MessagingController.java | 12 ++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/com/android/email/Controller.java b/src/com/android/email/Controller.java index df7e3b5dd..633a5f4b9 100644 --- a/src/com/android/email/Controller.java +++ b/src/com/android/email/Controller.java @@ -405,6 +405,9 @@ public class Controller { // for IMAP & POP only, (attempt to) send the message now final EmailContent.Account account = EmailContent.Account.restoreAccountWithId(mProviderContext, accountId); + if (account == null) { + return; + } final long sentboxId = findOrCreateMailboxOfType(accountId, Mailbox.TYPE_SENT); new Thread() { @Override @@ -444,6 +447,9 @@ public class Controller { // MessagingController implementation final EmailContent.Account account = EmailContent.Account.restoreAccountWithId(mProviderContext, accountId); + if (account == null) { + return; + } final long sentboxId = findOrCreateMailboxOfType(accountId, Mailbox.TYPE_SENT); new Thread() { @Override @@ -619,6 +625,9 @@ public class Controller { // 6. Service runs automatically, MessagingController needs a kick Account account = Account.restoreAccountWithId(mProviderContext, accountId); + if (account == null) { + return; // isMessagingController returns false for null, but let's make it clear. + } if (isMessagingController(account)) { final long syncAccountId = accountId; new Thread() { @@ -647,7 +656,13 @@ public class Controller { // Service runs automatically, MessagingController needs a kick final Message message = Message.restoreMessageWithId(mProviderContext, messageId); + if (message == null) { + return; + } Account account = Account.restoreAccountWithId(mProviderContext, message.mAccountKey); + if (account == null) { + return; // isMessagingController returns false for null, but let's make it clear. + } if (isMessagingController(account)) { new Thread() { @Override @@ -675,7 +690,13 @@ public class Controller { // Service runs automatically, MessagingController needs a kick final Message message = Message.restoreMessageWithId(mProviderContext, messageId); + if (message == null) { + return; + } Account account = Account.restoreAccountWithId(mProviderContext, message.mAccountKey); + if (account == null) { + return; // isMessagingController returns false for null, but let's make it clear. + } if (isMessagingController(account)) { new Thread() { @Override @@ -772,6 +793,9 @@ public class Controller { private IEmailService getServiceForMessage(long messageId) { // TODO make this more efficient, caching the account, smaller lookup here, etc. Message message = Message.restoreMessageWithId(mProviderContext, messageId); + if (message == null) { + return null; + } return getServiceForAccount(message.mAccountKey); } diff --git a/src/com/android/email/MessagingController.java b/src/com/android/email/MessagingController.java index ceb762b51..93334fcb1 100644 --- a/src/com/android/email/MessagingController.java +++ b/src/com/android/email/MessagingController.java @@ -1094,6 +1094,9 @@ public class MessagingController implements Runnable { if (oldMessage != null) { if (mailbox == null || mailbox.mId != oldMessage.mMailboxKey) { mailbox = Mailbox.restoreMailboxWithId(mContext, oldMessage.mMailboxKey); + if (mailbox == null) { + continue; // Mailbox removed. Move to the next message. + } } deleteFromTrash = mailbox.mType == Mailbox.TYPE_TRASH; } @@ -1177,6 +1180,9 @@ public class MessagingController implements Runnable { // Load the mailbox if it will be needed if (mailbox == null) { mailbox = Mailbox.restoreMailboxWithId(mContext, mailboxId); + if (mailbox == null) { + continue; // Mailbox removed. Move to the next message. + } } // upsync the message long id = upsyncs1.getLong(EmailContent.Message.ID_PROJECTION_COLUMN); @@ -1204,6 +1210,9 @@ public class MessagingController implements Runnable { // Load the mailbox if it will be needed if (mailbox == null) { mailbox = Mailbox.restoreMailboxWithId(mContext, mailboxId); + if (mailbox == null) { + continue; // Mailbox removed. Move to the next message. + } } // upsync the message long id = upsyncs2.getLong(EmailContent.Message.ID_PROJECTION_COLUMN); @@ -1264,6 +1273,9 @@ public class MessagingController implements Runnable { if (newMessage != null) { if (mailbox == null || mailbox.mId != newMessage.mMailboxKey) { mailbox = Mailbox.restoreMailboxWithId(mContext, newMessage.mMailboxKey); + if (mailbox == null) { + continue; // Mailbox removed. Move to the next message. + } } changeMoveToTrash = (oldMessage.mMailboxKey != newMessage.mMailboxKey) && (mailbox.mType == Mailbox.TYPE_TRASH);