-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConcurrentStack.PushRange(T[]) throws an ArgumentOutOfRangeException on empty T[] #62121
Comments
Tagging subscribers to this area: @dotnet/area-system-collections Issue DetailsDescription
Reproduction Steps
Expected behaviorIt should not throw an exception. Actual behaviorIt throws an ArgumentOutOfRangeException: 'The startIndex argument must be greater than or equal to zero.' Regression?No response Known WorkaroundsCheck the array for Configuration.NET 6.0.100 Other informationNo response
|
Looks like the argument validation happens before the zero length special case: Lines 346 to 350 in 12a8819
which throws because Lines 412 to 416 in 12a8819
|
Proposed fix: #62126 |
* No-op ConcurrentStack.PushRange(T[]) if empty Resolves #62121. * Add more bounds checks Assert that ArgumentOutOfRangeException is thrown if specifying indexes for an empty array with PushRange(T[], int, int). * Review feedback Allow out-of-bounds index on empty array if count is zero. * Add extra test case Add a further test case for a non-empty array but with a count parameter value of zero.
Description
ConcurrentStack<T>.PushRange(T[])
throws an ArgumentOutOfRangeException whenT[]
is an empty array. The exception message is 'The startIndex argument must be greater than or equal to zero.'.List<T>.AddRange(IEnumerable<T>)
doesReproduction Steps
new ConcurrentStack<int>().PushRange(Array.Empty<int>());
Expected behavior
It should not throw an exception.
Actual behavior
It throws an ArgumentOutOfRangeException: 'The startIndex argument must be greater than or equal to zero.'
Regression?
No response
Known Workarounds
Check the array for
Length > 0
before callingConcurrentStack<T>.PushRange(T[])
.Configuration
.NET 6.0.100
Other information
No response
The text was updated successfully, but these errors were encountered: