Bug 1210243 - ReadingListPanel.markAsRead can crash on a null return from getActivity() r=sebastian a=lizzard
authorMark Finkle <mfinkle@mozilla.com>
Fri, 02 Oct 2015 16:54:28 -0400
changeset 296375 68f9590115499ee32320d3268a6365ef8b248ba4
parent 296374 4ce2d18fd3c18b0523fa92febf62d258cfdc3a53
child 296376 3902adefa47c767da4aa55e238633018f3560da0
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, lizzard
bugs1210243
milestone43.0a2
Bug 1210243 - ReadingListPanel.markAsRead can crash on a null return from getActivity() r=sebastian a=lizzard
mobile/android/base/home/ReadingListPanel.java
--- a/mobile/android/base/home/ReadingListPanel.java
+++ b/mobile/android/base/home/ReadingListPanel.java
@@ -73,30 +73,35 @@ public class ReadingListPanel extends Ho
         mTopView = view;
 
         mList = (HomeListView) view.findViewById(R.id.list);
         mList.setTag(HomePager.LIST_TAG_READING_LIST);
 
         mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+                final Context context = getActivity();
+                if (context == null) {
+                    return;
+                }
+
                 final Cursor c = mAdapter.getCursor();
                 if (c == null || !c.moveToPosition(position)) {
                     return;
                 }
 
                 String url = c.getString(c.getColumnIndexOrThrow(URLColumns.URL));
                 url = ReaderModeUtils.getAboutReaderForUrl(url);
 
                 Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.LIST_ITEM);
 
                 // This item is a TwoLinePageRow, so we allow switch-to-tab.
                 mUrlOpenListener.onUrlOpen(url, EnumSet.of(OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB));
 
-                markAsRead(id);
+                markAsRead(context, id);
             }
         });
 
         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(ReadingListItems.URL));
@@ -105,19 +110,17 @@ public class ReadingListPanel extends Ho
                 info.isUnread = cursor.getInt(cursor.getColumnIndexOrThrow(ReadingListItems.IS_UNREAD)) == 1;
                 info.itemType = RemoveItemType.READING_LIST;
                 return info;
             }
         });
         registerForContextMenu(mList);
     }
 
-    private void markAsRead(long id) {
-        final Context context = getActivity();
-
+    private void markAsRead(final Context context, final long id) {
         GeckoProfile.get(context).getDB().getReadingListAccessor().markAsRead(
             context.getContentResolver(),
             id
         );
     }
 
     @Override
     public void onDestroyView() {