Skip to content

ConcurrentStack.PushRange(T[]) throws an ArgumentOutOfRangeException on empty T[] #62121

Closed
@megazyz

Description

@megazyz

Description

ConcurrentStack<T>.PushRange(T[]) throws an ArgumentOutOfRangeException when T[] is an empty array. The exception message is 'The startIndex argument must be greater than or equal to zero.'.

  • This behavior is not documented
  • It should do nothing instead of throwing an exception, like List<T>.AddRange(IEnumerable<T>) does

Reproduction 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 calling ConcurrentStack<T>.PushRange(T[]).

Configuration

.NET 6.0.100

Other information

No response

Metadata

Metadata

Labels

area-System.CollectionsenhancementProduct code improvement that does NOT require public API changes/additions

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions