From 0dbc15e6f15a01fdb2bd4f5263c06369299ec361 Mon Sep 17 00:00:00 2001 From: Mihai Preda Date: Tue, 22 Sep 2009 17:50:53 +0200 Subject: [PATCH] Email: catch RuntimeException when loading message with huge body from DB. Bug: 2133062. --- .../email/activity/MessageCompose.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/com/android/email/activity/MessageCompose.java b/src/com/android/email/activity/MessageCompose.java index d57f7c74c..d4c52f3b6 100644 --- a/src/com/android/email/activity/MessageCompose.java +++ b/src/com/android/email/activity/MessageCompose.java @@ -496,16 +496,33 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus @Override protected Object[] doInBackground(Long... messageIds) { Message message = Message.restoreMessageWithId(MessageCompose.this, messageIds[0]); + if (message == null) { + return null; + } long accountId = message.mAccountKey; Account account = Account.restoreAccountWithId(MessageCompose.this, accountId); - Body body = Body.restoreBodyWithMessageId(MessageCompose.this, message.mId); - message.mHtml = body.mHtmlContent; - message.mText = body.mTextContent; + try { + // Body body = Body.restoreBodyWithMessageId(MessageCompose.this, message.mId); + message.mHtml = Body.restoreBodyHtmlWithMessageId(MessageCompose.this, message.mId); + message.mText = Body.restoreBodyTextWithMessageId(MessageCompose.this, message.mId); + } catch (RuntimeException e) { + Log.d(Email.LOG_TAG, "Exception while loading message body: " + e); + return null; + } return new Object[]{message, account}; } @Override protected void onPostExecute(Object[] messageAndAccount) { + if (messageAndAccount == null) { + // Something unexpected happened: + // the message or the body couldn't be loaded by SQLite. + // Bail out. + Toast.makeText(MessageCompose.this, R.string.error_loading_message_body, + Toast.LENGTH_LONG).show(); + finish(); + return; + } final Message message = (Message) messageAndAccount[0]; final Account account = (Account) messageAndAccount[1]; final String action = getIntent().getAction();