Repository navigation
[Android] Don't throw an IllegalArgumentException for every page popped from a NavigationPage - #39183
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39183Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39183" |
|
Hey there @@MykhailoDav! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Hey there @MykhailoDav! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
This comment has been minimized.
This comment has been minimized.
|
/azp run |
|
Note 🔍
|
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
8dbc1dc to
6f16080
Compare
This comment has been minimized.
This comment has been minimized.
|
/azp run |
|
Note 🔍
|
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
Tests Failure Analysis
🧪 CI Analysis — click to expand📊 maui-pr
🧪 maui-pr-devicetestsNo failures found. 🧪 maui-pr-uitests
🧭 Follow-up — actions and refreshNext action: Restore complete UI results and variant metadata; inspect the Android crash and Windows screenshot.
|
6f16080 to
7f50eab
Compare
Without the fix, every popped page throws (and catches) an IllegalArgumentException from NavController.GetBackStackEntry (dotnet#31368). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed from a NavigationPage After a pop, ApplyNavigationRequest calls IterateBackStack to find the destinations that left the back stack. IterateBackStack looks up every destination of the NavGraph with NavController.GetBackStackEntry, which throws for each destination that was just popped. The exception was caught, but FirstChanceException handlers and crash reporters still saw it. Remove the popped destinations from the graph as soon as PopBackStack succeeds. These are the same destinations the method removed afterwards. Fixes dotnet#31368 Fixes dotnet#35276 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
|
/azp run |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
Note 🔍
|
7f50eab to
b39a024
Compare
AI Review Summary
🗂️ Review Sessions — click to expand🚦 Gate — Test Before & After FixGate Result: ✅ PASSEDPlatform: ANDROID · Base: inflight/current · Merge base:
🔴 Without fix — 📱 NavigationViewHandlerTests (PoppingPagesDoesntThrowJavaExceptions): FAIL ✅ · 534s(no coded error found; showing last 1200 chars) 🟢 With fix — 📱 NavigationViewHandlerTests (PoppingPagesDoesntThrowJavaExceptions): PASS ✅ · 399s(no coded error found; showing last 1200 chars) 📁 Fix files reverted (1 files)
📋 Pre-Flight — Context & ValidationThe Copilot expert-review task ended before this phase was persisted, usually because the review-stage time budget expired or the CI agent encountered a transient authentication/runtime problem. Earlier completed sections remain valid, but this review is incomplete without this phase. Next step: re-comment 🔬 Code Review — Deep AnalysisThe Copilot expert-review task ended before this phase was persisted, usually because the review-stage time budget expired or the CI agent encountered a transient authentication/runtime problem. Earlier completed sections remain valid, but this review is incomplete without this phase. Next step: re-comment 🛠️ Try-Fix — Analysis & ComparisonThe Copilot expert-review task ended before this phase was persisted, usually because the review-stage time budget expired or the CI agent encountered a transient authentication/runtime problem. Earlier completed sections remain valid, but this review is incomplete without this phase. Next step: re-comment 🏁 Report — Final RecommendationThe Copilot expert-review task ended before this phase was persisted, usually because the review-stage time budget expired or the CI agent encountered a transient authentication/runtime problem. Earlier completed sections remain valid, but this review is incomplete without this phase. Next step: re-comment 📱 UI Tests — ViewBaseTestsDetected UI test categories: ✅ Deep UI tests — 118 passed, 0 failed, 1 skipped across 1 category on platform-pool agent (replaces in-process counts above). 🧪 UI Test Execution Results (deep, platform pool)
🧭 Next Steps — review latest findingsNo alternative fix was selected for this run. Review the session findings and CI results before merging. |
…ed from a NavigationPage (#39183) ### Description of Change On Android, every page popped from a `NavigationPage` throws a Java `IllegalArgumentException`: ``` Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment at androidx.navigation.NavController.getBackStackEntry(...) ``` MAUI catches the exception, so navigation still works. `AppDomain.FirstChanceException` handlers, crash reporters and the debugger output still see it. The same exception was also reported in #26375 and #30238, which were closed without a repro. **Root cause** For a pop, `StackNavigationManager.ApplyNavigationRequest`: 1. calls `NavController.PopBackStack(popToId, false)`; 2. calls `IterateBackStack` to find the destinations that are no longer on the back stack, and removes them from the `NavGraph`. `IterateBackStack` calls `NavController.GetBackStackEntry` for every destination in the graph. For each destination that was just popped, that call throws `IllegalArgumentException`, which `IterateBackStack` catches. **Fix** When `PopBackStack` succeeds, the popped destinations are removed from the graph right away. They are the entries after `popToId` in `fragmentNavDestinations`, the list the method already uses to find `popToId`. `IterateBackStack` then only finds destinations that are on the back stack. The method already removed these same destinations a few lines later, so the resulting graph and back stack don't change. Not changed: `Initialize` runs when a `NavigationPage` handler is created with more than one page. It still calls `IterateBackStack` while only the first page's destination is on the back stack. The bug also reproduces on `net11.0`. There, the default Android Shell handler also navigates through `StackNavigationManager` (`ShellStackNavigationManager`), so Shell back navigation throws the same exceptions too. **Tests** `NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions` (Core.DeviceTests, Android) pops two of three pages. During the pop, it records every `IllegalArgumentException` that reaches `AppDomain.FirstChanceException`. | | Without fix | With fix | |---|---|---| | `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with ID 3 is on the NavController's back stack`, and the same for ID 4 | Passes | These results are from `inflight/current` (262d959) on an API 37 emulator. With the fix: | Suite | Category | Passed | |---|---|---| | Core.DeviceTests | `NavigationPage` | 2/2 | | Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped | | Controls.DeviceTests | `Modal` | 42/44 | | Controls.DeviceTests | `FlyoutPage` | 17/17 | | Controls.DeviceTests | `TabbedPage` | 44/48 | These tests also time out on this emulator without the fix: - `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals, so it doesn't run this code) - `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases On `net11.0` (0b038e7), the test also fails without the fix and passes with it. Controls.DeviceTests `Shell` passed 151/151 there. ### Issues Fixed Fixes #31368 Fixes #35276 ---------
…ed from a NavigationPage (#39183) ### Description of Change On Android, every page popped from a `NavigationPage` throws a Java `IllegalArgumentException`: ``` Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment at androidx.navigation.NavController.getBackStackEntry(...) ``` MAUI catches the exception, so navigation still works. `AppDomain.FirstChanceException` handlers, crash reporters and the debugger output still see it. The same exception was also reported in #26375 and #30238, which were closed without a repro. **Root cause** For a pop, `StackNavigationManager.ApplyNavigationRequest`: 1. calls `NavController.PopBackStack(popToId, false)`; 2. calls `IterateBackStack` to find the destinations that are no longer on the back stack, and removes them from the `NavGraph`. `IterateBackStack` calls `NavController.GetBackStackEntry` for every destination in the graph. For each destination that was just popped, that call throws `IllegalArgumentException`, which `IterateBackStack` catches. **Fix** When `PopBackStack` succeeds, the popped destinations are removed from the graph right away. They are the entries after `popToId` in `fragmentNavDestinations`, the list the method already uses to find `popToId`. `IterateBackStack` then only finds destinations that are on the back stack. The method already removed these same destinations a few lines later, so the resulting graph and back stack don't change. Not changed: `Initialize` runs when a `NavigationPage` handler is created with more than one page. It still calls `IterateBackStack` while only the first page's destination is on the back stack. The bug also reproduces on `net11.0`. There, the default Android Shell handler also navigates through `StackNavigationManager` (`ShellStackNavigationManager`), so Shell back navigation throws the same exceptions too. **Tests** `NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions` (Core.DeviceTests, Android) pops two of three pages. During the pop, it records every `IllegalArgumentException` that reaches `AppDomain.FirstChanceException`. | | Without fix | With fix | |---|---|---| | `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with ID 3 is on the NavController's back stack`, and the same for ID 4 | Passes | These results are from `inflight/current` (262d959) on an API 37 emulator. With the fix: | Suite | Category | Passed | |---|---|---| | Core.DeviceTests | `NavigationPage` | 2/2 | | Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped | | Controls.DeviceTests | `Modal` | 42/44 | | Controls.DeviceTests | `FlyoutPage` | 17/17 | | Controls.DeviceTests | `TabbedPage` | 44/48 | These tests also time out on this emulator without the fix: - `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals, so it doesn't run this code) - `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases On `net11.0` (0b038e7), the test also fails without the fix and passes with it. Controls.DeviceTests `Shell` passed 151/151 there. ### Issues Fixed Fixes #31368 Fixes #35276 ---------
…ed from a NavigationPage (#39183) ### Description of Change On Android, every page popped from a `NavigationPage` throws a Java `IllegalArgumentException`: ``` Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment at androidx.navigation.NavController.getBackStackEntry(...) ``` MAUI catches the exception, so navigation still works. `AppDomain.FirstChanceException` handlers, crash reporters and the debugger output still see it. The same exception was also reported in #26375 and #30238, which were closed without a repro. **Root cause** For a pop, `StackNavigationManager.ApplyNavigationRequest`: 1. calls `NavController.PopBackStack(popToId, false)`; 2. calls `IterateBackStack` to find the destinations that are no longer on the back stack, and removes them from the `NavGraph`. `IterateBackStack` calls `NavController.GetBackStackEntry` for every destination in the graph. For each destination that was just popped, that call throws `IllegalArgumentException`, which `IterateBackStack` catches. **Fix** When `PopBackStack` succeeds, the popped destinations are removed from the graph right away. They are the entries after `popToId` in `fragmentNavDestinations`, the list the method already uses to find `popToId`. `IterateBackStack` then only finds destinations that are on the back stack. The method already removed these same destinations a few lines later, so the resulting graph and back stack don't change. Not changed: `Initialize` runs when a `NavigationPage` handler is created with more than one page. It still calls `IterateBackStack` while only the first page's destination is on the back stack. The bug also reproduces on `net11.0`. There, the default Android Shell handler also navigates through `StackNavigationManager` (`ShellStackNavigationManager`), so Shell back navigation throws the same exceptions too. **Tests** `NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions` (Core.DeviceTests, Android) pops two of three pages. During the pop, it records every `IllegalArgumentException` that reaches `AppDomain.FirstChanceException`. | | Without fix | With fix | |---|---|---| | `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with ID 3 is on the NavController's back stack`, and the same for ID 4 | Passes | These results are from `inflight/current` (262d959) on an API 37 emulator. With the fix: | Suite | Category | Passed | |---|---|---| | Core.DeviceTests | `NavigationPage` | 2/2 | | Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped | | Controls.DeviceTests | `Modal` | 42/44 | | Controls.DeviceTests | `FlyoutPage` | 17/17 | | Controls.DeviceTests | `TabbedPage` | 44/48 | These tests also time out on this emulator without the fix: - `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals, so it doesn't run this code) - `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases On `net11.0` (0b038e7), the test also fails without the fix and passes with it. Controls.DeviceTests `Shell` passed 151/151 there. ### Issues Fixed Fixes #31368 Fixes #35276 ---------
…ed from a NavigationPage (#39183) ### Description of Change On Android, every page popped from a `NavigationPage` throws a Java `IllegalArgumentException`: ``` Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment at androidx.navigation.NavController.getBackStackEntry(...) ``` MAUI catches the exception, so navigation still works. `AppDomain.FirstChanceException` handlers, crash reporters and the debugger output still see it. The same exception was also reported in #26375 and #30238, which were closed without a repro. **Root cause** For a pop, `StackNavigationManager.ApplyNavigationRequest`: 1. calls `NavController.PopBackStack(popToId, false)`; 2. calls `IterateBackStack` to find the destinations that are no longer on the back stack, and removes them from the `NavGraph`. `IterateBackStack` calls `NavController.GetBackStackEntry` for every destination in the graph. For each destination that was just popped, that call throws `IllegalArgumentException`, which `IterateBackStack` catches. **Fix** When `PopBackStack` succeeds, the popped destinations are removed from the graph right away. They are the entries after `popToId` in `fragmentNavDestinations`, the list the method already uses to find `popToId`. `IterateBackStack` then only finds destinations that are on the back stack. The method already removed these same destinations a few lines later, so the resulting graph and back stack don't change. Not changed: `Initialize` runs when a `NavigationPage` handler is created with more than one page. It still calls `IterateBackStack` while only the first page's destination is on the back stack. The bug also reproduces on `net11.0`. There, the default Android Shell handler also navigates through `StackNavigationManager` (`ShellStackNavigationManager`), so Shell back navigation throws the same exceptions too. **Tests** `NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions` (Core.DeviceTests, Android) pops two of three pages. During the pop, it records every `IllegalArgumentException` that reaches `AppDomain.FirstChanceException`. | | Without fix | With fix | |---|---|---| | `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with ID 3 is on the NavController's back stack`, and the same for ID 4 | Passes | These results are from `inflight/current` (262d959) on an API 37 emulator. With the fix: | Suite | Category | Passed | |---|---|---| | Core.DeviceTests | `NavigationPage` | 2/2 | | Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped | | Controls.DeviceTests | `Modal` | 42/44 | | Controls.DeviceTests | `FlyoutPage` | 17/17 | | Controls.DeviceTests | `TabbedPage` | 44/48 | These tests also time out on this emulator without the fix: - `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals, so it doesn't run this code) - `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases On `net11.0` (0b038e7), the test also fails without the fix and passes with it. Controls.DeviceTests `Shell` passed 151/151 there. ### Issues Fixed Fixes #31368 Fixes #35276 ---------
…ed from a NavigationPage (#39183) ### Description of Change On Android, every page popped from a `NavigationPage` throws a Java `IllegalArgumentException`: ``` Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment at androidx.navigation.NavController.getBackStackEntry(...) ``` MAUI catches the exception, so navigation still works. `AppDomain.FirstChanceException` handlers, crash reporters and the debugger output still see it. The same exception was also reported in #26375 and #30238, which were closed without a repro. **Root cause** For a pop, `StackNavigationManager.ApplyNavigationRequest`: 1. calls `NavController.PopBackStack(popToId, false)`; 2. calls `IterateBackStack` to find the destinations that are no longer on the back stack, and removes them from the `NavGraph`. `IterateBackStack` calls `NavController.GetBackStackEntry` for every destination in the graph. For each destination that was just popped, that call throws `IllegalArgumentException`, which `IterateBackStack` catches. **Fix** When `PopBackStack` succeeds, the popped destinations are removed from the graph right away. They are the entries after `popToId` in `fragmentNavDestinations`, the list the method already uses to find `popToId`. `IterateBackStack` then only finds destinations that are on the back stack. The method already removed these same destinations a few lines later, so the resulting graph and back stack don't change. Not changed: `Initialize` runs when a `NavigationPage` handler is created with more than one page. It still calls `IterateBackStack` while only the first page's destination is on the back stack. The bug also reproduces on `net11.0`. There, the default Android Shell handler also navigates through `StackNavigationManager` (`ShellStackNavigationManager`), so Shell back navigation throws the same exceptions too. **Tests** `NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions` (Core.DeviceTests, Android) pops two of three pages. During the pop, it records every `IllegalArgumentException` that reaches `AppDomain.FirstChanceException`. | | Without fix | With fix | |---|---|---| | `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with ID 3 is on the NavController's back stack`, and the same for ID 4 | Passes | These results are from `inflight/current` (262d959) on an API 37 emulator. With the fix: | Suite | Category | Passed | |---|---|---| | Core.DeviceTests | `NavigationPage` | 2/2 | | Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped | | Controls.DeviceTests | `Modal` | 42/44 | | Controls.DeviceTests | `FlyoutPage` | 17/17 | | Controls.DeviceTests | `TabbedPage` | 44/48 | These tests also time out on this emulator without the fix: - `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals, so it doesn't run this code) - `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases On `net11.0` (0b038e7), the test also fails without the fix and passes with it. Controls.DeviceTests `Shell` passed 151/151 there. ### Issues Fixed Fixes #31368 Fixes #35276 ---------
…ed from a NavigationPage (#39183) ### Description of Change On Android, every page popped from a `NavigationPage` throws a Java `IllegalArgumentException`: ``` Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment at androidx.navigation.NavController.getBackStackEntry(...) ``` MAUI catches the exception, so navigation still works. `AppDomain.FirstChanceException` handlers, crash reporters and the debugger output still see it. The same exception was also reported in #26375 and #30238, which were closed without a repro. **Root cause** For a pop, `StackNavigationManager.ApplyNavigationRequest`: 1. calls `NavController.PopBackStack(popToId, false)`; 2. calls `IterateBackStack` to find the destinations that are no longer on the back stack, and removes them from the `NavGraph`. `IterateBackStack` calls `NavController.GetBackStackEntry` for every destination in the graph. For each destination that was just popped, that call throws `IllegalArgumentException`, which `IterateBackStack` catches. **Fix** When `PopBackStack` succeeds, the popped destinations are removed from the graph right away. They are the entries after `popToId` in `fragmentNavDestinations`, the list the method already uses to find `popToId`. `IterateBackStack` then only finds destinations that are on the back stack. The method already removed these same destinations a few lines later, so the resulting graph and back stack don't change. Not changed: `Initialize` runs when a `NavigationPage` handler is created with more than one page. It still calls `IterateBackStack` while only the first page's destination is on the back stack. The bug also reproduces on `net11.0`. There, the default Android Shell handler also navigates through `StackNavigationManager` (`ShellStackNavigationManager`), so Shell back navigation throws the same exceptions too. **Tests** `NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions` (Core.DeviceTests, Android) pops two of three pages. During the pop, it records every `IllegalArgumentException` that reaches `AppDomain.FirstChanceException`. | | Without fix | With fix | |---|---|---| | `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with ID 3 is on the NavController's back stack`, and the same for ID 4 | Passes | These results are from `inflight/current` (262d959) on an API 37 emulator. With the fix: | Suite | Category | Passed | |---|---|---| | Core.DeviceTests | `NavigationPage` | 2/2 | | Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped | | Controls.DeviceTests | `Modal` | 42/44 | | Controls.DeviceTests | `FlyoutPage` | 17/17 | | Controls.DeviceTests | `TabbedPage` | 44/48 | These tests also time out on this emulator without the fix: - `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals, so it doesn't run this code) - `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases On `net11.0` (0b038e7), the test also fails without the fix and passes with it. Controls.DeviceTests `Shell` passed 151/151 there. ### Issues Fixed Fixes #31368 Fixes #35276 ---------
…ed from a NavigationPage (#39183) ### Description of Change On Android, every page popped from a `NavigationPage` throws a Java `IllegalArgumentException`: ``` Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment at androidx.navigation.NavController.getBackStackEntry(...) ``` MAUI catches the exception, so navigation still works. `AppDomain.FirstChanceException` handlers, crash reporters and the debugger output still see it. The same exception was also reported in #26375 and #30238, which were closed without a repro. **Root cause** For a pop, `StackNavigationManager.ApplyNavigationRequest`: 1. calls `NavController.PopBackStack(popToId, false)`; 2. calls `IterateBackStack` to find the destinations that are no longer on the back stack, and removes them from the `NavGraph`. `IterateBackStack` calls `NavController.GetBackStackEntry` for every destination in the graph. For each destination that was just popped, that call throws `IllegalArgumentException`, which `IterateBackStack` catches. **Fix** When `PopBackStack` succeeds, the popped destinations are removed from the graph right away. They are the entries after `popToId` in `fragmentNavDestinations`, the list the method already uses to find `popToId`. `IterateBackStack` then only finds destinations that are on the back stack. The method already removed these same destinations a few lines later, so the resulting graph and back stack don't change. Not changed: `Initialize` runs when a `NavigationPage` handler is created with more than one page. It still calls `IterateBackStack` while only the first page's destination is on the back stack. The bug also reproduces on `net11.0`. There, the default Android Shell handler also navigates through `StackNavigationManager` (`ShellStackNavigationManager`), so Shell back navigation throws the same exceptions too. **Tests** `NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions` (Core.DeviceTests, Android) pops two of three pages. During the pop, it records every `IllegalArgumentException` that reaches `AppDomain.FirstChanceException`. | | Without fix | With fix | |---|---|---| | `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with ID 3 is on the NavController's back stack`, and the same for ID 4 | Passes | These results are from `inflight/current` (262d959) on an API 37 emulator. With the fix: | Suite | Category | Passed | |---|---|---| | Core.DeviceTests | `NavigationPage` | 2/2 | | Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped | | Controls.DeviceTests | `Modal` | 42/44 | | Controls.DeviceTests | `FlyoutPage` | 17/17 | | Controls.DeviceTests | `TabbedPage` | 44/48 | These tests also time out on this emulator without the fix: - `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals, so it doesn't run this code) - `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases On `net11.0` (0b038e7), the test also fails without the fix and passes with it. Controls.DeviceTests `Shell` passed 151/151 there. ### Issues Fixed Fixes #31368 Fixes #35276 ---------
Description of Change
On Android, every page popped from a
NavigationPagethrows a JavaIllegalArgumentException:MAUI catches the exception, so navigation still works.
AppDomain.FirstChanceExceptionhandlers, crash reporters and the debugger output still see it. The same exception was also reported in #26375 and #30238, which were closed without a repro.Root cause
For a pop,
StackNavigationManager.ApplyNavigationRequest:NavController.PopBackStack(popToId, false);IterateBackStackto find the destinations that are no longer on the back stack, and removes them from theNavGraph.IterateBackStackcallsNavController.GetBackStackEntryfor every destination in the graph. For each destination that was just popped, that call throwsIllegalArgumentException, whichIterateBackStackcatches.Fix
When
PopBackStacksucceeds, the popped destinations are removed from the graph right away. They are the entries afterpopToIdinfragmentNavDestinations, the list the method already uses to findpopToId.IterateBackStackthen only finds destinations that are on the back stack. The method already removed these same destinations a few lines later, so the resulting graph and back stack don't change.Not changed:
Initializeruns when aNavigationPagehandler is created with more than one page. It still callsIterateBackStackwhile only the first page's destination is on the back stack.The bug also reproduces on
net11.0. There, the default Android Shell handler also navigates throughStackNavigationManager(ShellStackNavigationManager), so Shell back navigation throws the same exceptions too.Tests
NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions(Core.DeviceTests, Android) pops two of three pages. During the pop, it records everyIllegalArgumentExceptionthat reachesAppDomain.FirstChanceException.PoppingPagesDoesntThrowJavaExceptionsNo destination with ID 3 is on the NavController's back stack, and the same for ID 4These results are from
inflight/current(262d959) on an API 37 emulator. With the fix:NavigationPageNavigationPageModalFlyoutPageTabbedPageThese tests also time out on this emulator without the fix:
PushModalModalWithoutAwaiting(it only pushesContentPagemodals, so it doesn't run this code)MovingBetweenMultiplePagesWithNestedNavigationPages, all 4 casesOn
net11.0(0b038e7), the test also fails without the fix and passes with it. Controls.DeviceTestsShellpassed 151/151 there.Issues Fixed
Fixes #31368
Fixes #35276