Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
        ...
}
like image 570
adhirajsinghchauhan Avatar asked Aug 15 '19 10:08

adhirajsinghchauhan


1 Answers

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.

like image 181
S.R Avatar answered Oct 05 '22 18:10

S.R