Closed Bug 1377819 Opened 4 years ago Closed 4 years ago

Crash in java.lang.ClassCastException: interface org.mozilla.gecko.tabs.TabsPanel$TabsLayout cannot be cast to android.view.View at java.lang.Class.asSubclass(Class.java)

Categories

(Firefox for Android Graveyard :: General, defect)

Unspecified
Android
defect
Not set
critical

Tracking

(fennec+, firefox55 affected, firefox57 affected)

RESOLVED DUPLICATE of bug 1401779
Tracking Status
fennec + ---
firefox55 --- affected
firefox57 --- affected

People

(Reporter: n.nethercote, Assigned: cnevinchen)

Details

(Keywords: crash)

Crash Data

Attachments

(1 file)

This bug was filed from the Socorro interface and is 
report bp-d8444c14-685f-4e47-88ec-7d9dc0170702.
=============================================================

> java.lang.ClassCastException: interface org.mozilla.gecko.tabs.TabsPanel$TabsLayout cannot be cast to android.view.View
> at java.lang.Class.asSubclass(Class.java:2467)
> at android.view.LayoutInflater.createView(LayoutInflater.java:609)
> at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
> at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
> at android.view.LayoutInflater.rInflate(LayoutInflater.java:860)
> at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
> at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
> at org.mozilla.gecko.tabs.TabsPanel.inflateLayout(TabsPanel.java:138)
> at org.mozilla.gecko.tabs.TabsPanel.<init>(TabsPanel.java:133)
> at java.lang.reflect.Constructor.newInstance0(Native Method)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
> at android.view.LayoutInflater.createView(LayoutInflater.java:645)
> at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
> at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
> at android.view.ViewStub.inflateViewNoAdd(ViewStub.java:269)
> at android.view.ViewStub.inflate(ViewStub.java:302)
> at org.mozilla.gecko.BrowserApp.ensureTabsPanelExists(BrowserApp.java:2266)
> at org.mozilla.gecko.BrowserApp.handleMessage(BrowserApp.java:1809)
> at org.mozilla.gecko.EventDispatcher$2.run(EventDispatcher.java:337)
> at android.os.Handler.handleCallback(Handler.java:769)
> at android.os.Handler.dispatchMessage(Handler.java:98)
> at android.os.Looper.loop(Looper.java:164)
> at android.app.ActivityThread.main(ActivityThread.java:6535)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

jchen, any ideas?
Flags: needinfo?(nchen)
All of these crashes are on API 25 or 26. Seems like `BrowserApp.onCreateView` isn't properly called in some cases, and as a result Android is unable to inflate "org.mozilla.gecko.tabs.TabsPanel$TabsLayout" from the layout.
Flags: needinfo?(nchen) → needinfo?(max)
Flags: needinfo?(max) → needinfo?(cnevinchen)
Assignee: nobody → cnevinchen
Flags: needinfo?(cnevinchen)
Comment on attachment 8885136 [details]
Bug 1377819 - Use ViewStub and give a default implementation of TabsLayout instead of puting an interface in layout xml.

https://reviewboard.mozilla.org/r/155982/#review161500

::: mobile/android/base/java/org/mozilla/gecko/BrowserApp.java:2269
(Diff revision 1)
>          if (mTabsPanel != null) {
>              return false;
>          }
>  
>          ViewStub tabsPanelStub = (ViewStub) findViewById(R.id.tabs_panel);
> -        mTabsPanel = (TabsPanel) tabsPanelStub.inflate();
> +        final View inflate = tabsPanelStub != null ? tabsPanelStub.inflate() : null;

Not sure this would work. The exception happens inside the `ViewStub.inflate` call. If `tabsPanelStub` is null, we would be getting a `NullPointerException` here.
Attachment #8885136 - Flags: review?(nchen) → review-
Comment on attachment 8885136 [details]
Bug 1377819 - Use ViewStub and give a default implementation of TabsLayout instead of puting an interface in layout xml.

https://reviewboard.mozilla.org/r/155982/#review162096

::: mobile/android/base/java/org/mozilla/gecko/BrowserApp.java:2229
(Diff revision 2)
>          if (mTabsPanel != null) {
>              return false;
>          }
>  
>          ViewStub tabsPanelStub = (ViewStub) findViewById(R.id.tabs_panel);
> -        mTabsPanel = (TabsPanel) tabsPanelStub.inflate();
> +        final View inflate = tabsPanelStub.inflate();

So the crash is happening inside `tabsPanelStub.inflate()`, which means we will still crash with this patch.
Attachment #8885136 - Flags: review?(nchen) → review-
Sorry I was wrong. I thought it crashed because the inflation is successful, but with the wrong type. Now I know it's because the inflation failed here[1]. 

I don't know how below works.
<view class="org.mozilla.gecko.tabs.TabsPanel$TabsLayout" 

maliu pointed me today that this causes view inflation fail due to it wants to cast TabsLayout interface to View class.

I wonder why this works perfectly without trouble in the past?

I can change the implementation from <view class="..."/> to dynamic inflation. But still don't know how to reproduce the bug.:(
Maybe Max has more idea how to fix this :)


[1]https://searchfox.org/mozilla-central/rev/cbd628b085ac809bf5a536109e6288aa91cbdff0/mobile/android/app/src/main/res/layout/tabs_panel_default.xml#83
Flags: needinfo?(max)
Android is supposed to call `BrowserApp.onCreateView` [1] when creating this view, but I guess that does not happen in some cases?

http://searchfox.org/mozilla-central/rev/cbd628b085ac809bf5a536109e6288aa91cbdff0/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java#352
Comment on attachment 8885136 [details]
Bug 1377819 - Use ViewStub and give a default implementation of TabsLayout instead of puting an interface in layout xml.

Yep, we decide at runtime which view class to instantiate.
Attachment #8885136 - Flags: review?(s.kaspari) → review-
All I can think of is AppCompat related issue. Un-assign myself so other people can fix it.
Assignee: cnevinchen → nobody
Comment on attachment 8885136 [details]
Bug 1377819 - Use ViewStub and give a default implementation of TabsLayout instead of puting an interface in layout xml.

I'll let Sebastian look at it.
Attachment #8885136 - Flags: review?(nchen)
Hi Ioana
Thanks for looking at this. Do you have any STR for this?
Flags: needinfo?(ioana.chiorean)
Attachment #8885136 - Flags: review?(max)
Assignee: nobody → cnevinchen
tracking-fennec: ? → +
I just hit this immediately after opening Firefox after not using it for quite a while (a few hours probably). Can't consistently reproduce though.
Just looking at the crash stat

Latest crash for api 26 is here[1].

at org.mozilla.gecko.tabs.TabsPanel.inflateLayout(TabsPanel.java:138)
	at org.mozilla.gecko.tabs.TabsPanel.refresh(TabsPanel.java:420)
	at org.mozilla.gecko.BrowserApp.refreshChrome(BrowserApp.java:1765)
	at org.mozilla.gecko.GeckoApp.onConfigurationChanged(GeckoApp.java:2544)

[1] http://searchfox.org/mozilla-central/rev/6769c4c331c85870ac3e7bf61968db98c16e4777/mobile/android/base/java/org/mozilla/gecko/tabs/TabsPanel.java#441

Since different context may be a problem, I'll try to reproduce it when I get to the office tomorrow.
(In reply to Nevin Chen [:nechen] from comment #10)

I still can't reproduce this on Android O (API 26) Pixel.

mFactory and mFactory2 is set here
https://android.googlesource.com/platform/frameworks/support/+/d25af35/v7/appcompat/src/android/support/v7/app/AppCompatDelegateImplV7.java#817

mPrivateFactory is set here
http://androidxref.com/7.1.1_r6/xref/frameworks/base/core/java/android/app/Activity.java#6623

I can't find a situation that'll make any of them null.
I just hit this crash on Nightly:
https://crash-stats.mozilla.com/report/index/594daf02-f1e8-474d-bbbd-ca12d0170918

I was talking to the Google Assistant at the time, in case that's relevant.
I did an analysis in bug 1401733 for a similar crash (onCreateView is not called). I discovered:

(In reply to Michael Comella (:mcomella) from bug 1401733 comment #3)
> 1) `onCreateView(String, Context, AttributeSet)` is apparently for pre-HC
> devices: "This implementation does nothing and is for pre-HONEYCOMB apps.
> Newer apps should use onCreateView(View, String, Context, AttributeSet)."

I also noticed the layout inflation source has changed from Nougat to O (bug 1401733 comment 7) so it's entirely possible that a bug was introduced in the old version of `onCreateView`, given that it probably gets less testing than the new version. I landed use of the new onCreateView in 57 (bug 1401779) and I'm hoping it'll fix these `onCreateView` issues (that being said, I landed a work-around in bug 1401733 for safety).
I think bug 1401779 fixed this problem. Since there's no crash after it lands.
Suggest to close this bug.
(In reply to Nevin Chen [:nechen] from comment #20)
> I think bug 1401779 fixed this problem. Since there's no crash after it
> lands.
> Suggest to close this bug.

I agree: duping.

To elaborate, onCreateView landed on 9/21. There have been 3 crashes in 57a since 9/22 (probably old build IDs) and it's never crashed in 57b or 58a [1].

[1]: https://crash-stats.mozilla.com/signature/?signature=java.lang.ClassCastException%3A%20interface%20org.mozilla.gecko.tabs.TabsPanel%24TabsLayout%20cannot%20be%20cast%20to%20android.view.View%20at%20java.lang.Class.asSubclass%28Class.java%29&date=%3E%3D2017-09-22T16%3A33%3A00.000Z&date=%3C2017-10-23T16%3A33%3A00.000Z#aggregations
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 1401779
Attachment #8885136 - Flags: review?(s.kaspari)
Attachment #8885136 - Flags: review?(max)
(In reply to Nevin Chen [:nechen] from comment #14)
> Hi Ioana
> Thanks for looking at this. Do you have any STR for this?

Not been able to reproduce it anymore. But I still see it happens a lot from the crash stats.
Flags: needinfo?(ioana.chiorean)
Flags: needinfo?(max)
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.