Skip to content

Collection<T>.AddRange should validate its parameters #12784

@justinvp

Description

@justinvp

I missed this in dotnet/coreclr#23166. Current it's defined as:

https://github.com/dotnet/coreclr/blob/b8d5b7b760f64d39e00554189ea0e5c66ed6bd62/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs#L72

But it should be something like:

public void AddRange(IEnumerable<T> collection)
{
    if (items.IsReadOnly)
    {
        ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
    }

    if (collection == null)
    {
        ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
    }

    int index = items.Count;
    InsertItemsRange(index, collection!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions