Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50d81f70 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #1883 from k9mail/GH-1874_fix_address_hashcode

Avoid NPE in Address.hashCode()
parents b2ed230b 40e5f038
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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();
        }
+17 −0
Original line number Diff line number Diff line
@@ -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();
    }
}