Bug 765486 - Protect isBookmark() against NPE. r=lucasr a=lsblakk
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Wed, 20 Jun 2012 17:56:02 -0700
changeset 98229 43e03ed8caef600168916826bf805f6f33ad5be8
parent 98228 6d28ccd8dde5b46b192f2feeab7c8b1929c5607b
child 98230 7315c99d681b38c25abf812583301a31cc50749b
push id1570
push usermleibovic@mozilla.com
push dateSat, 23 Jun 2012 00:21:38 +0000
treeherdermozilla-aurora@43e03ed8caef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr, lsblakk
bugs765486
milestone15.0a2
Bug 765486 - Protect isBookmark() against NPE. r=lucasr a=lsblakk
mobile/android/base/db/LocalBrowserDB.java
--- a/mobile/android/base/db/LocalBrowserDB.java
+++ b/mobile/android/base/db/LocalBrowserDB.java
@@ -372,26 +372,30 @@ public class LocalBrowserDB implements B
 
         // Cache result for future queries
         mReadingListItemsExist = (count > 0);
         return mReadingListItemsExist;
     }
 
     public boolean isBookmark(ContentResolver cr, String uri) {
         // This method is about normal bookmarks, not the Reading List
-        Cursor cursor = cr.query(mBookmarksUriWithProfile,
-                                 new String[] { Bookmarks._ID },
-                                 Bookmarks.URL + " = ? AND " +
-                                 Bookmarks.PARENT + " != ?",
-                                 new String[] { uri,
-                                                String.valueOf(Bookmarks.FIXED_READING_LIST_ID) },
-                                 Bookmarks.URL);
-
-        int count = cursor.getCount();
-        cursor.close();
+        int count = 0;
+        try {
+            Cursor c = cr.query(mBookmarksUriWithProfile,
+                                new String[] { Bookmarks._ID },
+                                Bookmarks.URL + " = ? AND " +
+                                Bookmarks.PARENT + " != ?",
+                                new String[] { uri,
+                                               String.valueOf(Bookmarks.FIXED_READING_LIST_ID) },
+                                Bookmarks.URL);
+            count = c.getCount();
+            c.close();
+        } catch (NullPointerException e) {
+            Log.e(LOGTAG, "NullPointerException in isBookmark for " + uri);
+        }
 
         return (count == 1);
     }
 
     public String getUrlForKeyword(ContentResolver cr, String keyword) {
         Cursor cursor = cr.query(mBookmarksUriWithProfile,
                                  new String[] { Bookmarks.URL },
                                  Bookmarks.KEYWORD + " = ?",