Bug 1390140 - Account for bookmark ID being <null> when populating BrowserSearch's HomeContextMenuInfo. r?grisha draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Wed, 23 Aug 2017 21:13:35 +0200
changeset 651461 a7fa7485687fa680114046201b3a32297fb97ebd
parent 651456 6ffcdde3eaba8f47ed27e4c3c762201e534aaaf0
child 727727 fce7d612a3293c16ffb57ea5500c32cf903b3f85
push id75744
push usermozilla@buttercookie.de
push dateWed, 23 Aug 2017 19:20:10 +0000
reviewersgrisha
bugs1390140
milestone57.0a1
Bug 1390140 - Account for bookmark ID being <null> when populating BrowserSearch's HomeContextMenuInfo. r?grisha The combined history view returns a bookmark ID of <null> for items that aren't a bookmark. Calling cursor.getInt() silently turns this into an ID of 0, which doesn't play well with the rest of our code that assumes that the bookmark ID for items that aren't in fact bookmarks is -1. When pressing "Remove" on a search history result, this means that we then end up trying to remove bookmark 0, i.e. the root "bookmark". Luckily this attempt doesn't succeed, but unfortunately still manages to crash the browser along the way. MozReview-Commit-ID: FZk4cI2EDAE
mobile/android/base/java/org/mozilla/gecko/home/BrowserSearch.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/BrowserSearch.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/BrowserSearch.java
@@ -372,17 +372,18 @@ public class BrowserSearch extends HomeF
 
         mList.setContextMenuInfoFactory(new HomeContextMenuInfo.Factory() {
             @Override
             public HomeContextMenuInfo makeInfoForCursor(View view, int position, long id, Cursor cursor) {
                 final HomeContextMenuInfo info = new HomeContextMenuInfo(view, position, id);
                 info.url = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.URL));
                 info.title = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.TITLE));
 
-                int bookmarkId = cursor.getInt(cursor.getColumnIndexOrThrow(BrowserContract.Combined.BOOKMARK_ID));
+                final int bookmarkColumn = cursor.getColumnIndexOrThrow(BrowserContract.Combined.BOOKMARK_ID);
+                int bookmarkId = cursor.isNull(bookmarkColumn) ? -1 : cursor.getInt(bookmarkColumn);
                 info.bookmarkId = bookmarkId;
 
                 int historyId = cursor.getInt(cursor.getColumnIndexOrThrow(BrowserContract.Combined.HISTORY_ID));
                 info.historyId = historyId;
 
                 boolean isBookmark = bookmarkId != -1;
                 boolean isHistory = historyId != -1;