From a313b897b47e66d253c17c84159b8bcbefa0942f Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Tue, 9 Jul 2013 15:18:56 -0700 Subject: [PATCH] Bug 839854 - Protect against getChildAt returning a null view during a rotation. r=mfinkle --- mobile/android/base/widget/TopSitesView.java | 33 +++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/mobile/android/base/widget/TopSitesView.java b/mobile/android/base/widget/TopSitesView.java index f1424e7b7c7..b322e88e163 100644 --- a/mobile/android/base/widget/TopSitesView.java +++ b/mobile/android/base/widget/TopSitesView.java @@ -124,6 +124,11 @@ public class TopSitesView extends GridView { // We can assume that the adapter count and view count are the same in this case because our grid view // force all items to be visible all the time View view = getChildAt(info.position); + // The grid view might get temporarily out of sync with the + // adapter refreshes (e.g. on device rotation) + if (view == null) { + return; + } TopSitesViewHolder holder = (TopSitesViewHolder) view.getTag(); if (TextUtils.isEmpty(holder.getUrl())) { menu.findItem(R.id.abouthome_open_new_tab).setVisible(false); @@ -288,8 +293,9 @@ public class TopSitesView extends GridView { // The grid view might get temporarily out of sync with the // adapter refreshes (e.g. on device rotation) - if (view == null) + if (view == null) { continue; + } TopSitesViewHolder holder = (TopSitesViewHolder)view.getTag(); final String url = holder.getUrl(); @@ -510,6 +516,11 @@ public class TopSitesView extends GridView { private void clearThumbnailsWithUrl(final String url) { for (int i = 0; i < mTopSitesAdapter.getCount(); i++) { final View view = getChildAt(i); + // The grid view might get temporarily out of sync with the + // adapter refreshes (e.g. on device rotation) + if (view == null) { + continue; + } final TopSitesViewHolder holder = (TopSitesViewHolder) view.getTag(); if (holder.getUrl().equals(url)) { @@ -550,6 +561,11 @@ public class TopSitesView extends GridView { final int position = info.position; final View v = getChildAt(position); + // The grid view might get temporarily out of sync with the + // adapter refreshes (e.g. on device rotation) + if (v == null) { + return; + } final TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag(); final String url = holder.getUrl(); // Quickly update the view so that there isn't as much lag between the request and response @@ -568,6 +584,11 @@ public class TopSitesView extends GridView { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; final int position = info.position; View v = getChildAt(position); + // The grid view might get temporarily out of sync with the + // adapter refreshes (e.g. on device rotation) + if (v == null) { + return; + } final TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag(); holder.setPinned(true); @@ -599,6 +620,11 @@ public class TopSitesView extends GridView { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; int position = info.position; View v = getChildAt(position); + // The grid view might get temporarily out of sync with the + // adapter refreshes (e.g. on device rotation) + if (v == null) { + return; + } TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag(); // Decode "user-entered" URLs before showing them to the user to edit. @@ -621,6 +647,11 @@ public class TopSitesView extends GridView { return; final View v = getChildAt(position); + // The grid view might get temporarily out of sync with the + // adapter refreshes (e.g. on device rotation) + if (v == null) { + return; + } final TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag(); String title = data.getStringExtra(AwesomeBar.TITLE_KEY);