Repository: thundernest/k-9
Issue: Crash: NPE in Address.hashCode()

Via Play Developer Console
App version: 5.200

```
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
	at com.fsck.k9.mail.Address.hashCode(Address.java:176)
	at java.util.Collections.secondaryHash(Collections.java:3405)
	at java.util.LinkedHashMap.get(LinkedHashMap.java:250)
	at android.support.v4.util.LruCache.get(LruCache.java:84)
	at com.fsck.k9.activity.misc.ContactPictureLoader.getBitmapFromCache(ContactPictureLoader.java:213)
	at com.fsck.k9.activity.misc.ContactPictureLoader.loadContactPicture(ContactPictureLoader.java:133)
	at com.fsck.k9.activity.compose.RecipientAdapter.setContactPhotoOrPlaceholder(RecipientAdapter.java:137)
	at com.fsck.k9.view.RecipientSelectView.bindObjectView(RecipientSelectView.java:128)
	at com.fsck.k9.view.RecipientSelectView.getViewForObject(RecipientSelectView.java:112)
	at com.fsck.k9.view.RecipientSelectView.buildSpanForObject(RecipientSelectView.java:437)
	at com.fsck.k9.view.RecipientSelectView.buildSpanForObject(RecipientSelectView.java:47)
	at com.tokenautocomplete.TokenCompleteTextView.insertSpan(TokenCompleteTextView.java:1031)
	at com.tokenautocomplete.TokenCompleteTextView.access$700(TokenCompleteTextView.java:54)
	at com.tokenautocomplete.TokenCompleteTextView$3.run(TokenCompleteTextView.java:924)
	at android.os.Handler.handleCallback(Handler.java:739)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:135)
	at android.app.ActivityThread.main(ActivityThread.java:5930)
	at java.lang.reflect.Method.invoke(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:372)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
```

Changed files:
k9mail-library/src/test/java/com/fsck/k9/mail/AddressTest.java, k9mail-library/src/main/java/com/fsck/k9/mail/Address.java

diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/Address.java b/k9mail-library/src/main/java/com/fsck/k9/mail/Address.java
index dfb778a4a..5b6b3885c 100644
--- a/k9mail-library/src/main/java/com/fsck/k9/mail/Address.java
+++ b/k9mail-library/src/main/java/com/fsck/k9/mail/Address.java
@@ -173,7 +173,10 @@ public class Address implements Serializable {
 
     @Override
     public int hashCode() {
-        int hash = mAddress.hashCode();
+        int hash = 0;
+        if (mAddress != null) {
+            hash += mAddress.hashCode();
+        }
         if (mPersonal != null) {
             hash += 3 * mPersonal.hashCode();
         }
diff --git a/k9mail-library/src/test/java/com/fsck/k9/mail/AddressTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/AddressTest.java
index ba21a4844..33eff0d1b 100644
--- a/k9mail-library/src/test/java/com/fsck/k9/mail/AddressTest.java
+++ b/k9mail-library/src/test/java/com/fsck/k9/mail/AddressTest.java
@@ -7,6 +7,7 @@ import org.robolectric.RobolectricTestRunner;
 import org.robolectric.annotation.Config;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 
 
 @RunWith(RobolectricTestRunner.class)
@@ -89,4 +90,20 @@ public class AddressTest {
         assertEquals("\\"sa\\"mp\\"le\\"", Address.quoteString("\\"sa\\"mp\\"le\\""));
         assertEquals("\\"\\"\\"", Address.quoteString("\\""));
     }
+
+    @Test
+    public void hashCode_withoutAddress() throws Exception {
+        Address address = Address.parse("name only")[0];
+        assertNull(address.getAddress());
+        
+        address.hashCode();
+    }
+
+    @Test
+    public void hashCode_withoutPersonal() throws Exception {
+        Address address = Address.parse("alice@example.org")[0];
+        assertNull(address.getPersonal());
+        
+        address.hashCode();
+    }
 }