Fatal Exception: java.lang.StackOverflowError stack size 8MB android.view.View.hasIdentityMatrix
Asked Answered
H

1

11

This is a very rare bug that's happening in my app. Users open SettingsActivity and notice the app has frozen, after which it crashes (5 - 10s later?).
I have no idea how to proceed, I've tried debugging but can't reproduce the issue. I've seen other similar questions, but their stack traces had application methods that were the cause of an infinite loop. Here, there is no application code that's responsible (at least, the stack trace doesn't reveal anything)

Stack trace shows only a bunch of Android core library methods (View, ViewGroup, RecyclerView), and has something to do with accessibility.

This perplexes me, since:

  • I'm not using RecyclerView anywhere in SettingsActivity, SettingsFragment, or their layouts
  • The only place I am using it, works perfectly, as proven by a few screenshots and videos users have sent me
  • I haven't overriden any accessibility callbacks in any of my activities
  • I added breakpoints in every method the stack trace shows, but those breakpoints were never hit. In any activity. (wtf)

Considering the stack trace doesn't show any custom classes/methods part of my codebase, how am I supposed to proceed? Is this a known bug in androidx.recyclerview, for example?

I know for sure that the app crashes in SettingsActivity, since Firebase tracks activities in Crashlytics for you. (the flow was MainActivity -> [AnyActivity] -> SettingsActivity -> <freeze> -> <crash>).

Our entire team can't reproduce this issue (using the same exact Play Store version), but it seems like there are around 100 users that are experiencing this crash. All devices that show these fatal exceptions are being used by our team to debug, to no avail.

Stack trace

Fatal Exception: java.lang.StackOverflowError: stack size 8MB
       at android.view.View.hasIdentityMatrix (View.java:14669)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6138)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6121)
       at android.view.View.getGlobalVisibleRect (View.java:16064)
       at android.view.View.isVisibleToUser (View.java:9065)
       at android.view.View.isVisibleToUser (View.java:9023)
       at android.view.View.onInitializeAccessibilityNodeInfoInternal (View.java:8814)
       at android.view.ViewGroup.onInitializeAccessibilityNodeInfoInternal (ViewGroup.java:3642)
       at android.view.View$AccessibilityDelegate.onInitializeAccessibilityNodeInfo (View.java:27387)
       at androidx.core.view.AccessibilityDelegateCompat.onInitializeAccessibilityNodeInfo (AccessibilityDelegateCompat.java:275)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:124)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.core.view.AccessibilityDelegateCompat$AccessibilityDelegateAdapter.onInitializeAccessibilityNodeInfo (AccessibilityDelegateCompat.java:86)
       at android.view.View.onInitializeAccessibilityNodeInfo (View.java:7776)
       at android.view.View.createAccessibilityNodeInfoInternal (View.java:7737)
       at android.view.View$AccessibilityDelegate.createAccessibilityNodeInfo (View.java:27485)
       at android.view.View.createAccessibilityNodeInfo (View.java:7720)
       at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode (AccessibilityInteractionController.java:1147)
       at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos (AccessibilityInteractionController.java:972)
       at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread (AccessibilityInteractionController.java:336)
       at android.view.AccessibilityInteractionController.access$400 (AccessibilityInteractionController.java:67)
       at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage (AccessibilityInteractionController.java:1324)
       at android.os.Handler.dispatchMessage (Handler.java:106)
       at android.os.Looper.loop (Looper.java:193)
       at android.app.ActivityThread.main (ActivityThread.java:6898)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:537)
       at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)

SettingsActivity

public class SettingsActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        settingsFragment = new SettingsFragment();

        getSupportFragmentManager().beginTransaction()
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                .replace(R.id.settings_container, settingsFragment, "Settings")
                .commit();

        ... // also contains code to init an IAP helper,
            // but that doesn't use RecyclerView either (obviously)

}

SettingsFragment

public class SettingsFragment extends PreferenceFragmentCompat implements OnPreferenceChangeListener {
    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        ...
        addPreferencesFromResource(R.xml.preferences);
        ...
}
Haas answered 15/8, 2019 at 10:4 Comment(0)
H
17

Update 3

It's fixed. now you can use the latest version of recyclerview:

implementation 'androidx.recyclerview:recyclerview:1.1.0'

Update 2

This known bug was fixed in earlier versions of recyclerview (beta03, beta04) , but now it is back in beta05.

So use :

implementation 'androidx.recyclerview:recyclerview:1.1.0-beta04'

until this issue is resolved in next versions.


Update 1

This bug is fixed in recyclerview:1.1.0-beta03, So use:

implementation 'androidx.recyclerview:recyclerview:1.1.0-beta03'

Old answer

If you are using recyclerview:1.1.0-beta02, downgrade it to beta01. beta02 has this bug that you and I have faced. So use this version of Recyclerview:

 implementation 'androidx.recyclerview:recyclerview:1.1.0-beta01'
 //implementation 'androidx.preference:preference:1.1.0-rc01'

until this issue is resolved in next versions.


It's caused by private codes inside Recyclerview class. I'm not sure maybe the crash lays inside this method of Recyclerview :

// called by accessibility delegate
void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfoCompat info) {
    onInitializeAccessibilityNodeInfo(mRecyclerView.mRecycler, mRecyclerView.mState, info);
}

PreferenceFragmentCompat is using this method through nested calls. so we'll face this exception by extending PreferenceFragmentCompat (for me I should also setOnPreferenceChangeListener on preference object and invoke this callback to stackoverflow occur). but as I mentioned this issue doesn't exist in recyclerview:1.1.0-beta01.

Homans answered 15/8, 2019 at 10:19 Comment(18)
I'll try it out, see if this gets the issue fixed. Could you point me to the code which causes this bug, if you know it?Haas
How about filing a bug to Google?Radiotelephony
It looks like this issue was fixed in recyclerview:1.1.0-beta03Hungerford
It's back in 1.1.0-beta05.Poplin
I had to revert back to 1.1.0-beta04 to avoid this problem.Cornellcornelle
For those who don't even have recyclerview in their dependencies, I found that androidx.viewpager2:viewpager2 needs to use 1.0.0-beta04, not 1.0.0-beta05, for now.Cindycine
Update: I had reverted back to 1.1.0-beta04 and it seemed fine (I thought) but it seems to crash on my physical device (Running API25), but doesn't on an emulator running the same API.Cornellcornelle
Another update: So, I also have the library com.google.android.material:material:1.1.0-beta01 If I update that one to: com.google.android.material:material:1.2.0-alpha01 I also have the crash issue (no matter what version of the recyclerview library I'm using). Even though I current have androidx.recyclerview:recyclerview:1.1.0-beta04.Cornellcornelle
So in a nutshell, I would recommend using the following libraries until this bug is resolved: recyclerview:1.1.0-beta04 and material:1.1.0-beta01Cornellcornelle
Does this issue exist on androidx.recyclerview:recyclerview:1.1.0-rc01 ?Terrarium
@androiddeveloper It's fixed in 1.1.0-rc01.Homans
@Homans Did you try it? How do you even reproduce it? Is it related to accessibility ?Terrarium
@androiddeveloper Sure, I've tested the new release. thanks for the inform by the way. for me stack overflow will happen when setOnPreferenceChangeListener is called on a preference object. It happens ONLY with 1.1.0-beta02 , and 1.1.0-beta05.Homans
@Homans I see. But how come I didn't notice it? It happens rarely? Or only on some devices and Android versions?Terrarium
@androiddeveloper I haven't tested it on different devices yet, but from the activities and votes I assume it doesn't happen just on some specific device and android version. It happens rarely? Or it happens everytime (beta02,beta05), or it doesn't happen at all(other versions).Homans
@Homans In our case, at least last time I checked, it was only on Android 9, on about 3 different Galaxy devices. Of course it can be a coincidence because it's a bit rare, and maybe if I check it again soon I will see more. But I still don't get how to reproduce it.Terrarium
I was able to consistently get it to crash (just making a selection in my SettingsActivity caused it). I just tried it with the latest updates with rc01 and it appears to be working for me as well.Cornellcornelle
I use androidx.recyclerview:recyclerview:1.1.0, androidx.viewpager2:viewpager2:1.0.0 and com.google.android.material:material:1.1.0-beta01 and same have such crash. But i don't have stable casePrimrosa

© 2022 - 2024 — McMap. All rights reserved.