Skip to content

Fixed bug where IPickerExtension.GetItemsAsList() would always return an empty list#31879

Merged
jfversluis merged 3 commits intodotnet:inflight/currentfrom
lothrop:fix/picker-extension-empty-list
Oct 20, 2025
Merged

Fixed bug where IPickerExtension.GetItemsAsList() would always return an empty list#31879
jfversluis merged 3 commits intodotnet:inflight/currentfrom
lothrop:fix/picker-extension-empty-list

Conversation

@lothrop
Copy link
Contributor

@lothrop lothrop commented Oct 6, 2025

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!

Description of Change

The existing code assumes the constructor of List<T> that takes an int will create a list of that size. In reality, it creates a list of size 0 with a capacity of the provided number. The change fixes this by calling Add() for each new element.

Issues Fixed

Fixes #31878

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Oct 6, 2025
@lothrop lothrop changed the title Fixed bug where IPickerExtensions.GetItemsAsList() would always return an empty list Fixed bug where IPickerExtension.GetItemsAsList() would always return an empty list Oct 6, 2025
@MartyIX
Copy link
Contributor

MartyIX commented Oct 6, 2025

Would it be possible to add a unit test for this? Great catch!

@lothrop
Copy link
Contributor Author

lothrop commented Oct 6, 2025 via email

@lothrop
Copy link
Contributor Author

lothrop commented Oct 7, 2025

I couldn't get the unit tests to execute locally. Will Github run them and report failures?

@MartyIX
Copy link
Contributor

MartyIX commented Oct 7, 2025

I couldn't get the unit tests to execute locally. Will Github run them and report failures?

@rmarinho will know. I'm not sure.

But one can check an older PR like https://github.com/dotnet/maui/pull/31831/checks and see if the AZP contains logs for passed tests for the similar category.

I can see here https://dev.azure.com/xamarin/public/_build/results?buildId=151456&view=ms.vss-test-web.build-test-results-tab:

image

that one can select "Passed" tests:

image

@rmarinho rmarinho requested a review from jsuarezruiz October 7, 2025 13:32
@rmarinho
Copy link
Member

rmarinho commented Oct 7, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@lothrop
Copy link
Contributor Author

lothrop commented Oct 7, 2025

/azp run

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 31879 in repo dotnet/maui

@lothrop
Copy link
Contributor Author

lothrop commented Oct 7, 2025

I couldn't get the unit tests to execute locally. Will Github run them and report failures?

@rmarinho will know. I'm not sure.

The build did run the unit tests and they failed: https://dev.azure.com/xamarin/public/_build/results?buildId=151620&view=ms.vss-test-web.build-test-results-tab

@lothrop
Copy link
Contributor Author

lothrop commented Oct 7, 2025

Looks like someone else will need to trigger the build.

@lothrop
Copy link
Contributor Author

lothrop commented Oct 8, 2025

@rmarinho?

@jfversluis
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jfversluis jfversluis added this to the .NET 9 SR12 milestone Oct 8, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR12, .NET 10 SR1 Oct 8, 2025
@jfversluis jfversluis moved this from Todo to Ready To Review in MAUI SDK Ongoing Oct 9, 2025
@lothrop
Copy link
Contributor Author

lothrop commented Oct 9, 2025

Not sure if those failing UI tests have anything to do with my changes.

@jfversluis
Copy link
Member

Not sure if those failing UI tests have anything to do with my changes.

Probably not :) so no worries

@lothrop
Copy link
Contributor Author

lothrop commented Oct 20, 2025

@jfversluis Could you please do a review?

jfversluis
jfversluis previously approved these changes Oct 20, 2025
@github-project-automation github-project-automation bot moved this from Ready To Review to Approved in MAUI SDK Ongoing Oct 20, 2025
@jfversluis jfversluis changed the base branch from main to inflight/current October 20, 2025 13:32
@jfversluis jfversluis changed the base branch from inflight/current to main October 20, 2025 13:33
@jfversluis jfversluis dismissed their stale review October 20, 2025 13:33

The base branch was changed.

@jfversluis jfversluis requested a review from Copilot October 20, 2025 13:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug in IPickerExtension.GetItemsAsList() where the method would always return an empty list due to a misunderstanding of the List<T>(int) constructor. The constructor sets the list's capacity but not its size, so the loop that tried to assign items by index never executed. The fix changes the implementation to use Add() to properly populate the list.

Key changes:

  • Fixed the GetItemsAsList() implementation to use Add() instead of index assignment
  • Added comprehensive unit tests to verify both GetItemsAsArray() and GetItemsAsList() work correctly
  • Added a new test category for Extensions tests

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Core/src/Core/Extensions/IPickerExtension.cs Fixed the bug by using Add() instead of index assignment and removed unused System.Linq import
src/Core/tests/UnitTests/Extensions/IPickerExtensionTests.cs Added new test file with comprehensive test coverage for both extension methods
src/Core/tests/UnitTests/TestCategory.cs Added "Extensions" test category constant

@jfversluis
Copy link
Member

jfversluis commented Oct 20, 2025

Hold on... I see a new test category, but not added in all the right places. So this test probably didn't even run yet.

I was hoping Copilot would pick that up, but guess it didn't 😄

Nope, I'm confused with UI tests, ignore me. Carry on! Kerry on? 🤔

@jfversluis jfversluis changed the base branch from main to inflight/current October 20, 2025 13:36
@jfversluis jfversluis merged commit 4a5f98b into dotnet:inflight/current Oct 20, 2025
126 of 129 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Oct 20, 2025
PureWeen pushed a commit that referenced this pull request Oct 30, 2025
… an empty list (#31879)

* Fixed bug where IPickerExtensions.GetItemsAsList() would always return an empty list.

* Added unit tests for IPickerExtension.

* Fixed unit tests.
github-actions bot pushed a commit that referenced this pull request Nov 4, 2025
… an empty list (#31879)

* Fixed bug where IPickerExtensions.GetItemsAsList() would always return an empty list.

* Added unit tests for IPickerExtension.

* Fixed unit tests.
@github-actions github-actions bot locked and limited conversation to collaborators Nov 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-picker Picker community ✨ Community Contribution

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

IPickerExtension.GetItemsAsList() always returns an empty list

6 participants