[release/10.0-rc2] Fix DefaultIfEmptyIterator.TryGetElementAt returning default value for out-of-bounds indices #120003
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #119838 to release/10.0-rc2
/cc @jeffhandley @eiriktsarpalis
Customer Impact
Customer reported in:
DefaultIfEmptyIterator<TSource>.TryGetElementAtreturns_defaultwhen not found (dotnet/runtime#119834).NET 9 regressed the behavior of the
DefaultIfEmptyLINQ method resulting in incorrect results when chained withElementAtOrDefaultusing an out of bounds index. This fix has been applied to .NET 11, .NET 10 GA, and .NET 9 Servicing (for the October servicing release). Therelease/10.0PR didn't get merged before the RC2 snap, but we should include this fix in RC2 so that 10.0 RC2 and 9.0 servicing are aligned in behavior.Regression
The regression was introduced in Consolidate LINQ's internal IIListProvider/IPartition into base Iterator class (#98969).
Testing
Added unit testing verifying the impacted behavior.
Risk
Low. Applies a straightforward fix to a simple bug.