Skip to content

Commit 965e56e

Browse files
authored
Add breaking change documentation for FilePatternMatch.Stem nullability change (#48285)
1 parent c82a45d commit 965e56e

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

docs/core/compatibility/10.0.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
4545
| [Default trace context propagator updated to W3C standard](core-libraries/10.0/default-trace-context-propagator.md) | Behavioral change | Preview 4 |
4646
| [DriveInfo.DriveFormat returns Linux filesystem types](core-libraries/10.0/driveinfo-driveformat-linux.md) | Behavioral change | Preview 6 |
4747
| [DynamicallyAccessedMembers annotation removed from DefaultValueAttribute ctor](core-libraries/10.0/defaultvalueattribute-dynamically-accessed-members.md) | Binary/source incompatible | Preview 7 |
48+
| [Explicit struct Size disallowed with InlineArray](core-libraries/10.0/inlinearray-explicit-size-disallowed.md) | Binary incompatible | Preview 7 |
49+
| [FilePatternMatch.Stem changed to non-nullable](core-libraries/10.0/filepatternmatch-stem-nonnullable.md) | Source incompatible/behavioral change | RC 1 |
4850
| [GnuTarEntry and PaxTarEntry no longer includes atime and ctime by default](core-libraries/10.0/tar-atime-ctime-default.md) | Behavioral change | Preview 5 |
4951
| [LDAP DirectoryControl parsing is now more stringent](core-libraries/10.0/ldap-directorycontrol-parsing.md) | Behavioral change | Preview 1 |
5052
| [MacCatalyst version normalization](core-libraries/10.0/maccatalyst-version-normalization.md) | Behavioral change | Preview 1 |
5153
| [.NET runtime no longer provides default termination signal handlers](core-libraries/10.0/sigterm-signal-handler.md) | Behavioral change | Preview 5 |
52-
| [Explicit struct Size disallowed with InlineArray](core-libraries/10.0/inlinearray-explicit-size-disallowed.md) | Binary incompatible | Preview 7 |
5354
| [System.Linq.AsyncEnumerable included in core libraries](core-libraries/10.0/asyncenumerable.md) | Source incompatible | Preview 1 |
5455
| [YMM embedded rounding removed from AVX10.2](core-libraries/10.0/ymm-embedded-rounding.md) | Behavioral change | Preview 5 |
5556

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: "Breaking change - FilePatternMatch.Stem changed to non-nullable"
3+
description: "Learn about the breaking change in .NET 10 where FilePatternMatch.Stem property was changed from nullable to non-nullable."
4+
ms.date: 09/08/2025
5+
ai-usage: ai-assisted
6+
ms.custom: https://github.com/dotnet/docs/issues/47914
7+
---
8+
9+
# FilePatternMatch.Stem changed to non-nullable
10+
11+
The <xref:Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch.Stem?displayProperty=nameWithType> property was previously annotated as nullable because the `PatternTestResult.Stem` property it gets its value from is nullable. While the <xref:Microsoft.Extensions.FileSystemGlobbing.Internal.PatternTestResult> can indeed be null if the result isn't successful, the `FilePatternMatch` never is because it's only constructed when `PatternTestResult` is successful.
12+
13+
To accurately reflect nullability, the `[MemberNotNullWhen()]` attribute is applied to the `PatternTestResult.Stem` property to tell the compiler it won't be null if it's successful. Additionally, the `stem` argument passed into the `FilePatternMatch` constructor is no longer nullable, and an `ArgumentNullException` will be thrown if a null `stem` is passed in.
14+
15+
## Version introduced
16+
17+
.NET 10 RC 1
18+
19+
## Previous behavior
20+
21+
Previously, the <xref:Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch> constructor accepted `null` for the `stem` parameter without any compile-time or run-time warnings or errors.
22+
23+
```csharp
24+
// Allowed in previous versions.
25+
var match = new FilePatternMatch("path/to/file.txt", null);
26+
```
27+
28+
The <xref:Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch.Stem?displayProperty=nameWithType> property was also annotated as being nullable.
29+
30+
## New behavior
31+
32+
Starting in .NET 10, passing a `null` or possibly-null value to the `stem` argument in the <xref:Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch> constructor yields a compile-time warning. And, if `null` is passed in, a run-time <xref:System.ArgumentNullException> is thrown.
33+
34+
The <xref:Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch.Stem?displayProperty=nameWithType> property is now annotated to indicate that the value won't be null if `IsSuccessful` is `true`.
35+
36+
```csharp
37+
// Generates compile-time warning.
38+
var match = new FilePatternMatch("path/to/file.txt", null);
39+
```
40+
41+
## Type of breaking change
42+
43+
This change can affect [source compatibility](../../categories.md#source-compatibility) and is a [behavioral change](../../categories.md#behavioral-change).
44+
45+
## Reason for change
46+
47+
The previous nullability annotations were inaccurate, and a `null` value for the `stem` argument was unexpected but not properly guarded against. This change reflects the expected behavior of the API and guards against unpredictable behavior while also producing design-time guidance around usage.
48+
49+
## Recommended action
50+
51+
If a possibly null value was passed in for the `stem` argument, review usage and update the call site to ensure `stem` can't be paTssed in as `null`.
52+
53+
If you applied nullability warning suppressions when consuming the `FilePatternMatch.Stem` property, you can remove those suppressions.
54+
55+
## Affected APIs
56+
57+
- [FilePatternMatch(String,String) constructor](xref:Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch.%23ctor(System.String,System.String))
58+
- <xref:Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch.Stem?displayProperty=fullName>

docs/core/compatibility/toc.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ items:
4848
href: core-libraries/10.0/driveinfo-driveformat-linux.md
4949
- name: DynamicallyAccessedMembers annotation removed from DefaultValueAttribute ctor
5050
href: core-libraries/10.0/defaultvalueattribute-dynamically-accessed-members.md
51+
- name: Explicit struct Size disallowed with InlineArray
52+
href: core-libraries/10.0/inlinearray-explicit-size-disallowed.md
53+
- name: FilePatternMatch.Stem changed to non-nullable
54+
href: core-libraries/10.0/filepatternmatch-stem-nonnullable.md
5155
- name: GnuTarEntry and PaxTarEntry exclude atime and ctime by default
5256
href: core-libraries/10.0/tar-atime-ctime-default.md
5357
- name: LDAP DirectoryControl parsing is now more stringent
@@ -56,8 +60,6 @@ items:
5660
href: core-libraries/10.0/maccatalyst-version-normalization.md
5761
- name: No default termination signal handlers
5862
href: core-libraries/10.0/sigterm-signal-handler.md
59-
- name: Explicit struct Size disallowed with InlineArray
60-
href: core-libraries/10.0/inlinearray-explicit-size-disallowed.md
6163
- name: System.Linq.AsyncEnumerable included in core libraries
6264
href: core-libraries/10.0/asyncenumerable.md
6365
- name: YMM embedded rounding removed from AVX10.2

0 commit comments

Comments
 (0)