Bug 1315938 - Don't crash if tabs aren't initialised yet r?sebastian
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);