Bug 1317631 - Post: add more cursor position sanity checks r=sebastian
authorAndrzej Hunt <ahunt@mozilla.com>
Tue, 15 Nov 2016 17:03:03 +0800
changeset 439694 399dea6e9200b57cf8ba98cf6c3490d103973652
parent 439693 c6f5da9786e92fd3add8a460f3a8dc1c87b55277
child 439695 5f5e46d71cbf98eb61db0e5e934fd5ed7efc6109
push id36064
push userrthijssen@mozilla.com
push dateWed, 16 Nov 2016 13:38:27 +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