Skip to content

Conversation

@MitchBodmer
Copy link
Contributor

  • Make FilePatternMatch.Stem non-nullable.
  • Add an ArgumentNullException if stem is null in Success method.
  • Add tests for null checks.

Implements #116982

- Add an ArgumentNullException if stem is null in Success method.
- Add tests for null checks.
Copilot AI review requested due to automatic review settings August 5, 2025 21:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request makes the FilePatternMatch.Stem property non-nullable to improve type safety. The change ensures that the Stem property always has a valid string value, preventing potential null reference exceptions when consumers use this property.

Key changes:

  • Converted Stem property from nullable string to non-nullable string
  • Added null validation in the constructor to enforce the contract
  • Added comprehensive tests to verify null argument validation

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
FilePatternMatch.cs Changed Stem property to non-nullable and added null validation in constructor
PatternTestResult.cs Added MemberNotNullWhen attribute to support nullable analysis when IsSuccessful is true
FilePatternMatchTests.cs Added unit tests to verify ArgumentNullException is thrown for null path and stem parameters
Comments suppressed due to low confidence (2)

src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/FilePatternMatchTests.cs:32

  • The test should verify that the exception is thrown for the correct parameter name. Consider using Assert.Throws("path", () => new FilePatternMatch(null, "sub2/bar/baz/three.txt")) to ensure the parameter name is validated.
            Assert.Throws<ArgumentNullException>(() => new FilePatternMatch(null, "sub2/bar/baz/three.txt"));

src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/FilePatternMatchTests.cs:38

  • The test should verify that the exception is thrown for the correct parameter name. Consider using Assert.Throws("stem", () => new FilePatternMatch("sub2/bar/baz/three.txt", null)) to ensure the parameter name is validated.
            Assert.Throws<ArgumentNullException>(() => new FilePatternMatch("sub2/bar/baz/three.txt", null));

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Aug 5, 2025
@MitchBodmer
Copy link
Contributor Author

@dotnet-policy-service agree company="Microsoft"

Copy link
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me; thanks, @MitchBodmer! I will mark this as a breaking-change Issue or PR that represents a breaking API or functional change over a previous release. and create the documentation issue.

@jeffhandley jeffhandley added the breaking-change Issue or PR that represents a breaking API or functional change over a previous release. label Aug 5, 2025
@dotnet-policy-service
Copy link
Contributor

Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this PR and the issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET Breaking Change Notification DL.

Tagging @dotnet/compat for awareness of the breaking change.

@dotnet-policy-service dotnet-policy-service bot added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Aug 5, 2025
@MitchBodmer
Copy link
Contributor Author

@jeffhandley it looks like the build hit some unrelated failures. Is there something I should do here?

@jeffhandley
Copy link
Member

Thanks, @MitchBodmer. No worries; I'll review the failures further and the build analysis shortly and will update the build analysis with the justification for override, and then I'll merge this after I create the breaking-change notification. I'll let you know if I need anything further from you on it. Thanks for the contribution!

@jeffhandley
Copy link
Member

Breaking change documentation issue created: [Breaking change]: FilePatternMatch.Stem annotated as non-nullable (dotnet/docs#47914). PR is pending review from @artl93 for .NET 10 RC1 consideration.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Extensions-FileSystem breaking-change Issue or PR that represents a breaking API or functional change over a previous release. community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants