Prevent a null address from being added to the address map

Consolidate the implementations of getAddress

Also, removed unnecessary null checks from Utils#getAddress(), as if
cache was null, starting the synchronized block would have thrown an exception

Bug: 11009928
Change-Id: Ib7685b28224b14e4d881594cdca13096771d5185
diff --git a/src/com/android/mail/ui/ConversationViewFragment.java b/src/com/android/mail/ui/ConversationViewFragment.java
index e6b9a1d..f7a5093 100644
--- a/src/com/android/mail/ui/ConversationViewFragment.java
+++ b/src/com/android/mail/ui/ConversationViewFragment.java
@@ -1013,15 +1013,7 @@
     }
 
     protected Address getAddress(String rawFrom) {
-        Address addr;
-        synchronized (mAddressCache) {
-            addr = mAddressCache.get(rawFrom);
-            if (addr == null) {
-                addr = Address.getEmailAddress(rawFrom);
-                mAddressCache.put(rawFrom, addr);
-            }
-        }
-        return addr;
+        return Utils.getAddress(mAddressCache, rawFrom);
     }
 
     private void ensureContentSizeChangeListener() {
diff --git a/src/com/android/mail/utils/Utils.java b/src/com/android/mail/utils/Utils.java
index e6a0312..7b57b83 100644
--- a/src/com/android/mail/utils/Utils.java
+++ b/src/com/android/mail/utils/Utils.java
@@ -1432,14 +1432,12 @@
 
 
     public static Address getAddress(Map<String, Address> cache, String emailStr) {
-        Address addr = null;
+        Address addr;
         synchronized (cache) {
-            if (cache != null) {
-                addr = cache.get(emailStr);
-            }
+            addr = cache.get(emailStr);
             if (addr == null) {
                 addr = Address.getEmailAddress(emailStr);
-                if (cache != null) {
+                if (addr != null) {
                     cache.put(emailStr, addr);
                 }
             }