Bug 1557661 java.lang.NullPointerException: at org.mozilla.gecko.home.TabMenuStripLayout.onPageSelected(TabMenuStripLayout.java) r=VladBaicu
authorAndrei Lazar <andrei.a.lazar@softvision.ro>
Fri, 21 Jun 2019 12:22:20 +0000
changeset 479823 1e2272faa004fdacb4cff7db7055e633736c4ae3
parent 479822 db9fe7cbc88c3d93f270212e725a36dd7d4dbb21
child 479824 d7559e411fc5cf36ff676dc53e45d6d3836f6924
push id88293
push usercbrindusan@mozilla.com
push dateFri, 21 Jun 2019 12:48:03 +0000
treeherderautoland@1e2272faa004 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersVladBaicu
bugs1557661
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1557661 java.lang.NullPointerException: at org.mozilla.gecko.home.TabMenuStripLayout.onPageSelected(TabMenuStripLayout.java) r=VladBaicu Fixed an issue where we were trying to set some attributes on a null object due to the fact that the view had not finished rendering. Differential Revision: https://phabricator.services.mozilla.com/D35515
mobile/android/base/java/org/mozilla/gecko/home/TabMenuStripLayout.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/TabMenuStripLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/TabMenuStripLayout.java
@@ -118,30 +118,30 @@ class TabMenuStripLayout extends ThemedL
         }
 
         addView(button);
         button.setOnClickListener(new ViewClickListener(getChildCount() - 1));
         button.setOnFocusChangeListener(this);
     }
 
     void onPageSelected(final int position) {
-        if (selectedView != null) {
-            selectedView.setTextColor(inactiveTextColor);
-        }
-
-        selectedView = (TextView) getChildAt(position);
-        selectedView.setTextColor(activeTextColor);
-
         // Callback to measure and draw the strip after the view is visible.
-        ViewTreeObserver vto = selectedView.getViewTreeObserver();
+        ViewTreeObserver vto = getViewTreeObserver();
         if (vto.isAlive()) {
             vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                 @Override
                 public void onGlobalLayout() {
-                    selectedView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
+                    // let's ensure that we are calling this only once
+                    vto.removeOnGlobalLayoutListener(this);
+                    if (selectedView != null) {
+                        selectedView.setTextColor(inactiveTextColor);
+                    }
+
+                    selectedView = (TextView) getChildAt(position);
+                    selectedView.setTextColor(activeTextColor);
 
                     if (strip != null) {
                         boolean isLayoutRtl = ViewCompat.getLayoutDirection(selectedView) == ViewCompat.LAYOUT_DIRECTION_RTL;
                         final int startPaddingOffset;
                         final int endPaddingOffset;
                         if (position != 0) {
                             startPaddingOffset = 0;
                             endPaddingOffset = 0;