Bug 1315938 - Don't crash if tabs aren't initialised yet r=sebastian, a=gchang
authorAndrzej Hunt <ahunt@mozilla.com>
Tue, 08 Nov 2016 13:07:24 +0100
changeset 439959 36f945043957d096b5085599dc65c3c91866f067
parent 439958 1f41acac2aa680a42c0dc85062a0c0ff70c9b80f
child 439960 06660e22513db840537ff6a9bd8875bdb7a83ffe
push id36143
push userjkingston@mozilla.com
push dateWed, 16 Nov 2016 22:20:38 +0000
reviewerssebastian, gchang
Bug 1315938 - Don't crash if tabs aren't initialised yet r=sebastian, a=gchang getSelectedTab() specifies that it can return null "if we're doing a session restore after a crash and Gecko isn't ready yet". This seems to occasionally be happening, resulting in crashes. (What isn't clear is why this would be happening more regularly in 51, it's possible some completely unrelated changes are either making the rendering of TopSites faster, causing this call to be made earlier, or session restore has simply gotten slower. We have also had a crash spike recently due to library loading issues, which would likely further exacerbate the whole issue.) MozReview-Commit-ID: GLFOoXFrAkj
--- a/mobile/android/base/java/org/mozilla/gecko/home/TwoLinePageRow.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/TwoLinePageRow.java
@@ -196,17 +196,18 @@ public class TwoLinePageRow extends Line
      * Replaces the page URL with "Switch to tab" if there is already a tab open with that URL.
      * Only looks for tabs that are either private or non-private, depending on the current
      * selected tab.
     protected void updateDisplayedUrl() {
-        boolean isPrivate = Tabs.getInstance().getSelectedTab().isPrivate();
+        final Tab selectedTab = Tabs.getInstance().getSelectedTab();
+        final boolean isPrivate = (selectedTab != null) && (selectedTab.isPrivate());
         // We always want to display the underlying page url, however for readermode pages
         // we navigate to the about:reader equivalent, hence we need to use that url when finding
         // existing tabs
         final String navigationUrl = mHasReaderCacheItem ? ReaderModeUtils.getAboutReaderForUrl(mPageUrl) : mPageUrl;
         Tab tab = Tabs.getInstance().getFirstTabForUrl(navigationUrl, isPrivate);