Bug 1356693 - Pre: add comment explaining why MergeCursor can't handle null cursors draft
authorAndrzej Hunt <ahunt@mozilla.com>
Fri, 28 Apr 2017 08:38:41 +0800
changeset 569894 bf3b3797097cfda7e418e38be419650b6de11b9a
parent 569893 f75ab922115e204ea80b5a91d6c8172226ec39d0
child 569895 68b43a5b065ef82b7d9e0144f98cc94308e7b532
push id56302
push userahunt@mozilla.com
push dateFri, 28 Apr 2017 00:45:18 +0000
bugs1356693
milestone55.0a1
Bug 1356693 - Pre: add comment explaining why MergeCursor can't handle null cursors MozReview-Commit-ID: CGwMi9LKYTj
mobile/android/base/java/org/mozilla/gecko/home/BookmarksPanel.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/BookmarksPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/BookmarksPanel.java
@@ -292,26 +292,32 @@ public class BookmarksPanel extends Home
                     && (isRootFolder || mFolderInfo.id <= Bookmarks.FAKE_PARTNER_BOOKMARKS_START)) {
                 partnerCursor = contentResolver.query(PartnerBookmarksProviderProxy.getUriForBookmarks(getContext(), mFolderInfo.id), null, null, null, null);
             }
 
             if (isRootFolder || mFolderInfo.id > Bookmarks.FAKE_PARTNER_BOOKMARKS_START) {
                 userCursor = mDB.getBookmarksInFolder(contentResolver, mFolderInfo.id);
             }
 
-
+            // MergeCursor is only partly capable of handling null cursors, hence the complicated
+            // logic here. The main issue is CursorAdapter always queries the _id column when
+            // swapping a cursor. If you haven't started iterating over the cursor, MergeCursor will
+            // try to fetch columns from the first Cursor in the list - if that item is null,
+            // we can't getColumnIndexOrThrow("_id"), and CursorAdapter crashes.
             if (partnerCursor == null && userCursor == null) {
                 return null;
             } else if (partnerCursor == null) {
                 return userCursor;
             } else if (userCursor == null) {
                 return partnerCursor;
             } else {
-                return new MergeCursor(new Cursor[] { partnerCursor, userCursor });
+                return new MergeCursor(new Cursor[]{ partnerCursor, userCursor });
             }
+
+
         }
 
         @Override
         public void onContentChanged() {
             // Invalidate the cached value that keeps track of whether or
             // not desktop bookmarks exist.
             mDB.invalidate();
             super.onContentChanged();