Repository navigation
[Android] Prevent CollectionView EmptyView crash after handler disconnect - #38653
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38653Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38653" |
|
Hey there @@Shalini-Ashokan! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
This comment has been minimized.
This comment has been minimized.
|
Warning Your |
This reverts commit 5462939.
This comment has been minimized.
This comment has been minimized.
|
Warning Your |
This comment has been minimized.
This comment has been minimized.
|
Note 🔍
|
|
Note 🔍
|
This comment has been minimized.
This comment has been minimized.
Tests Failure Analysis
🧪 CI Analysis — click to expand🧪 maui-pr-devicetests
🧭 Follow-up — actions and refreshNext action: Wait for
|
Resolve the CollectionView Android device-test conflict by retaining the queued empty-view disconnect regression and both upstream grouped empty-view tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Resolved the merge conflict with
GitHub now reports the PR as mergeable (no conflicts). CI for the new commit is still pending. |
AI Review Summary
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After FixGate Result:
|
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
📱 CollectionViewTests (DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash) Category=CollectionView |
🔴 Without fix — 📱 CollectionViewTests (DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash): ⚠️ ENV ERROR · 694s
No log file found
🟢 With fix — 📱 CollectionViewTests (DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash): ⚠️ ENV ERROR · 692s
No log file found
⚠️ Failure Details
⚠️ CollectionViewTests (DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash) without fix:XHarness did not produce the expected fresh result 'testResults-4b1197a69ef54a7096e8413991cc1223.xml' for requested class(es) 'Microsoft.Maui.DeviceTests.CollectionViewTests' (the target tests did not run).⚠️ CollectionViewTests (DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash) with fix:XHarness did not produce the expected fresh result 'testResults-c7fce54530c64daca4faea63f4cc1f94.xml' for requested class(es) 'Microsoft.Maui.DeviceTests.CollectionViewTests' (the target tests did not run).
📁 Fix files reverted (1 files)
src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs
📋 Pre-Flight — Context & Validation
Issue: #38526 - [Android] CollectionView EmptyView callback throws PlatformView cannot be null after handler disconnect
PR: #38653 - [Android] Prevent CollectionView EmptyView crash after handler disconnect
Platforms Affected: Android
Files Changed: 1 implementation, 1 test
Key Findings
UpdateEmptyViewSizeposts an Android UI-loop callback when the EmptyView holder is not yet available; the baseline callback reads the handler's typedPlatformViewafter it may have been disconnected, which throws.- The PR captures the native
RecyclerViewand verifies that it is still the handler's current platform view before servicing the queued callback. - The added Android device test forces the measure/disconnect ordering and waits for the next looper turn. The prior Gate was inconclusive because the test environment could not build/run it; this is not evidence that the fix failed.
- No substantive PR discussion or inline review feedback was present. The dedicated expert review is intentionally deferred to STEP 5b.
Code Review Summary
Verdict: SKIPPED
Confidence: N/A
Errors: 0 | Warnings: 0 | Suggestions: 0
Key code review findings:
- Code review sub-agent was not launched because STEP 5a is limited to the two requested try-fix invocations; the dedicated expert pass runs in STEP 5b.
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #38653 | Capture the native RecyclerView and ignore the queued callback if the handler no longer owns it | 2 files | Original PR |
🔬 Code Review — Deep Analysis
Code Review — PR #38653
Independent Assessment
What this changes: The Android ItemsViewHandler captures the current native RecyclerView before queuing EmptyView layout work. The queued callback compares that captured view with the nullable IElementHandler.PlatformView and exits when the handler has disconnected or reconnected to a replacement view, avoiding the throwing typed PlatformView getter after teardown. The PR also adds an Android device regression test that queues the layout callback, disconnects the handler, and waits for the next looper turn.
Inferred motivation: IElementHandler.DisconnectHandler() clears the base PlatformView before invoking handler teardown. The old callback subsequently read the non-null typed getter, which throws InvalidOperationException when the queued work outlives the handler connection.
Approach assessment: The implementation is sound and narrowly scoped. Reference identity rejects callbacks after both disconnect and reconnect while preserving the existing holder-level RequestLayout() behavior when the same native view remains connected. It adds no shared state or public API.
Reconciliation with PR Narrative
Author claims: A delayed Android EmptyView layout callback can run after handler disconnect and crash while reading PlatformView; capturing the native view and validating ownership prevents that access.
Agreement/disagreement: The code and lifecycle implementation support the claim. The callback uses the nullable interface property only for the ownership check and never evaluates the throwing typed getter after disconnect.
Prior Review Reconciliation
No prior ❌ Error findings were found across top-level reviews, inline review comments, or PR issue comments. The single authorized maui-expert-reviewer pass produced inline-findings.json with [].
Blast Radius Assessment
- Runs for all instances:
UpdateEmptyViewSizestill runs during Android measure/arrange, but the changed callback path requires anEmptyViewAdapter, changed dimensions, and a holder that is not yet available. - Startup impact: None; this is instance-local deferred layout work.
- Static/shared state: None.
- Adjacent CollectionView behavior: Existing-holder layout remains synchronous, header-aware adapter positioning is unchanged, and normal item adapters and other platforms do not enter the changed branch.
CI Status
- Required-check result: Pending for current PR HEAD
aa67c09429f7de2424cd17b5c9b5618b63a6fe08; the public check-run API showed themaui-praggregate queued and its build/test jobs in progress. - Classification: Undetermined, not a PR-caused failure.
- Trusted Gate:
⚠️ INCONCLUSIVE because the environment did not produce a usable broken-baseline result. Per the execution contract, this is not classified as a fix failure and was not rerun. - Action taken: Confidence is capped at low; no additional CI investigation or gate rerun was performed.
Findings
No actionable errors, warnings, or suggestions.
Failure-Mode Probing
- Disconnect before dispatch:
IElementHandler.PlatformViewis null, so the callback returns without touching the throwing typed getter. - Disconnect and reconnect before dispatch: the replacement native view differs by reference from the captured old
RecyclerView, so stale work is rejected. - Still connected at dispatch: identity matches, the holder lookup uses the captured live view, and the prior
ItemView.RequestLayout()behavior is preserved. - No EmptyView or a populated source: the adapter is not
EmptyViewAdapter, so behavior is unchanged. - Header present: the existing position calculation remains
1; the change only alters lifecycle validation.
External Output Contract
Not applicable.
Verdict: NEEDS_DISCUSSION
Confidence: low
Summary: The raw fix is correct on code inspection and the expert pass found no actionable issue. Approval cannot be recommended from this evaluation alone because current required CI is pending and the trusted regression gate is inconclusive.
🛠️ Try-Fix — Analysis & Comparison
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| 1 | gpt-5.3-codex / try-fix | Invalidate deferred EmptyView callbacks with a handler generation token on disconnect, then use the nullable interface platform view | ✅ PASSED (2/2 scoped Android device tests) | 1 file | Different from the PR's captured-view ownership comparison; inline expert self-review found 0 issues |
| 2 | gpt-5.6-sol / try-fix | Post a native RecyclerView layout request instead of a deferred handler-dependent ViewHolder lookup | ✅ PASSED (2/2 scoped Android device tests) | 1 file | Avoids handler state, ownership checks, and lifecycle tokens; inline expert self-review found 0 issues |
| PR | PR #38653 | Capture the native RecyclerView and ignore the queued callback if the handler no longer owns it | 2 files | Original PR |
Cross-Pollination
| Model | Round | New Ideas? | Details |
|---|---|---|---|
| N/A | N/A | N/A | Intentionally skipped by the STEP 5a execution contract |
Exhausted: Yes - the bounded two-candidate budget is complete.
Selected Fix: Candidate #2 — both alternatives passed the same primary and related EmptyView regression tests, but candidate #2 is simpler and removes the deferred handler-dependent lookup without adding mutable lifecycle state.
📝 PR Finalize — Recommended Title & Description
Assessment: ✏️ Recommend updating — the current description says the callback does not access the handler after disconnect, but the submitted code actually reads nullable IElementHandler.PlatformView to verify that the captured RecyclerView is still current before using it.
Recommended title
[Android] CollectionView: Prevent EmptyView crash after handler disconnect
Recommended description
### Issue Details
When a `CollectionView` has an `EmptyView`, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the previous code reads the typed `PlatformView` getter after it has been cleared and crashes the application.
### Root Cause
Android queues the EmptyView layout work for the next UI-loop cycle. Navigation can disconnect the handler and clear its `PlatformView` before that work executes. The queued callback then reads the non-null typed `PlatformView` getter, causing the “PlatformView cannot be null here” exception.
### Description of Change
The native `RecyclerView` is captured before scheduling the delayed EmptyView layout update. When the callback runs, it compares the captured view with the handler's nullable `IElementHandler.PlatformView` and returns if the handler disconnected or now owns a different native view. If the captured view is still current, the callback finds the EmptyView holder and requests layout without reading the throwing typed getter.
An Android device regression test queues the EmptyView layout callback, disconnects the handler, verifies that its platform view was cleared, and waits for the next looper turn to confirm that the callback does not crash.
### Platforms Validated
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
### Issues Fixed
Fixes #38526
### Output Screenshot
| Before | After |
|--|--|
| <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"> | <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613"> |
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Winning Candidate: try-fix-2
try-fix-2 is the strongest candidate because it passed both scoped Android device tests and removes the deferred callback's dependency on handler state entirely. When the EmptyView holder is unavailable, it posts RecyclerView.RequestLayout on the captured native view; the next native layout pass consumes the adapter dimensions already updated by UpdateEmptyViewSize. This is simpler than retaining a handler-aware callback and avoids new lifecycle state.
Comparative Ranking
| Rank | Candidate | Mechanism | Regression evidence | Assessment |
|---|---|---|---|---|
| 1 | try-fix-2 |
Post a native RecyclerView.RequestLayout when the EmptyView holder is not yet available |
✅ PASSED — 2/2 scoped Android device tests | Best balance of correctness and simplicity. It removes the stale handler access rather than guarding it, adds no mutable state, and also avoids using a potentially stale holder position inside the deferred callback. |
| 2 | try-fix-1 |
Increment a handler generation on disconnect and reject callbacks from older generations | ✅ PASSED — 2/2 scoped Android device tests | Correctly invalidates stale work, but adds mutable lifecycle bookkeeping and still performs a deferred handler/view lookup. |
| 3 | pr |
Capture the native view and run the holder lookup only when it is still the handler's current platform view | Sound on code inspection and covered by an appropriate submitted regression test, but the trusted Gate did not verify it in the available environment. | |
| 4 | pr-plus-reviewer |
Identical to pr; the expert pass produced no actionable refinement |
No worse than the raw PR, but it provides no improvement and no additional validation evidence. |
No candidate failed a regression test. The two passing alternatives therefore rank above the unverified raw/reviewer candidates; the Gate's environment failure is not treated as a failing fix.
Expert Review Result
inline-findings.json:[]- Actionable errors, warnings, or suggestions: none
- Raw PR lifecycle behavior: safe on disconnect, reconnect to a replacement native view, and normal connected dispatch
- Blast radius: localized to Android CollectionView EmptyView measure/arrange work; no public API, startup path, static state, or non-Android implementation changes
Validation and Risk
The targeted command for both try-fix candidates exercised:
DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrashNullItemsSourceDisplaysHeaderFooterAndEmptyView
Both tests passed for try-fix-2. Posting a parent RecyclerView layout is broader than requesting layout on one holder, but it occurs only when dimensions changed and that holder does not yet exist; the passing related EmptyView test provides direct evidence that layout remains correct. Current PR CI is pending, so confidence in overall merge safety remains limited even though the candidate comparison is decisive.
Required Change
Replace the submitted deferred ownership-check callback with the try-fix-2 native RecyclerView.RequestLayout approach while retaining the submitted regression test. Because an alternative candidate wins, the submitted PR should not be approved as-is.
📱 UI Tests — CollectionView
Detected UI test categories: CollectionView
❌ Deep UI tests — 615 passed, 23 failed across 1 category on platform-pool agent (replaces in-process counts above).
🧪 UI Test Execution Results (deep, platform pool)
| Category | Tests | Snapshot diffs |
|---|---|---|
CollectionView |
615/638 (23 ❌) | — |
🔍 AI analysis of failures — PR-related vs unrelated
🔍 AI-generated triage (GitHub Copilot CLI) — a heuristic judgement of whether each deep UI test failure is connected to this PR's changes. Verify before relying on it.
Likely unrelated: the failures appear pre-existing, flaky, or infrastructure.
- ● Unrelated — Android CollectionView scrolling and automation failures (23 tests): the populated-list index mismatches do not exercise the changed
EmptyViewAdaptersizing callback, while the timeout and stale-element variants are nondeterministic Appium patterns rather than evidence that the callback guard affects scrolling.
Strongest signal: the production change is confined to a queued empty-view relayout during sizing and disconnect, whereas these failures involve populated scrolling positions, header interaction, or element lookup.
❌ CollectionView — 23 failed tests
VerifyGroupIndexScrollToByIndexWithMakeVisiblePositionAndVerticalList_Apricot
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithMakeVisiblePositionAndVerticalList_Apricot() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1824
at System
...
VerifyGroupItemScrollToByIndexWithStartPositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("FirstIndexLabel").GetText(), Is.EqualTo("13"))
String lengths are both 2. Strings differ at index 0.
Expected: "13"
But was: "45"
-----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithStartPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3368
1) at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithStartPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3368
VerifyGroupItemScrollToByItemWithCenterPositionAndVerticalList_Potato
Assert.That(App.WaitForElement("CenterIndexLabel").GetText(), Is.EqualTo("30"))
String lengths are both 2. Strings differ at index 0.
Expected: "30"
But was: "46"
-----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByItemWithCenterPositionAndVerticalList_Potato() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2028
1) at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByItemWithCenterPositionAndVerticalList_Potato() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2028
VerifyGroupItemScrollToByItemWithMakeVisiblePositionAndVerticalList_Apricot
Assert.That(App.WaitForElement("LastIndexLabel").GetText(), Is.EqualTo("24"))
String lengths are both 2. Strings differ at index 0.
Expected: "24"
But was: "51"
-----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByItemWithMakeVisiblePositionAndVerticalList_Apricot() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1961
1) at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByItemWithMakeVisiblePositionAndVerticalList_Apricot() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1961
VerifyScrollToByItemWithMakeVisiblePositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("LastIndexLabel").GetText(), Is.EqualTo("12"))
String lengths are both 2. Strings differ at index 0.
Expected: "12"
But was: "29"
-----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithMakeVisiblePositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2473
1) at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithMakeVisiblePositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2473
CollectionViewHeaderShouldNotScroll
OpenQA.Selenium.StaleElementReferenceException : Cached elements 'By.id: com.microsoft.maui.uitests:id/HeaderEntry' do not exist in DOM anymore; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#stale-element-reference-exception
at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
at OpenQA.Selenium.WebDriver.ExecuteAsync(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebElement.Execute(String commandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebElement.get_Location()
at OpenQA.Selenium.Appium.AppiumElement.get_Rect()
at UITest.Appium.AppiumGeneralActions.GetRect(IDictionary`2 parameters) in /_/src/TestUtils/src/UITest.Appium/Actions/AppiumGeneralActions.cs:line 51
at UITest.Appium.AppiumGeneralActions.Execute(String commandName, IDictionary`2 parameters) in /_/src/TestUtils/src/UITest.Appium/Actions/AppiumGeneralA
...
VerifyScrollToByIndexWithStartPositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByIndexWithStartPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2228
at System.RuntimeMethodHan
...
VerifyScrollToByItemWithEndPositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("LastIndexLabel").GetText(), Is.EqualTo("12"))
String lengths are both 2. Strings differ at index 0.
Expected: "12"
But was: "29"
-----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithEndPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2732
1) at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithEndPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2732
VerifyGroupIndexScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2833
at System.
...
VerifyGroupItemScrollToByIndexWithEndPositionAndHorizontalGrid_Potato
Assert.That(App.WaitForElement("LastIndexLabel").GetText(), Is.EqualTo("30"))
String lengths are both 2. Strings differ at index 0.
Expected: "30"
But was: "51"
-----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithEndPositionAndHorizontalGrid_Potato() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3620
1) at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithEndPositionAndHorizontalGrid_Potato() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3620
VerifyGroupIndexScrollToByIndexWithStartPositionAndVerticalList_Carrot
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithStartPositionAndVerticalList_Carrot() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1860
at System.Runtim
...
VerifyGroupIndexScrollToByIndexWithEndPositionAndHorizontalGrid_Potato
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithEndPositionAndHorizontalGrid_Potato() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3193
at System.Runtim
...
VerifyGroupItemScrollToByIndexWithEndPositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("LastIndexLabel").GetText(), Is.EqualTo("13"))
String lengths are both 2. Strings differ at index 0.
Expected: "13"
But was: "51"
-----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithEndPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3584
1) at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithEndPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3584
VerifyScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2149
at System.RuntimeMet
...
VerifyGroupItemScrollToByItemWithStartPositionAndVerticalList_Carrot
Assert.That(App.WaitForElement("FirstIndexLabel").GetText(), Is.EqualTo("27"))
String lengths are both 2. Strings differ at index 0.
Expected: "27"
But was: "41"
-----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByItemWithStartPositionAndVerticalList_Carrot() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1994
1) at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByItemWithStartPositionAndVerticalList_Carrot() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1994
VerifyGroupItemScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("LastIndexLabel").GetText(), Is.EqualTo("13"))
String lengths are both 2. Strings differ at index 0.
Expected: "13"
But was: "51"
-----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3262
1) at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3262
VerifyScrollToByIndexWithCenterPositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByIndexWithCenterPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2309
at System.RuntimeMethodHa
...
VerifyScrollToByItemWithCenterPositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("CenterIndexLabel").GetText(), Is.EqualTo("12"))
String lengths are both 2. Strings differ at index 0.
Expected: "12"
But was: "27"
-----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithCenterPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2645
1) at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithCenterPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2645
VerifyGroupIndexScrollToByIndexWithEndPositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithEndPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3157
at System.RuntimeM
...
VerifyScrollToByIndexWithEndPositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByIndexWithEndPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2390
at System.RuntimeMethodHandl
...
VerifyGroupIndexScrollToByIndexWithStartPositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithStartPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2941
at System.Runtim
...
VerifyGroupIndexScrollToByIndexWithCenterPositionAndVerticalList_Potato
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithCenterPositionAndVerticalList_Potato() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1894
at System.Runti
...
VerifyScrollToByItemWithStartPositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("FirstIndexLabel").GetText(), Is.EqualTo("12"))
String lengths are both 2. Strings differ at index 0.
Expected: "12"
But was: "24"
-----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithStartPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2558
1) at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithStartPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2558
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)
🧭 Next Steps — alternative fix proposed (try-fix-2)
Automated review — alternative fix proposed
The expert-reviewer evaluation compared the PR fix against automatically generated candidates and selected try-fix-2 as the strongest fix.
Why: try-fix-2 passed both scoped Android device tests and removes deferred handler-state access without adding lifecycle bookkeeping. Its native RecyclerView layout request is simpler than the submitted ownership guard and preserves the regression test against the PR base.
Please consider applying the candidate diff below (or use it as guidance). Once you push an update, this workflow will re-trigger and re-evaluate.
Candidate diff (try-fix-2)
diff --git a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs
index 8542a9dbf5d9451432553d5ef44240b8661876b2..5401a9b8bed5dbeeaf76b01b4f80560f7a39921b 100644
--- a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs
+++ b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs
@@ -105,7 +105,8 @@ namespace Microsoft.Maui.Controls.Handlers.Items
void UpdateEmptyViewSize(double width, double height)
{
- var adapter = PlatformView.GetAdapter();
+ var platformView = PlatformView;
+ var adapter = platformView.GetAdapter();
if (adapter is EmptyViewAdapter emptyViewAdapter)
{
@@ -124,7 +125,7 @@ namespace Microsoft.Maui.Controls.Handlers.Items
var emptyViewPosition = hasHeader ? 1 : 0;
// Check if ViewHolder exists and is ready for immediate layout request
- var viewHolder = PlatformView.FindViewHolderForAdapterPosition(emptyViewPosition);
+ var viewHolder = platformView.FindViewHolderForAdapterPosition(emptyViewPosition);
if (viewHolder is not null)
{
// ViewHolder exists, request layout immediately to avoid frame delay
@@ -132,12 +133,8 @@ namespace Microsoft.Maui.Controls.Handlers.Items
}
else
{
- // ViewHolder not created yet, defer layout request to next UI loop iteration
- PlatformView.Post(() =>
- {
- var vh = PlatformView.FindViewHolderForAdapterPosition(emptyViewPosition);
- vh?.ItemView.RequestLayout();
- });
+ // ViewHolder not created yet, defer RecyclerView layout to the next UI loop iteration
+ platformView.Post(platformView.RequestLayout);
}
}
}
diff --git a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.Android.cs
index 4976a590d4a0fd54888e7745e33eb768908624a1..92f45ecbeea65d81e536f3c90b6906be3a54d79e 100644
--- a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.Android.cs
+++ b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.Android.cs
@@ -105,6 +105,43 @@ namespace Microsoft.Maui.DeviceTests
});
}
+ [Fact]
+ public async Task DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash()
+ {
+ SetupBuilder();
+
+ var host = new Grid();
+
+ await CreateHandlerAndAddToWindow<LayoutHandler>(host, async _ =>
+ {
+ var collectionView = new CollectionView
+ {
+ ItemsSource = System.Array.Empty<string>(),
+ EmptyView = new Label { Text = "Empty" }
+ };
+
+ host.Add(collectionView);
+
+ var handler = Assert.IsType<CollectionViewHandler>(collectionView.Handler);
+ var platformView = handler.PlatformView;
+
+ Assert.True(platformView.IsAttachedToWindow);
+ Assert.IsType<EmptyViewAdapter>(platformView.GetAdapter());
+ Assert.Null(platformView.FindViewHolderForAdapterPosition(0));
+
+ handler.GetDesiredSize(317, 241);
+
+ host.Remove(collectionView);
+ ((IElementHandler)handler).DisconnectHandler();
+
+ Assert.Null(((IElementHandler)handler).PlatformView);
+
+ var nextLooperTurn = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
+ MauiContext.Context.GetActivity().Window.DecorView.Post(() => nextLooperTurn.SetResult(true));
+ await nextLooperTurn.Task.WaitAsync(System.TimeSpan.FromSeconds(5));
+ });
+ }
+
//src/Compatibility/Core/tests/Android/RendererTests.cs
[Fact(DisplayName = "EmptySource should have a count of zero")]
[Trait("Category", "CollectionView")]
…nect (#38653) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details When a CollectionView has an EmptyView, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application. ### Root Cause Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception. ### Description of Change The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects. The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash. Validated the behavior in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Issues Fixed Fixes #38526 ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f" >| <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">| --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nect (#38653) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details When a CollectionView has an EmptyView, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application. ### Root Cause Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception. ### Description of Change The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects. The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash. Validated the behavior in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Issues Fixed Fixes #38526 ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f" >| <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">| --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nect (#38653) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details When a CollectionView has an EmptyView, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application. ### Root Cause Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception. ### Description of Change The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects. The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash. Validated the behavior in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Issues Fixed Fixes #38526 ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f" >| <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">| --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nect (#38653) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details When a CollectionView has an EmptyView, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application. ### Root Cause Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception. ### Description of Change The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects. The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash. Validated the behavior in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Issues Fixed Fixes #38526 ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f" >| <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">| --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nect (#38653) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details When a CollectionView has an EmptyView, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application. ### Root Cause Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception. ### Description of Change The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects. The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash. Validated the behavior in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Issues Fixed Fixes #38526 ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f" >| <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">| --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nect (#38653) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details When a CollectionView has an EmptyView, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application. ### Root Cause Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception. ### Description of Change The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects. The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash. Validated the behavior in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Issues Fixed Fixes #38526 ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f" >| <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">| --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nect (#38653) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details When a CollectionView has an EmptyView, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application. ### Root Cause Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception. ### Description of Change The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects. The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash. Validated the behavior in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Issues Fixed Fixes #38526 ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f" >| <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">| --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nect (#38653) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details When a CollectionView has an EmptyView, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application. ### Root Cause Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception. ### Description of Change The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects. The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash. Validated the behavior in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Issues Fixed Fixes #38526 ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f" >| <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">| --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nect (#38653) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details When a CollectionView has an EmptyView, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application. ### Root Cause Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception. ### Description of Change The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects. The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash. Validated the behavior in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Issues Fixed Fixes #38526 ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f" >| <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">| --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nect (#38653) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details When a CollectionView has an EmptyView, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application. ### Root Cause Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception. ### Description of Change The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects. The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash. Validated the behavior in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Issues Fixed Fixes #38526 ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f" >| <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">| --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nect (#38653) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details When a CollectionView has an EmptyView, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application. ### Root Cause Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception. ### Description of Change The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects. The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash. Validated the behavior in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Issues Fixed Fixes #38526 ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f" >| <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">| --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nect (#38653) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details When a CollectionView has an EmptyView, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application. ### Root Cause Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception. ### Description of Change The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects. The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash. Validated the behavior in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Issues Fixed Fixes #38526 ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f" >| <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">| --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…nect (#38653) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details When a CollectionView has an EmptyView, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application. ### Root Cause Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception. ### Description of Change The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects. The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash. Validated the behavior in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Issues Fixed Fixes #38526 ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f" >| <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">| --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to size it.
If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application.
Root Cause
Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception.
Description of Change
The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects.
The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash.
Validated the behavior in the following platforms
Issues Fixed
Fixes #38526
Output ScreenShot
BeforeFix-38526.mov
AfterFix-38526.mov