Fix NPE in NotificationController

This would happen when a message has no from addresses.

Bug 4027170

Change-Id: I1da091a6a55b274805ee6b3e109cbeb55a21fae1
This commit is contained in:
Makoto Onuki 2011-03-08 10:34:18 -08:00
parent 4408de227c
commit 43c455eb26
2 changed files with 22 additions and 1 deletions

View File

@ -215,7 +215,10 @@ public class NotificationController {
return null; // no message found???
}
final String senderName = Address.toFriendly(Address.unpack(message.mFrom));
String senderName = Address.toFriendly(Address.unpack(message.mFrom));
if (senderName == null) {
senderName = ""; // Happens when a message has no from.
}
final String subject = message.mSubject;
final Bitmap senderPhoto = getSenderPhoto(message);

View File

@ -224,6 +224,24 @@ public class NotificationControllerTest extends AndroidTestCase {
// TODO Add 2 account test, if we find a way to check content
}
public void testCreateNewMessageNotificationWithEmptyFrom() {
final Context c = mProviderContext;
Notification n;
// Message with no from fields.
Account a1 = ProviderTestUtils.setupAccount("a1", true, c);
Mailbox b1 = ProviderTestUtils.setupMailbox("inbox", a1.mId, true, c, Mailbox.TYPE_INBOX);
Message m1 = ProviderTestUtils.setupMessage("message", a1.mId, b1.mId, true, false, c);
m1.mFrom = null;
m1.save(c);
// This shouldn't crash.
n = mTarget.createNewMessageNotification(a1.mId, 1);
// Minimum test for the result
assertEquals(R.drawable.stat_notify_email_generic, n.icon);
}
public void testGetNotificationTitle() {
final Context c = mProviderContext;