diff --git a/src/com/android/email/NotificationController.java b/src/com/android/email/NotificationController.java index b5d5f495e..4695afe12 100644 --- a/src/com/android/email/NotificationController.java +++ b/src/com/android/email/NotificationController.java @@ -240,7 +240,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); diff --git a/tests/src/com/android/email/NotificationControllerTest.java b/tests/src/com/android/email/NotificationControllerTest.java index 84e9bbfe8..fd3c19b42 100644 --- a/tests/src/com/android/email/NotificationControllerTest.java +++ b/tests/src/com/android/email/NotificationControllerTest.java @@ -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;