OSDN Git Service

Fixing NPE in raw contact sorting
authorDmitri Plotnikov <dplotnikov@google.com>
Tue, 16 Mar 2010 02:06:33 +0000 (19:06 -0700)
committerDmitri Plotnikov <dplotnikov@google.com>
Tue, 16 Mar 2010 02:06:33 +0000 (19:06 -0700)
Bug: 2513827
Change-Id: I92e263d8d258ab49d4b513e8acd0586354af7c9d

src/com/android/contacts/ui/EditContactActivity.java

index 35224d2..b79ba0f 100644 (file)
@@ -242,7 +242,7 @@ public final class EditContactActivity extends Activity
             final boolean hasState = entitySet.size() > 0;
             if (hasExtras && hasState) {
                 // Find source defining the first RawContact found
-                final EntityDelta state = entitySet.get(0);
+                final EntityDelta state = target.mState.get(0);
                 final String accountType = state.getValues().getAsString(RawContacts.ACCOUNT_TYPE);
                 final ContactsSource source = sources.getInflatedSource(accountType,
                         ContactsSource.LEVEL_CONSTRAINTS);
@@ -1350,7 +1350,7 @@ public final class EditContactActivity extends Activity
             return -1;
         } else if (twoIsGoogle && !oneIsGoogle) {
             return 1;
-        } else {
+        } else if (oneIsGoogle && twoIsGoogle){
             skipAccountTypeCheck = true;
         }
 
@@ -1375,8 +1375,14 @@ public final class EditContactActivity extends Activity
         }
 
         // Both are in the same account, fall back to contact ID
-        long oneId = oneValues.getAsLong(RawContacts._ID);
-        long twoId = twoValues.getAsLong(RawContacts._ID);
+        Long oneId = oneValues.getAsLong(RawContacts._ID);
+        Long twoId = twoValues.getAsLong(RawContacts._ID);
+        if (oneId == null) {
+            return -1;
+        } else if (twoId == null) {
+            return 1;
+        }
+
         return (int)(oneId - twoId);
     }