Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2019)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetItemDecoration.java

Issue 1961323003: [NTP Snippets] Fix crash on snippet dismiss (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetItemDecoration.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetItemDecoration.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetItemDecoration.java
index da0719b053036e8a39bf6d07e491c9fce4132696..696036fcc2ce490dbe90aca1700db33194e3007d 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetItemDecoration.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetItemDecoration.java
@@ -62,9 +62,13 @@ public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
*/
private boolean shouldPlaceSeparator(View view, RecyclerView parent) {
int childPos = parent.getChildAdapterPosition(view);
- Adapter adapter = parent.getAdapter();
+ Adapter<?> adapter = parent.getAdapter();
- if (childPos == adapter.getItemCount() - 1) return false;
+ // childPos can be NO_POSITION if the method is called with a view being removed from the
+ // RecyclerView, for example when dismissing an item.
+ if (childPos == adapter.getItemCount() - 1 || childPos == RecyclerView.NO_POSITION) {
+ return false;
+ }
return adapter.getItemViewType(childPos) == NewTabPageListItem.VIEW_TYPE_SNIPPET
&& adapter.getItemViewType(childPos + 1) == NewTabPageListItem.VIEW_TYPE_SNIPPET;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698