google / accompanist

A collection of extension libraries for Jetpack Compose
https://google.github.io/accompanist
Apache License 2.0
7.31k stars 592 forks source link

[Navigation Material] Crash in BottomSheetNavigator when user goes back #1750

Closed filip-misadin closed 4 months ago

filip-misadin commented 5 months ago

We have some crashes that, as far as I can see when looking at the logs, happen when a user goes back on any of our bottom modals. The version of Navigation Material library we currently use is 0.32.0. I looked into the newest version (0.34.0) and by looking into the code I think we would have the same crashes with that version too, even though the code changed to some degree.

I tried a lot of ways to reproduce this crash, but I didn't succeed in reproducing it. That's why I can't know for sure why this happens and what is the edge case that keeps popping up. This crash happens to around 1% of our users, so it's not that uncommon.

This is the crash stack trace:

Fatal Exception: java.lang.NullPointerException
com.google.accompanist.navigation.material.BottomSheetNavigator$sheetContent$1$2.invoke (BottomSheetNavigator.kt:224)
com.google.accompanist.navigation.material.BottomSheetNavigator$sheetContent$1$2.invoke (BottomSheetNavigator.kt:223)
androidx.activity.compose.BackHandlerKt$BackHandler$backCallback$1$1.handleOnBackPressed (BackHandler.kt:89)
androidx.activity.OnBackPressedDispatcher.onBackPressed (OnBackPressedDispatcher.kt:276)
androidx.activity.ComponentActivity.onBackPressed (ComponentActivity.java:678)
android.app.Activity.onKeyUp (Activity.java:3976)
android.view.KeyEvent.dispatch (KeyEvent.java:2925)
android.app.Activity.dispatchKeyEvent (Activity.java:4329)
androidx.core.app.ComponentActivity.superDispatchKeyEvent (ComponentActivity.java:120)
androidx.core.view.KeyEventDispatcher.dispatchKeyEvent (KeyEventDispatcher.java:85)
androidx.core.app.ComponentActivity.dispatchKeyEvent (ComponentActivity.java:138)
com.android.internal.policy.DecorView.dispatchKeyEvent (DecorView.java:420)
android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent (ViewRootImpl.java:6735)
android.view.ViewRootImpl$ViewPostImeInputStage.onProcess (ViewRootImpl.java:6601)
android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:6059)
android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:6116)
android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:6082)
android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:6247)
android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:6090)
android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:6304)
android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:6063)
android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:6116)
android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:6082)
android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:6090)
android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:6063)
android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:6116)
android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:6082)
android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:6280)
android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent (ViewRootImpl.java:6460)
android.view.inputmethod.InputMethodManager$PendingEvent.run (InputMethodManager.java:3708)
android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback (InputMethodManager.java:3217)
android.view.inputmethod.InputMethodManager.finishedInputEvent (InputMethodManager.java:3208)
android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished (InputMethodManager.java:3685)
android.view.InputEventSender.dispatchInputEventFinished (InputEventSender.java:154)
android.os.MessageQueue.nativePollOnce (MessageQueue.java)
android.os.MessageQueue.next (MessageQueue.java:342)
android.os.Looper.loopOnce (Looper.java:182)
android.os.Looper.loop (Looper.java:357)
android.app.ActivityThread.main (ActivityThread.java:8088)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:548)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:957)

As can be seen in the stack trace above, the crash happens when executing these lines:

BackHandler(retainedEntry != null) {
    state.popWithTransition(retainedEntry!!, false)
}

This crash doesn't make sense to me, since state.popWithTransition(retainedEntry!!, false) shouldn't execute if retainedEntry is null. Can someone please look into this and check if it can be fixed by adding an additional check inside of BackHandler?

LluisFelip commented 4 months ago

Attempting to fix this here 🙏🏼

ianhanniballake commented 4 months ago

With the release of Compose Material 1.7.0-alpha04, the Material team has added a new artifact: androidx.compose.material:material-navigation, which fully replaces Accompanist Navigation Material.

As such, we are closing all issues here on Accompanist and will be fully deprecating Accompanist Navigation Material in an upcoming release.

A number of issues were fixed as part of the migration, but if you're still seeing an issue, please file an issue with a sample project that reproduces your issue and the Material team will take a look.

rekaszeru commented 3 months ago

Since the issue is present in Compose Material 1.7.0-alpha04 too, can it be moved over?