Bug 1317631 - Post: add more cursor position sanity checks r?sebastian draft
authorAndrzej Hunt <ahunt@mozilla.com>
Tue, 15 Nov 2016 17:03:03 +0800
changeset 439459 0154e33fc42158832d08f98c5ac98f122698d7a2
parent 439458 a934adf92ce2379fb76a2da96b804ddecd685952
child 537165 511bd626c9812b6ee860b925f27f7e2d744d401a
push id36002
push userahunt@mozilla.com
push dateWed, 16 Nov 2016 01:39:50 +0000
reviewerssebastian
bugs1317631
milestone53.0a1
Bug 1317631 - Post: add more cursor position sanity checks r?sebastian MozReview-Commit-ID: 7CBnLZDkExI
mobile/android/base/java/org/mozilla/gecko/home/activitystream/StreamRecyclerAdapter.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/StreamRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/StreamRecyclerAdapter.java
@@ -44,18 +44,20 @@ public class StreamRecyclerAdapter exten
     }
 
     @Override
     public int getItemViewType(int position) {
         if (position == 0) {
             return TopPanel.LAYOUT_ID;
         } else if (position == 1) {
             return StreamItem.HighlightsTitle.LAYOUT_ID;
+        } else if (position < getItemCount()) {
+            return HighlightItem.LAYOUT_ID;
         } else {
-            return HighlightItem.LAYOUT_ID;
+            throw new IllegalArgumentException("Requested position does not exist");
         }
     }
 
     @Override
     public StreamItem onCreateViewHolder(ViewGroup parent, final int type) {
         final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
 
         if (type == TopPanel.LAYOUT_ID) {
@@ -65,17 +67,17 @@ public class StreamRecyclerAdapter exten
         } else if (type == HighlightItem.LAYOUT_ID) {
             return new HighlightItem(inflater.inflate(type, parent, false), onUrlOpenListener, onUrlOpenInBackgroundListener);
         } else {
             throw new IllegalStateException("Missing inflation for ViewType " + type);
         }
     }
 
     private int translatePositionToCursor(int position) {
-        if (position == 0) {
+        if (getItemViewType(position) != HighlightItem.LAYOUT_ID) {
             throw new IllegalArgumentException("Requested cursor position for invalid item");
         }
 
         // We have two blank panels at the top, hence remove that to obtain the cursor position
         return position - 2;
     }
 
     @Override