Skip to content

[Android] Keep EmptyViewAdapter view types from matching the items adapter's - #39193

Merged
kubaflo merged 6 commits into
dotnet:inflight/currentfrom
MykhailoDav:fix-34207-android-emptyview-viewtype-collision
Oct 7, 2026
Merged

kubaflo merged 6 commits into
dotnet:inflight/currentfrom
MykhailoDav:fix-34207-android-emptyview-viewtype-collision

Conversation

@MykhailoDav

@MykhailoDav MykhailoDav commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Description of Change

On Android, a CollectionView that has an EmptyView can show the wrong views after its items are cleared and loaded again a few times. The empty view, header or footer can show up in place of items. The reporter's repro breaks after 9 reloads. In the test below, it breaks after the first reload.

Root cause

MauiRecyclerView swaps the RecyclerView between EmptyViewAdapter and the items adapter. The two adapters take their view holders from the same RecycledViewPool. The pool is cleared before each SwapAdapter, but SwapAdapter(…, true) puts the old adapter's view holders back into it.

EmptyViewAdapter starts its view types at 1, 2 and 3. Every Header, HeaderTemplate, Footer, FooterTemplate, EmptyView and EmptyViewTemplate set increments one of them, and UpdateEmptyView sets all six each time it runs. So the values grow into the view types of the items adapter: ItemViewType (41–46) and DataTemplate ids (from 101).

When two view types match, RecyclerView binds a view holder of one adapter in the other one. In the test, the empty adapter's empty-view holder (view type 44) ends up in the footer position (ItemViewType.Footer). Separately, the header type (1 + 2n) reaches the footer's earlier values (3 + 2n), so even inside EmptyViewAdapter the header can reuse an old footer holder.

Fix

All view types of EmptyViewAdapter now come from one counter that counts down from -2 (-1 is RecyclerView.INVALID_TYPE).

  • The items adapter's view types are all positive, so the two adapters can't share a view type.
  • No view type is reused, so header, empty view and footer can't match each other either.
  • Each property set still gets a new view type. That still forces OnCreateViewHolder when the EmptyView changes. GridLayoutSpanSizeLookup already assumes these view types never match ItemViewType, which is now true.

#34208 tried to make the values smaller and closed itself after #34452 added the pool clearing. Making the view types constant doesn't work here: the empty view would then reuse its old view holder when the EmptyView changes.

EmptyViewAdapter is identical on net11.0, and the test fails there without the fix as well.

Tests

CollectionViewTests.ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace (Controls.DeviceTests, Android) uses a CollectionView with a header, a footer, an EmptyView and an ItemTemplate. It sets ItemsSource to null and back 30 times. After each step, it checks the view holder at every position.

Without fix With fix
ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace Fails: Reload 1: position 4 should show Footer, but shows Empty (view type 44) Passes

On main (84b1fb3) and an API 37 emulator, the test fails without the fix with the message above and passes with it. With the fix:

  • Controls.DeviceTests CollectionView: 57 passed, 1 skipped.
  • Controls.DeviceTests CarouselView: 10/10 passed.

The same holds on net11.0 (0b038e7).

Issues Fixed

Fixes #34207

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39193

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39193"

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Oct 6, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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.

@kubaflo

This comment has been minimized.

@kubaflo

kubaflo commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

/azp run

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15586330 is running for android.

The s/agent-review-in-progress label stays on this PR while the run is active. The final recommendation and outcome labels are posted only after Gate, expert review, and Deep UI tests finish.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@kubaflo

kubaflo commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

…#39190)

<!-- 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. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

Regenerate only `issue-triage.lock.yml` using gh-aw v0.86.2 against
deployed main `8c974ad7037c6e171e951883c752bbcea1514cc3`, following
dotnet#39065. Shared `pat_pool.md` frontmatter changed before merge, leaving
the triage lock stale. Actual production runs
[37503999448](https://github.com/dotnet/maui/actions/runs/37503999448)
and
[37503998307](https://github.com/dotnet/maui/actions/runs/37503998307)
failed before inference/publication with `E009 CONFIG_HASH_MISMATCH`.

The compiler changes only `frontmatter_hash` in the first metadata line:
- Previous:
`d2c371bf924eb254532ec722f31d817ebdb42fd4e5565b4952a40e09e465e0d1`
- Regenerated:
`eb116514f337eb247c8767becceaefdd9cfb69da65044098b5cdc510e7c2d153`

The new value matches the actual activation runtime recomputation in run
37503999448. All bytes after that metadata line are unchanged:
authorization, GPT-only inference, permission boundaries, publication,
hash checks, action/container pins and job conditions are preserved. Add
a deployment note requiring dependent lock recompilation after shared
import frontmatter changes. No workflow source, shared import, script or
C# changes.

Configuration validation:
- `git merge-base --is-ancestor 8c974ad
HEAD` — passed before editing; initial HEAD was exactly that deployed
squash merge.
- `gh aw compile issue-triage --strict --no-check-update` — passed; 1
workflow succeeded, 0 warnings, compiler v0.86.2.
- `gh aw hash-frontmatter .github/workflows/issue-triage.md` — passed;
output equals regenerated metadata and actual runtime hash above.
- `test "$(gh aw hash-frontmatter .github/workflows/issue-triage.md)" =
"$(head -n 1 .github/workflows/issue-triage.lock.yml | sed 's/^#
gh-aw-metadata: //' | jq -r .frontmatter_hash)"` — passed.
- `cmp <(git show HEAD:.github/workflows/issue-triage.lock.yml | tail -n
+2) <(tail -n +2 .github/workflows/issue-triage.lock.yml)` — passed
before committing; compiled lock excluding metadata is byte-identical to
deployed main.
- `actionlint -ignore 'unexpected key "queue" for "concurrency" section'
.github/workflows/issue-triage.lock.yml` — passed with actionlint
1.7.12; only the existing narrow compiler-generated queue exception.
- `git diff --check` — passed.

No pipeline/Pester/snapshot/synthetic fixture tests or product builds
were added or run. No production commands, dispatches or issue-label
mutations were performed for this correction. Post-merge production
outcome audit remains separate; local validation does not claim hosted
end-to-end success.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Follow-up to dotnet#39065. No issue is closed: the reproduced defect is the
activation failure in the linked actual production runs, not the
underlying product reports used as smoke-test targets.

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

@kubaflo kubaflo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MykhailoDavm my comment on one of your PRs was wrong, which is why I removed it. What I meant was: please make sure that you and Opus don't spend time fixing issues that are no longer valid in net11, but keep targeting main.

Sorry for the misunderstanding. Great job, though - the PRs look pretty good!

@MauiBot

This comment has been minimized.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Oct 6, 2026
…dotnet#39188)

<!-- 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. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

Fix a confirmed startup-deadline regression in the CI-fix Azure DevOps
dispatcher introduced by dotnet#39147, and correct a separate, pre-existing
producer prompt contradiction that blocks mandatory safe-output
registration.

**Production evidence:** [run
37477952193](https://github.com/dotnet/maui/actions/runs/37477952193)
spent approximately 533 seconds between starting the 420-second deadline
and completing trusted checkout; [run
37485076087](https://github.com/dotnet/maui/actions/runs/37485076087)
spent approximately 494 seconds. Both then failed with `The variable
cannot be validated because the value 0 is not a valid value for the
DispatcherBudgetSeconds variable.`

**Root cause:** The script parameter `[ValidateRange(1,
540)][int]$DispatcherBudgetSeconds` and top-level
`$script:DispatcherBudgetSeconds` are the same validated PowerShell
variable. Clamping valid caller input `420` against an already-expired
absolute deadline assigns `0` to that variable, triggering validation
before explicit budget-exhaustion reporting can run. Extracted helper
tests did not exercise this entrypoint initialization.

**Correction:**
- Store the clamped runtime allowance in the distinct
`EffectiveDispatcherBudgetSeconds` variable and update remaining-budget
helpers and their extracted-test state consistently. Caller budget `0`
remains invalid.
- Fail startup explicitly with `[dispatcher-budget-exhausted]` when
preparation has consumed the deadline, before PR discovery,
authentication, HTTP, or sleep. Write a failed preparation/deadline job
summary and state `No queue POST was attempted.` This also fails rather
than claiming successful no-work reconciliation when the deadline is
expired.
- Limit trusted checkout to the standalone
`/.github/scripts/Queue-CiFixAzdoValidation.ps1` using non-cone sparse
checkout. The existing SHA-pinned checkout v7.0.1 supports exact
patterns and automatically uses `blob:none` for sparse fetches. Preserve
`github.sha`, `fetch-depth: 1`, and `persist-credentials: false`; never
fetch or execute PR code.
- Document preparation behavior and limitations. Keep the absolute
pre-checkout 420-second deadline and ten-minute hard job timeout
unchanged; do not restart or extend either allowance.

**Validation:** Baseline dispatcher suite: 73 passed. Before the script
correction, the six new actual-entrypoint cases produced four expected
expired-deadline failures with the original validation exception and two
passing caller-validation/future-deadline cases. After correction, all
**79 tests passed**, including existing helper/queue regressions.
Expired cases assert the preparation summary, explicit prefix, no-POST
message, and zero HTTP/sleep calls; a native PowerShell process asserts
nonzero exit. The valid future deadline still produces the three
verified offline pipeline payloads.

Exact final commands and results:

```powershell
pwsh -NoProfile -Command '$env:PSModulePath = "/Users/shneuvil/.copilot/session-state/237fbb01-6532-4170-9f5e-6af14fa3a5e0/files/powershell-modules" + [IO.Path]::PathSeparator + $env:PSModulePath; Import-Module Pester -ErrorAction Stop; Invoke-Pester -Path .github/scripts/Queue-CiFixAzdoValidation.Tests.ps1 -Output Normal -CI'
# Passed: 79; failed/skipped: 0. Reused existing Pester; no dependency installation.

pwsh -NoProfile -Command '$files = @(".github/scripts/Queue-CiFixAzdoValidation.ps1", ".github/scripts/Queue-CiFixAzdoValidation.Tests.ps1"); foreach ($file in $files) { $tokens = $null; $errors = $null; [void][System.Management.Automation.Language.Parser]::ParseFile((Join-Path $PWD $file), [ref]$tokens, [ref]$errors); if ($errors.Count) { $errors | ForEach-Object { Write-Error $_ }; exit 1 }; Write-Output "Parse passed: $file" }'
# Passed: both PowerShell files parsed without errors.
```

```bash
actionlint .github/workflows/ci-fix-azdo-validation.yml
# Passed.
git diff --check
# Passed.
```

**Limits:** The sparse-checkout assertion is a static
configuration/trust regression, not a hosted checkout timing
measurement. Production checkout performance remains unproven; checkout
or PowerShell startup exceeding the ten-minute hard guard can still
cancel the job before a summary is written. No live Azure queue
requests, manual workflow dispatches/reruns, `/azp` requests, or
credential/permission/model-policy changes were performed. There is
still no successful eligible-PR Azure canary evidence here; this PR does
not establish Azure permissions or exact-head check linkage for any of
the three pipelines.

**Related producer blocker (pre-existing, not introduced by dotnet#39147):**
[main producer run
37464881821](https://github.com/dotnet/maui/actions/runs/37464881821)
and [net11 producer run
37465231994](https://github.com/dotnet/maui/actions/runs/37465231994)
concluded success but emitted `missing_tool` / `report_incomplete`. The
net11 diagnostic explicitly says mandatory expectation registration
requires PowerShell but the run instructions exclude it. The main
diagnostic likewise reports the prompt-specific `no-pwsh` restriction,
alongside separate unavailable cited Azure timeline evidence. This is an
upstream producer blocker: a compliant PR cannot reach dispatcher
validation if required registration is prohibited by its own prompt.

Both producers already allow `pwsh` in `tools.bash`, and Hard Rule 11
requires `Register-CiFixSafeOutputExpectation.ps1` or atomic
validation/registration via `Test-CiFixTransport.ps1`. Their bottom
Environment constraints sections nevertheless said `no pwsh`. The
mirrored correction changes only that prose: explicitly identify `pwsh`
availability for those deterministic helpers, retain `no gh` / `no
python` and `curl` + `jq` API guidance, and reiterate existing
fail-closed registration/transport requirements. No tool allowlists,
network, permissions, credentials, trust, model policy, or output gates
change.

Added two assertions in the existing registration test suite protecting
both producer twins. Both failed on the old contradictory guidance and
pass after correction. Regenerated both locks with retained **gh-aw
v0.86.2**, without manual edits or compiler upgrade; **only `body_hash`
changes**. Frontmatter and all generated lock runtime content remain
identical.

Additional exact validation commands and results:

```powershell
pwsh -NoProfile -Command '$env:PSModulePath = "/Users/shneuvil/.copilot/session-state/237fbb01-6532-4170-9f5e-6af14fa3a5e0/files/powershell-modules" + [IO.Path]::PathSeparator + $env:PSModulePath; Import-Module Pester -ErrorAction Stop; $config = New-PesterConfiguration; $config.Run.Path = @(".github/scripts/Register-CiFixSafeOutputExpectation.Tests.ps1", ".github/scripts/Test-CiFixTransport.Tests.ps1", ".github/scripts/Queue-CiFixAzdoValidation.Tests.ps1"); $config.Run.Exit = $true; $config.Output.Verbosity = "Normal"; $config.TestResult.Enabled = $true; $config.TestResult.OutputPath = "/Users/shneuvil/.copilot/session-state/1e0cc90a-a521-4055-9e7a-9565cdaf5504/files/producer-and-dispatcher-pester-results.xml"; Invoke-Pester -Configuration $config'
# Passed after lock regeneration: 116 tests (6 registration, 31 transport, 79 dispatcher); 0 failed/skipped.

pwsh -NoProfile -Command '$file = Join-Path $PWD ".github/scripts/Register-CiFixSafeOutputExpectation.Tests.ps1"; $tokens = $null; $errors = $null; [void][System.Management.Automation.Language.Parser]::ParseFile($file, [ref]$tokens, [ref]$errors); if ($errors.Count) { $errors | ForEach-Object { Write-Error $_ }; exit 1 }; Write-Output "PowerShell parse passed"'
# Passed.
```

```bash
/Users/shneuvil/.copilot/session-state/237fbb01-6532-4170-9f5e-6af14fa3a5e0/files/tools/gh-aw-0.86.2/darwin-arm64 compile ci-status-fix ci-status-fix-net11 --strict --no-emit --no-check-update
# Passed: 2 workflows, 0 warnings.
/Users/shneuvil/.copilot/session-state/237fbb01-6532-4170-9f5e-6af14fa3a5e0/files/tools/gh-aw-0.86.2/darwin-arm64 compile ci-status-fix ci-status-fix-net11 --strict --no-check-update
# Passed: 2 workflows, 0 warnings; emitted body-hash-only changes.
actionlint .github/workflows/ci-status-fix.lock.yml .github/workflows/ci-status-fix-net11.lock.yml
# Nonzero both before and after regeneration: identical six baseline diagnostics.
# Each twin: concurrency.queue not recognized, ShellCheck SC2129 style, github.aw expression not recognized.
# No new lint findings; baseline/after outputs compared byte-identical.
```

**Producer limits:** These are static prompt/configuration assertions
and offline helper tests, not a hosted agent behavior evaluation.
Removing the contradiction does not guarantee that an agent will
register correctly, find a viable product fix, create a PR, or attach
Azure checks. Separate cited-timeline failures and other producer
blockers are not fixed here. No live workflow or network validation
tests were run.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Follow-up to dotnet#39147 for the production startup regression evidenced by
the two linked dispatcher runs, plus the separate pre-existing producer
helper-guidance contradiction evidenced by the two producer runs. No
separate tracking issue is closed by this PR.

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

---------

Co-authored-by: PureWeen <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1e0cc90a-a521-4055-9e7a-9565cdaf5504
@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Tests Failure Analysis

@MykhailoDav — test-failure analysis for commit f5c6d19.

Scope CI failures Commit f5c6d19


🧪 CI Analysis — click to expand
📊 maui-pr
  • 🟢 Likely unrelated — Debug builds (Windows, macOS): identical MSB4184 empty-version evaluation fails on net11.0; MSBuild targets/SDK configuration are unchanged.

🧪 maui-pr-devicetests

🧪 maui-pr-uitests

🧭 Follow-up — actions and refresh

Next action: Restore complete results and inspect indicated stacks/setup/snapshots.

Maintainers: comment /review tests to refresh this report.

Updated
[Microsoft.AspNetCore.Authentication.Facebook](https://github.com/dotnet/dotnet)
from 10.0.0 to 10.0.13.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.AspNetCore.Authentication.Facebook's
releases](https://github.com/dotnet/dotnet/releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/dotnet/dotnet/commits).
</details>

Updated
[Microsoft.AspNetCore.Authentication.Google](https://github.com/dotnet/dotnet)
from 10.0.0 to 10.0.13.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.AspNetCore.Authentication.Google's
releases](https://github.com/dotnet/dotnet/releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/dotnet/dotnet/commits).
</details>

Updated
[Microsoft.AspNetCore.Authentication.MicrosoftAccount](https://github.com/dotnet/dotnet)
from 10.0.0 to 10.0.13.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.AspNetCore.Authentication.MicrosoftAccount's
releases](https://github.com/dotnet/dotnet/releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/dotnet/dotnet/commits).
</details>

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
MykhailoDav and others added 2 commits October 7, 2026 17:49
Without the fix, the EmptyViewAdapter view types reach the view types
of the items adapter, and RecyclerView reuses the wrong view holder
from the shared pool (dotnet#34207).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…apter's

EmptyViewAdapter started its view types at 1, 2 and 3 and incremented
them every time UpdateEmptyView set its properties, so they grew into
the view types of the items adapter (41-46 and the DataTemplate ids).
RecyclerView then reused a view holder of the other adapter from the
shared pool, which showed the empty view, header or footer in place of
items. The header and footer types also reached each other's old
values.

Give every change a new negative view type from a single counter
instead.

Fixes dotnet#34207

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MykhailoDav
MykhailoDav changed the base branch from net11.0 to main October 7, 2026 14:56
@MykhailoDav
MykhailoDav force-pushed the fix-34207-android-emptyview-viewtype-collision branch from f5c6d19 to 93799df Compare October 7, 2026 14:56
@kubaflo

This comment has been minimized.

@kubaflo

kubaflo commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15598672 is running for android.

The s/agent-review-in-progress label stays on this PR while the run is active. The final recommendation and outcome labels are posted only after Gate, expert review, and Deep UI tests finish.

@kubaflo
kubaflo changed the base branch from main to inflight/current October 7, 2026 16:46
Keep the adapter collision regression test alongside upstream EmptyView disconnect and grouped-source coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@kubaflo

kubaflo commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Resolved and pushed the conflict with inflight/current in merge commit d9ba878ed0. GitHub now reports this PR as mergeable.

The only conflict was in CollectionViewTests.Android.cs. I kept this PR's repeated EmptyView/items reload test and the target branch's EmptyView disconnect and grouped-source tests, including their required imports. The Android EmptyViewAdapter fix is unchanged from the PR head.

Validation: the scoped dotnet format whitespace ... --verify-no-changes check and git diff --check on the PR files passed. dotnet build src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj -f net10.0-android --no-restore -p:PublicApiType=Validate -v:minimal initially failed on an existing xUnit2031 analyzer error in unrelated SwipeViewTests.Android.cs:509. The build passed after retaining the project's existing NoWarn settings and suppressing only xUnit2031 for that validation command. No device tests or XCTest were run.

@kubaflo
kubaflo merged commit 59eca9e into dotnet:inflight/current Oct 7, 2026
2 of 4 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR12 milestone Oct 7, 2026
@MauiBot

MauiBot commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

AI Review Summary

@MykhailoDav — new AI review results are available based on commit 93799df.

Gate Passed Confidence Unknown Platform Android


🗂️ Review Sessions — click to expand

[!WARNING]
This run reviewed commit 93799df, but the PR advanced to d9ba878 while it was running. These results are informational; re-run /review for the current head.


🚦 Gate — Test Before & After Fix

Gate Result: ✅ PASSED

Platform: ANDROID · Base: main · Merge base: 84b1fb39

Test Without Fix (expect FAIL) With Fix (expect PASS)
📱 CollectionViewTests (ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace) Category=CollectionView ✅ FAIL — 451s ✅ PASS — 442s
🔴 Without fix — 📱 CollectionViewTests (ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace): FAIL ✅ · 451s

(no coded error found; showing last 1200 chars)

moryBytes": 8322998272
          },
          "target": {
            "kind": "emulator",
            "name": "sdk_gphone_x86_64",
            "identifier": "emulator-5554",
            "operatingSystem": "Android",
            "operatingSystemVersion": "11",
            "apiLevel": 30,
            "architecture": "x86_64",
            "supportedArchitectures": [
              "x86_64",
              "x86",
              "arm64-v8a",
              "armeabi-v7a",
              "armeabi"
            ],
            "manufacturer": "Google",
            "model": "sdk_gphone_x86_64",
            "productName": "sdk_gphone_x86_64",
            "buildFingerprint": "google/sdk_gphone_x86_64/generic_x86_64_arm64:11/RSR1.201211.001/7027799:user/release-keys",
            "cpuModel": "0",
            "cpuMaxFrequencyHertz": 2000,
            "totalMemoryBytes": 2077544448
          }
        }
      }
      <<XHARNESS_RESULT_END>>
info: Attempting to remove apk 'com.microsoft.maui.controls.devicetests'..
info: Successfully uninstalled com.microsoft.maui.controls.devicetests
XHarness exit code: 1 (TESTS_FAILED)
  Passed: 0
  Failed: 1
  Skipped: 0
  Total: 1
  Tests completed with exit code: 1
🟢 With fix — 📱 CollectionViewTests (ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace): PASS ✅ · 442s

(no coded error found; showing last 1200 chars)

            "totalMemoryBytes": 8322998272
          },
          "target": {
            "kind": "emulator",
            "name": "sdk_gphone_x86_64",
            "identifier": "emulator-5554",
            "operatingSystem": "Android",
            "operatingSystemVersion": "11",
            "apiLevel": 30,
            "architecture": "x86_64",
            "supportedArchitectures": [
              "x86_64",
              "x86",
              "arm64-v8a",
              "armeabi-v7a",
              "armeabi"
            ],
            "manufacturer": "Google",
            "model": "sdk_gphone_x86_64",
            "productName": "sdk_gphone_x86_64",
            "buildFingerprint": "google/sdk_gphone_x86_64/generic_x86_64_arm64:11/RSR1.201211.001/7027799:user/release-keys",
            "cpuModel": "0",
            "cpuMaxFrequencyHertz": 2000,
            "totalMemoryBytes": 2077544448
          }
        }
      }
      <<XHARNESS_RESULT_END>>
info: Attempting to remove apk 'com.microsoft.maui.controls.devicetests'..
info: Successfully uninstalled com.microsoft.maui.controls.devicetests
XHarness exit code: 0
  Passed: 1
  Failed: 0
  Skipped: 0
  Total: 1
  Tests completed successfully
📁 Fix files reverted (1 files)
  • src/Controls/src/Core/Handlers/Items/Android/Adapters/EmptyViewAdapter.cs

📋 Pre-Flight — Context & Validation

⚠️ Pre-Flight did not produce output on this run.

The 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 /review to retry on a fresh agent. If this repeats across runs, a maintainer should inspect the reviewer token and Task 3 logs.


🔬 Code Review — Deep Analysis

⚠️ Code Review did not produce output on this run.

The 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 /review to retry on a fresh agent. If this repeats across runs, a maintainer should inspect the reviewer token and Task 3 logs.


🛠️ Try-Fix — Analysis & Comparison

⚠️ Try-Fix did not produce output on this run.

The 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 /review to retry on a fresh agent. If this repeats across runs, a maintainer should inspect the reviewer token and Task 3 logs.


🏁 Report — Final Recommendation

⚠️ Report / Final Recommendation did not produce output on this run.

The 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 /review to retry on a fresh agent. If this repeats across runs, a maintainer should inspect the reviewer token and Task 3 logs.


📱 UI Tests — CollectionView

Detected UI test categories: CollectionView

[!WARNING]
No UI test results were produced for the detected categories. The PR build itself was
fine — the deep UI stage was skipped or interrupted on infrastructure (the
merge-for-testing step, emulator/simulator boot, or an Appium hang), not by this PR's code.
This is usually transient; the review re-runs on new commits (a maintainer can also re-run it).


🧭 Next Steps — review latest findings

No alternative fix was selected for this run. Review the session findings and CI results before merging.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Oct 7, 2026
kubaflo added a commit that referenced this pull request Oct 13, 2026
…apter's (#39193)

### Description of Change

On Android, a `CollectionView` that has an `EmptyView` can show the
wrong views after its items are cleared and loaded again a few times.
The empty view, header or footer can show up in place of items. The
reporter's repro breaks after 9 reloads. In the test below, it breaks
after the first reload.

**Root cause**

`MauiRecyclerView` swaps the `RecyclerView` between `EmptyViewAdapter`
and the items adapter. The two adapters take their view holders from the
same `RecycledViewPool`. The pool is cleared before each `SwapAdapter`,
but `SwapAdapter(…, true)` puts the old adapter's view holders back into
it.

`EmptyViewAdapter` starts its view types at 1, 2 and 3. Every `Header`,
`HeaderTemplate`, `Footer`, `FooterTemplate`, `EmptyView` and
`EmptyViewTemplate` set increments one of them, and `UpdateEmptyView`
sets all six each time it runs. So the values grow into the view types
of the items adapter: `ItemViewType` (41–46) and `DataTemplate` ids
(from 101).

When two view types match, `RecyclerView` binds a view holder of one
adapter in the other one. In the test, the empty adapter's empty-view
holder (view type 44) ends up in the footer position
(`ItemViewType.Footer`). Separately, the header type (`1 + 2n`) reaches
the footer's earlier values (`3 + 2n`), so even inside
`EmptyViewAdapter` the header can reuse an old footer holder.

**Fix**

All view types of `EmptyViewAdapter` now come from one counter that
counts down from -2 (-1 is `RecyclerView.INVALID_TYPE`).
- The items adapter's view types are all positive, so the two adapters
can't share a view type.
- No view type is reused, so header, empty view and footer can't match
each other either.
- Each property set still gets a new view type. That still forces
`OnCreateViewHolder` when the `EmptyView` changes.
`GridLayoutSpanSizeLookup` already assumes these view types never match
`ItemViewType`, which is now true.

#34208 tried to make the values smaller and closed itself after #34452
added the pool clearing. Making the view types constant doesn't work
here: the empty view would then reuse its old view holder when the
`EmptyView` changes.

`EmptyViewAdapter` is identical on `net11.0`, and the test fails there
without the fix as well.

**Tests**


`CollectionViewTests.ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace`
(Controls.DeviceTests, Android) uses a `CollectionView` with a header, a
footer, an `EmptyView` and an `ItemTemplate`. It sets `ItemsSource` to
`null` and back 30 times. After each step, it checks the view holder at
every position.

| | Without fix | With fix |
|---|---|---|
| `ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace` | Fails:
`Reload 1: position 4 should show Footer, but shows Empty (view type
44)` | Passes |

On `main` (84b1fb3) and an API 37 emulator, the test fails without the
fix with the message above and passes with it. With the fix:
- Controls.DeviceTests `CollectionView`: 57 passed, 1 skipped.
- Controls.DeviceTests `CarouselView`: 10/10 passed.

The same holds on `net11.0` (0b038e7).

### Issues Fixed

Fixes #34207

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Oct 14, 2026
…apter's (#39193)

### Description of Change

On Android, a `CollectionView` that has an `EmptyView` can show the
wrong views after its items are cleared and loaded again a few times.
The empty view, header or footer can show up in place of items. The
reporter's repro breaks after 9 reloads. In the test below, it breaks
after the first reload.

**Root cause**

`MauiRecyclerView` swaps the `RecyclerView` between `EmptyViewAdapter`
and the items adapter. The two adapters take their view holders from the
same `RecycledViewPool`. The pool is cleared before each `SwapAdapter`,
but `SwapAdapter(…, true)` puts the old adapter's view holders back into
it.

`EmptyViewAdapter` starts its view types at 1, 2 and 3. Every `Header`,
`HeaderTemplate`, `Footer`, `FooterTemplate`, `EmptyView` and
`EmptyViewTemplate` set increments one of them, and `UpdateEmptyView`
sets all six each time it runs. So the values grow into the view types
of the items adapter: `ItemViewType` (41–46) and `DataTemplate` ids
(from 101).

When two view types match, `RecyclerView` binds a view holder of one
adapter in the other one. In the test, the empty adapter's empty-view
holder (view type 44) ends up in the footer position
(`ItemViewType.Footer`). Separately, the header type (`1 + 2n`) reaches
the footer's earlier values (`3 + 2n`), so even inside
`EmptyViewAdapter` the header can reuse an old footer holder.

**Fix**

All view types of `EmptyViewAdapter` now come from one counter that
counts down from -2 (-1 is `RecyclerView.INVALID_TYPE`).
- The items adapter's view types are all positive, so the two adapters
can't share a view type.
- No view type is reused, so header, empty view and footer can't match
each other either.
- Each property set still gets a new view type. That still forces
`OnCreateViewHolder` when the `EmptyView` changes.
`GridLayoutSpanSizeLookup` already assumes these view types never match
`ItemViewType`, which is now true.

#34208 tried to make the values smaller and closed itself after #34452
added the pool clearing. Making the view types constant doesn't work
here: the empty view would then reuse its old view holder when the
`EmptyView` changes.

`EmptyViewAdapter` is identical on `net11.0`, and the test fails there
without the fix as well.

**Tests**


`CollectionViewTests.ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace`
(Controls.DeviceTests, Android) uses a `CollectionView` with a header, a
footer, an `EmptyView` and an `ItemTemplate`. It sets `ItemsSource` to
`null` and back 30 times. After each step, it checks the view holder at
every position.

| | Without fix | With fix |
|---|---|---|
| `ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace` | Fails:
`Reload 1: position 4 should show Footer, but shows Empty (view type
44)` | Passes |

On `main` (84b1fb3) and an API 37 emulator, the test fails without the
fix with the message above and passes with it. With the fix:
- Controls.DeviceTests `CollectionView`: 57 passed, 1 skipped.
- Controls.DeviceTests `CarouselView`: 10/10 passed.

The same holds on `net11.0` (0b038e7).

### Issues Fixed

Fixes #34207

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Oct 18, 2026
…apter's (#39193)

### Description of Change

On Android, a `CollectionView` that has an `EmptyView` can show the
wrong views after its items are cleared and loaded again a few times.
The empty view, header or footer can show up in place of items. The
reporter's repro breaks after 9 reloads. In the test below, it breaks
after the first reload.

**Root cause**

`MauiRecyclerView` swaps the `RecyclerView` between `EmptyViewAdapter`
and the items adapter. The two adapters take their view holders from the
same `RecycledViewPool`. The pool is cleared before each `SwapAdapter`,
but `SwapAdapter(…, true)` puts the old adapter's view holders back into
it.

`EmptyViewAdapter` starts its view types at 1, 2 and 3. Every `Header`,
`HeaderTemplate`, `Footer`, `FooterTemplate`, `EmptyView` and
`EmptyViewTemplate` set increments one of them, and `UpdateEmptyView`
sets all six each time it runs. So the values grow into the view types
of the items adapter: `ItemViewType` (41–46) and `DataTemplate` ids
(from 101).

When two view types match, `RecyclerView` binds a view holder of one
adapter in the other one. In the test, the empty adapter's empty-view
holder (view type 44) ends up in the footer position
(`ItemViewType.Footer`). Separately, the header type (`1 + 2n`) reaches
the footer's earlier values (`3 + 2n`), so even inside
`EmptyViewAdapter` the header can reuse an old footer holder.

**Fix**

All view types of `EmptyViewAdapter` now come from one counter that
counts down from -2 (-1 is `RecyclerView.INVALID_TYPE`).
- The items adapter's view types are all positive, so the two adapters
can't share a view type.
- No view type is reused, so header, empty view and footer can't match
each other either.
- Each property set still gets a new view type. That still forces
`OnCreateViewHolder` when the `EmptyView` changes.
`GridLayoutSpanSizeLookup` already assumes these view types never match
`ItemViewType`, which is now true.

#34208 tried to make the values smaller and closed itself after #34452
added the pool clearing. Making the view types constant doesn't work
here: the empty view would then reuse its old view holder when the
`EmptyView` changes.

`EmptyViewAdapter` is identical on `net11.0`, and the test fails there
without the fix as well.

**Tests**


`CollectionViewTests.ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace`
(Controls.DeviceTests, Android) uses a `CollectionView` with a header, a
footer, an `EmptyView` and an `ItemTemplate`. It sets `ItemsSource` to
`null` and back 30 times. After each step, it checks the view holder at
every position.

| | Without fix | With fix |
|---|---|---|
| `ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace` | Fails:
`Reload 1: position 4 should show Footer, but shows Empty (view type
44)` | Passes |

On `main` (84b1fb3) and an API 37 emulator, the test fails without the
fix with the message above and passes with it. With the fix:
- Controls.DeviceTests `CollectionView`: 57 passed, 1 skipped.
- Controls.DeviceTests `CarouselView`: 10/10 passed.

The same holds on `net11.0` (0b038e7).

### Issues Fixed

Fixes #34207

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Oct 21, 2026
…apter's (#39193)

### Description of Change

On Android, a `CollectionView` that has an `EmptyView` can show the
wrong views after its items are cleared and loaded again a few times.
The empty view, header or footer can show up in place of items. The
reporter's repro breaks after 9 reloads. In the test below, it breaks
after the first reload.

**Root cause**

`MauiRecyclerView` swaps the `RecyclerView` between `EmptyViewAdapter`
and the items adapter. The two adapters take their view holders from the
same `RecycledViewPool`. The pool is cleared before each `SwapAdapter`,
but `SwapAdapter(…, true)` puts the old adapter's view holders back into
it.

`EmptyViewAdapter` starts its view types at 1, 2 and 3. Every `Header`,
`HeaderTemplate`, `Footer`, `FooterTemplate`, `EmptyView` and
`EmptyViewTemplate` set increments one of them, and `UpdateEmptyView`
sets all six each time it runs. So the values grow into the view types
of the items adapter: `ItemViewType` (41–46) and `DataTemplate` ids
(from 101).

When two view types match, `RecyclerView` binds a view holder of one
adapter in the other one. In the test, the empty adapter's empty-view
holder (view type 44) ends up in the footer position
(`ItemViewType.Footer`). Separately, the header type (`1 + 2n`) reaches
the footer's earlier values (`3 + 2n`), so even inside
`EmptyViewAdapter` the header can reuse an old footer holder.

**Fix**

All view types of `EmptyViewAdapter` now come from one counter that
counts down from -2 (-1 is `RecyclerView.INVALID_TYPE`).
- The items adapter's view types are all positive, so the two adapters
can't share a view type.
- No view type is reused, so header, empty view and footer can't match
each other either.
- Each property set still gets a new view type. That still forces
`OnCreateViewHolder` when the `EmptyView` changes.
`GridLayoutSpanSizeLookup` already assumes these view types never match
`ItemViewType`, which is now true.

#34208 tried to make the values smaller and closed itself after #34452
added the pool clearing. Making the view types constant doesn't work
here: the empty view would then reuse its old view holder when the
`EmptyView` changes.

`EmptyViewAdapter` is identical on `net11.0`, and the test fails there
without the fix as well.

**Tests**


`CollectionViewTests.ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace`
(Controls.DeviceTests, Android) uses a `CollectionView` with a header, a
footer, an `EmptyView` and an `ItemTemplate`. It sets `ItemsSource` to
`null` and back 30 times. After each step, it checks the view holder at
every position.

| | Without fix | With fix |
|---|---|---|
| `ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace` | Fails:
`Reload 1: position 4 should show Footer, but shows Empty (view type
44)` | Passes |

On `main` (84b1fb3) and an API 37 emulator, the test fails without the
fix with the message above and passes with it. With the fix:
- Controls.DeviceTests `CollectionView`: 57 passed, 1 skipped.
- Controls.DeviceTests `CarouselView`: 10/10 passed.

The same holds on `net11.0` (0b038e7).

### Issues Fixed

Fixes #34207

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Oct 25, 2026
…apter's (#39193)

### Description of Change

On Android, a `CollectionView` that has an `EmptyView` can show the
wrong views after its items are cleared and loaded again a few times.
The empty view, header or footer can show up in place of items. The
reporter's repro breaks after 9 reloads. In the test below, it breaks
after the first reload.

**Root cause**

`MauiRecyclerView` swaps the `RecyclerView` between `EmptyViewAdapter`
and the items adapter. The two adapters take their view holders from the
same `RecycledViewPool`. The pool is cleared before each `SwapAdapter`,
but `SwapAdapter(…, true)` puts the old adapter's view holders back into
it.

`EmptyViewAdapter` starts its view types at 1, 2 and 3. Every `Header`,
`HeaderTemplate`, `Footer`, `FooterTemplate`, `EmptyView` and
`EmptyViewTemplate` set increments one of them, and `UpdateEmptyView`
sets all six each time it runs. So the values grow into the view types
of the items adapter: `ItemViewType` (41–46) and `DataTemplate` ids
(from 101).

When two view types match, `RecyclerView` binds a view holder of one
adapter in the other one. In the test, the empty adapter's empty-view
holder (view type 44) ends up in the footer position
(`ItemViewType.Footer`). Separately, the header type (`1 + 2n`) reaches
the footer's earlier values (`3 + 2n`), so even inside
`EmptyViewAdapter` the header can reuse an old footer holder.

**Fix**

All view types of `EmptyViewAdapter` now come from one counter that
counts down from -2 (-1 is `RecyclerView.INVALID_TYPE`).
- The items adapter's view types are all positive, so the two adapters
can't share a view type.
- No view type is reused, so header, empty view and footer can't match
each other either.
- Each property set still gets a new view type. That still forces
`OnCreateViewHolder` when the `EmptyView` changes.
`GridLayoutSpanSizeLookup` already assumes these view types never match
`ItemViewType`, which is now true.

#34208 tried to make the values smaller and closed itself after #34452
added the pool clearing. Making the view types constant doesn't work
here: the empty view would then reuse its old view holder when the
`EmptyView` changes.

`EmptyViewAdapter` is identical on `net11.0`, and the test fails there
without the fix as well.

**Tests**


`CollectionViewTests.ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace`
(Controls.DeviceTests, Android) uses a `CollectionView` with a header, a
footer, an `EmptyView` and an `ItemTemplate`. It sets `ItemsSource` to
`null` and back 30 times. After each step, it checks the view holder at
every position.

| | Without fix | With fix |
|---|---|---|
| `ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace` | Fails:
`Reload 1: position 4 should show Footer, but shows Empty (view type
44)` | Passes |

On `main` (84b1fb3) and an API 37 emulator, the test fails without the
fix with the message above and passes with it. With the fix:
- Controls.DeviceTests `CollectionView`: 57 passed, 1 skipped.
- Controls.DeviceTests `CarouselView`: 10/10 passed.

The same holds on `net11.0` (0b038e7).

### Issues Fixed

Fixes #34207

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Oct 26, 2026
…apter's (#39193)

### Description of Change

On Android, a `CollectionView` that has an `EmptyView` can show the
wrong views after its items are cleared and loaded again a few times.
The empty view, header or footer can show up in place of items. The
reporter's repro breaks after 9 reloads. In the test below, it breaks
after the first reload.

**Root cause**

`MauiRecyclerView` swaps the `RecyclerView` between `EmptyViewAdapter`
and the items adapter. The two adapters take their view holders from the
same `RecycledViewPool`. The pool is cleared before each `SwapAdapter`,
but `SwapAdapter(…, true)` puts the old adapter's view holders back into
it.

`EmptyViewAdapter` starts its view types at 1, 2 and 3. Every `Header`,
`HeaderTemplate`, `Footer`, `FooterTemplate`, `EmptyView` and
`EmptyViewTemplate` set increments one of them, and `UpdateEmptyView`
sets all six each time it runs. So the values grow into the view types
of the items adapter: `ItemViewType` (41–46) and `DataTemplate` ids
(from 101).

When two view types match, `RecyclerView` binds a view holder of one
adapter in the other one. In the test, the empty adapter's empty-view
holder (view type 44) ends up in the footer position
(`ItemViewType.Footer`). Separately, the header type (`1 + 2n`) reaches
the footer's earlier values (`3 + 2n`), so even inside
`EmptyViewAdapter` the header can reuse an old footer holder.

**Fix**

All view types of `EmptyViewAdapter` now come from one counter that
counts down from -2 (-1 is `RecyclerView.INVALID_TYPE`).
- The items adapter's view types are all positive, so the two adapters
can't share a view type.
- No view type is reused, so header, empty view and footer can't match
each other either.
- Each property set still gets a new view type. That still forces
`OnCreateViewHolder` when the `EmptyView` changes.
`GridLayoutSpanSizeLookup` already assumes these view types never match
`ItemViewType`, which is now true.

#34208 tried to make the values smaller and closed itself after #34452
added the pool clearing. Making the view types constant doesn't work
here: the empty view would then reuse its old view holder when the
`EmptyView` changes.

`EmptyViewAdapter` is identical on `net11.0`, and the test fails there
without the fix as well.

**Tests**


`CollectionViewTests.ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace`
(Controls.DeviceTests, Android) uses a `CollectionView` with a header, a
footer, an `EmptyView` and an `ItemTemplate`. It sets `ItemsSource` to
`null` and back 30 times. After each step, it checks the view holder at
every position.

| | Without fix | With fix |
|---|---|---|
| `ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace` | Fails:
`Reload 1: position 4 should show Footer, but shows Empty (view type
44)` | Passes |

On `main` (84b1fb3) and an API 37 emulator, the test fails without the
fix with the message above and passes with it. With the fix:
- Controls.DeviceTests `CollectionView`: 57 passed, 1 skipped.
- Controls.DeviceTests `CarouselView`: 10/10 passed.

The same holds on `net11.0` (0b038e7).

### Issues Fixed

Fixes #34207

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
github-actions Bot pushed a commit that referenced this pull request Oct 28, 2026
…apter's (#39193)

### Description of Change

On Android, a `CollectionView` that has an `EmptyView` can show the
wrong views after its items are cleared and loaded again a few times.
The empty view, header or footer can show up in place of items. The
reporter's repro breaks after 9 reloads. In the test below, it breaks
after the first reload.

**Root cause**

`MauiRecyclerView` swaps the `RecyclerView` between `EmptyViewAdapter`
and the items adapter. The two adapters take their view holders from the
same `RecycledViewPool`. The pool is cleared before each `SwapAdapter`,
but `SwapAdapter(…, true)` puts the old adapter's view holders back into
it.

`EmptyViewAdapter` starts its view types at 1, 2 and 3. Every `Header`,
`HeaderTemplate`, `Footer`, `FooterTemplate`, `EmptyView` and
`EmptyViewTemplate` set increments one of them, and `UpdateEmptyView`
sets all six each time it runs. So the values grow into the view types
of the items adapter: `ItemViewType` (41–46) and `DataTemplate` ids
(from 101).

When two view types match, `RecyclerView` binds a view holder of one
adapter in the other one. In the test, the empty adapter's empty-view
holder (view type 44) ends up in the footer position
(`ItemViewType.Footer`). Separately, the header type (`1 + 2n`) reaches
the footer's earlier values (`3 + 2n`), so even inside
`EmptyViewAdapter` the header can reuse an old footer holder.

**Fix**

All view types of `EmptyViewAdapter` now come from one counter that
counts down from -2 (-1 is `RecyclerView.INVALID_TYPE`).
- The items adapter's view types are all positive, so the two adapters
can't share a view type.
- No view type is reused, so header, empty view and footer can't match
each other either.
- Each property set still gets a new view type. That still forces
`OnCreateViewHolder` when the `EmptyView` changes.
`GridLayoutSpanSizeLookup` already assumes these view types never match
`ItemViewType`, which is now true.

#34208 tried to make the values smaller and closed itself after #34452
added the pool clearing. Making the view types constant doesn't work
here: the empty view would then reuse its old view holder when the
`EmptyView` changes.

`EmptyViewAdapter` is identical on `net11.0`, and the test fails there
without the fix as well.

**Tests**


`CollectionViewTests.ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace`
(Controls.DeviceTests, Android) uses a `CollectionView` with a header, a
footer, an `EmptyView` and an `ItemTemplate`. It sets `ItemsSource` to
`null` and back 30 times. After each step, it checks the view holder at
every position.

| | Without fix | With fix |
|---|---|---|
| `ReloadingItemsWithEmptyViewKeepsHeaderFooterAndItemsInPlace` | Fails:
`Reload 1: position 4 should show Footer, but shows Empty (view type
44)` | Passes |

On `main` (84b1fb3) and an API 37 emulator, the test fails without the
fix with the message above and passes with it. With the fix:
- Controls.DeviceTests `CollectionView`: 57 passed, 1 skipped.
- Controls.DeviceTests `CarouselView`: 10/10 passed.

The same holds on `net11.0` (0b038e7).

### Issues Fixed

Fixes #34207

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-review-incomplete AI review did not complete all expected phases s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] CollectionView with an EmptyView or EmptyViewTemplate gets potentially corrupted after being cleared and repopulated a number of times

4 participants