Skip to content

Encountering NullReferenceException when the match parameter of ImmutableArray<T>.Builder.RemoveAll is null #125921

@prozolic

Description

@prozolic

Description

When the match parameter of ImmutableArray<T>.Builder.RemoveAll is null, it throws NullReferenceException or no exception instead of ArgumentNullException.

For reference, List<T>.RemoveAll throws ArgumentNullException under the same condition.

var list = new List<int>();
list.RemoveAll(match: null); // ArgumentNullException

Reproduction Steps

var builder = ImmutableArray.CreateBuilder<int>();
builder.RemoveAll(null);  // no exception
var builder = ImmutableArray.CreateBuilder<int>();
builder.Add(1);
builder.RemoveAll(null);  // NullReferenceException

Expected behavior

ArgumentNullException is thrown.

Actual behavior

  • When Count == 0: no exception.
  • When Count > 0: NullReferenceException is thrown.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

A fix has been submitted in #125920.
This fix is a potential Bucket 2 breaking change per the breaking change guidelines.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions