Bug 1317631 - Post: add more cursor position sanity checks r?sebastian
MozReview-Commit-ID: 7CBnLZDkExI
--- 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