Merge "Fix NPE with null cursor"
diff --git a/src/com/android/contacts/common/list/ProfileAndContactsLoader.java b/src/com/android/contacts/common/list/ProfileAndContactsLoader.java
index 9d2bbbb..e31b8ec 100644
--- a/src/com/android/contacts/common/list/ProfileAndContactsLoader.java
+++ b/src/com/android/contacts/common/list/ProfileAndContactsLoader.java
@@ -56,6 +56,8 @@
         if (mLoadProfile) {
             cursors.add(loadProfile());
         }
+        // ContactsCursor.loadInBackground() can return null; MergeCursor
+        // correctly handles null cursors.
         final Cursor contactsCursor = super.loadInBackground();
         cursors.add(contactsCursor);
         return new MergeCursor(cursors.toArray(new Cursor[cursors.size()])) {
@@ -68,11 +70,17 @@
     }
 
     /**
-     * Loads the profile into a MatrixCursor.
+     * Loads the profile into a MatrixCursor. On failure returns null, which
+     * matches the behavior of CursorLoader.loadInBackground().
+     *
+     * @return MatrixCursor containing profile or null on query failure.
      */
     private MatrixCursor loadProfile() {
         Cursor cursor = getContext().getContentResolver().query(Profile.CONTENT_URI, mProjection,
                 null, null, null);
+        if (cursor == null) {
+            return null;
+        }
         try {
             MatrixCursor matrix = new MatrixCursor(mProjection);
             Object[] row = new Object[mProjection.length];