Status Update
Comments
jb...@google.com <jb...@google.com> #2
Oh I forgot to mention that I thought it might be connected to this issue:
kr...@gmail.com <kr...@gmail.com> #3
Please provide a minimal sample project along with the minimal steps to recreate the issue in the project.
kr...@gmail.com <kr...@gmail.com> #4
Sorry for the delay. I got a working example here:
I poked into it a little bit and it seems to be connected to
Steps to reproduce:
- Navigate from Second Fragment to Child nav graph (with non-nullable parameters).
- Navigate to Third fragment using SafeArgs and the app crashes.
Crash log:
Process: cz.dels.issues, PID: 1743
java.lang.NullPointerException: null cannot be cast to non-null type kotlin.Long
at androidx.navigation.NavType$Companion$LongType$1.get(NavType.kt:352)
at androidx.navigation.NavType$Companion$LongType$1.get(NavType.kt:342)
at androidx.navigation.NavArgument.verify(NavArgument.kt:76)
at androidx.navigation.NavDestination.addInDefaultArgs(NavDestination.kt:502)
at androidx.navigation.NavController.addEntryToBackStack(NavController.kt:1865)
at androidx.navigation.NavController.addEntryToBackStack$default(NavController.kt:1813)
at androidx.navigation.NavController$navigate$4.invoke(NavController.kt:1721)
at androidx.navigation.NavController$navigate$4.invoke(NavController.kt:1719)
at androidx.navigation.NavController$NavControllerNavigatorState.push(NavController.kt:287)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.kt:246)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.kt:162)
at androidx.navigation.NavController.navigateInternal(NavController.kt:260)
at androidx.navigation.NavController.navigate(NavController.kt:1719)
at androidx.navigation.NavController.navigate(NavController.kt:1545)
at androidx.navigation.NavController.navigate(NavController.kt:1472)
at androidx.navigation.NavController.navigate(NavController.kt:1930)
at cz.dels.issues.SecondFragment.onViewCreated$lambda-0(SecondFragment.kt:38)
at cz.dels.issues.SecondFragment.$r8$lambda$XDYnOS_cYrafiNQ5rcCu1WCn0IE(Unknown Source:0)
at cz.dels.issues.SecondFragment$$ExternalSyntheticLambda0.onClick(Unknown Source:2)
Note: If in step 2 SaveArgs is not used then navigation works correctly. More information is here:
kr...@gmail.com <kr...@gmail.com> #5
Ups a typo: Navigate from Second First Fragment to Child nav graph (with non-nullable parameters).
Note: sorry for the spam but I am not able to edit my own comment.
kr...@gmail.com <kr...@gmail.com> #6
This has been fixed and will be available in navigation 2.6.0-alpha08
jb...@google.com <jb...@google.com> #7
Branch: androidx-main
commit 6b358154b794a0456b089ac8e548bfb830dd6c22
Author: Clara Fok <clarafok@google.com>
Date: Tue Mar 14 17:56:12 2023
Fix missing non-nullable arg when rebuilding hierarchy
When navigating with NavDirections, args is populated with an empty bundle. This causes issue when we rebuild parent hierarchy while adding a new entry to NavBackStack. If the Entry being rebuilt contains a non-nullalbe arg, i.e. Long, this empty bundle will cause an exception.
Test: ./gradlew navigation:navigation-runtime:cC
Bug: 249988437
Change-Id: I5c8ce739ad9a3428c8a8de13eae391bfff0db5df
M navigation/navigation-runtime/src/androidTest/java/androidx/navigation/NavControllerTest.kt
M navigation/navigation-runtime/src/main/java/androidx/navigation/NavController.kt
kr...@gmail.com <kr...@gmail.com> #8
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-runtime:2.6.0-alpha08
jb...@google.com <jb...@google.com>
ap...@google.com <ap...@google.com> #9
Branch: androidx-main
commit fec95ed9a91ef4058d5265e2f7ba1240db4f651d
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Aug 29 19:09:30 2022
Fix double nested graph popUpTo behavior
Navigation should always maintain the path to current destination as
part of that back stack. Under normal circumstances following the
recommended behavior this is true.
It is possible to create a scenario where this is not the case.
Given the following graph:
A
|
B
/ \
C D
|
E
|
F
Where C is the start destination of graph B, if you navigate to D while
popping C off the back stack (which is not recommended), Navigation
fails to build the proper hierarchy for D resulting in B being popped
incorrectly and causing an IllegalStateException.
We should ensure that Navigation properly handles nested destinations.
RelNote: "Fixed `IllegalStateException` caused by navigating to a double
nested graph that shares a parent with a new popped start destination."
Test: added testLifecycleDoubleNestedGraph
Bug: 243778589
Change-Id: I9f7cb2445e6021c6ab4cb81d62612411249c1257
M navigation/navigation-runtime/src/main/java/androidx/navigation/NavController.kt
M navigation/navigation-runtime/src/androidTest/java/androidx/navigation/NavBackStackEntryLifecycleTest.kt
jb...@google.com <jb...@google.com> #10
I was able to find that is this particular case Navigation is indeed losing the proper back stack.
Again, this is not something we recommend doing when using Navigation as the startDestination is meant to be the entry and exit point of a particular graph. If this is something that the app needs, it might be a sign that the architecture needs to be re-evaluated.
This has been fixed and will be a part of the Navigation 2.5.2
and 2.6.0-alpha01
releases.
kr...@gmail.com <kr...@gmail.com> #11
Thank you! Have a nice day :)
na...@google.com <na...@google.com> #12
This bug was linked in a change in the following release(s):
androidx.navigation:navigation-runtime:2.6.0-alpha01
androidx.navigation:navigation-runtime:2.5.2
Description
Version used: every version since 2.4.0 (latest tested version is 2.5.1)
Latest version working correctly: 2.3.5
Devices/Android versions reproduced on: Emulator API 30, Oppo CPH2251 API 30, Samsung Galaxy S21 API 31
Repro steps:
1. Define the following 3 graphs (sample project is attached to this bug report):
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="
xmlns:app="
xmlns:tools="
android:id="@+id/level_0_graph"
app:startDestination="@id/level_0_fragment">
<fragment
android:id="@+id/level_0_fragment"
android:name="com.example.nestedpopupto.Level0Fragment"
tools:layout="@layout/fragment_level_0">
<action
android:id="@+id/to_level_1"
app:popUpTo="@id/level_0_graph"
app:destination="@id/level_1" />
</fragment>
<navigation
android:id="@+id/level_1"
app:startDestination="@id/level_1_graph">
<include app:graph="@navigation/level_1_graph" />
</navigation>
</navigation>
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="
xmlns:app="
xmlns:tools="
android:id="@+id/level_1_graph"
app:startDestination="@id/level_1_fragment">
<fragment
android:id="@+id/level_1_fragment"
android:name="com.example.nestedpopupto.Level1Fragment"
tools:layout="@layout/fragment_level_1">
<action
android:id="@+id/to_level_2"
app:popUpTo="@id/level_1_graph"
app:destination="@id/level_2" />
</fragment>
<navigation
android:id="@+id/level_2"
app:startDestination="@id/level_2_graph">
<include app:graph="@navigation/level_2_graph" />
</navigation>
</navigation>
<navigation xmlns:android="
xmlns:app="
xmlns:tools="
android:id="@+id/level_2_graph"
app:startDestination="@id/level_2_fragment">
<fragment
android:id="@+id/level_2_fragment"
android:name="com.example.nestedpopupto.Level2Fragment"
tools:layout="@layout/fragment_level_2">
</fragment>
</navigation>
2. Use "to_level_1" to navigate to nested graph.
3. Use "to_level_2" action.
Result:
The action "to_level_2" will fail with the following stacktrace:
java.lang.IllegalArgumentException: No destination with ID 2131230965 is on the NavController's back stack. The current destination is Destination(com.example.nestedpopupto:id/level_2_fragment) class=com.example.nestedpopupto.Level2Fragment
at androidx.navigation.NavController.getBackStackEntry(NavController.kt:2209)
at androidx.navigation.NavController.addEntryToBackStack(NavController.kt:1918)
at androidx.navigation.NavController.addEntryToBackStack$default(NavController.kt:1813)
at androidx.navigation.NavController$navigate$4.invoke(NavController.kt:1721)
at androidx.navigation.NavController$navigate$4.invoke(NavController.kt:1719)
at androidx.navigation.NavController$NavControllerNavigatorState.push(NavController.kt:287)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.kt:246)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.kt:162)
at androidx.navigation.NavGraphNavigator.navigate(NavGraphNavigator.kt:83)
at androidx.navigation.NavGraphNavigator.navigate(NavGraphNavigator.kt:49)
at androidx.navigation.NavGraphNavigator.navigate(NavGraphNavigator.kt:83)
at androidx.navigation.NavGraphNavigator.navigate(NavGraphNavigator.kt:49)
at androidx.navigation.NavController.navigateInternal(NavController.kt:260)
at androidx.navigation.NavController.navigate(NavController.kt:1719)
at androidx.navigation.NavController.navigate(NavController.kt:1545)
at androidx.navigation.NavController.navigate(NavController.kt:1472)
at androidx.navigation.NavController.navigate(NavController.kt:1930)
at com.example.nestedpopupto.Level1Fragment.onViewCreated$lambda-0(Level1Fragment.kt:13)
The crash will NOT occur if any of the following is applied:
- the "to_level_2" action does not use "popUpTo"
- the "level_2_graph" is not wrapped with the <navigation>.
As one can see the "to_level_1" action is identical to the "to_level_2" action and is defined in an identical graph and it works correctly. It seems that the bug occurs only when navigation is performed in the graph that is included in an other graph.
In the end I would like to remind that everything works correctly with version 2.3.5 of the androidx.navigation.