Skip to content

Commit b4ad8a5

Browse files
Copilotgewarren
andcommitted
Add FilePatternMatch.Stem breaking change documentation
Co-authored-by: gewarren <[email protected]>
1 parent e7362c3 commit b4ad8a5

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

docs/core/compatibility/10.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
5050
| [MacCatalyst version normalization](core-libraries/10.0/maccatalyst-version-normalization.md) | Behavioral change | Preview 1 |
5151
| [.NET runtime no longer provides default termination signal handlers](core-libraries/10.0/sigterm-signal-handler.md) | Behavioral change | Preview 5 |
5252
| [Explicit struct Size disallowed with InlineArray](core-libraries/10.0/inlinearray-explicit-size-disallowed.md) | Binary incompatible | Preview 7 |
53+
| [FilePatternMatch.Stem changed to non-nullable](core-libraries/10.0/filepatternmatch-stem-nonnullable.md) | Source incompatible/behavioral change | RC 1 |
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: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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: 01/27/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=fullName> property was previously annotated as nullable purely because the `PatternTestResult.Stem` property it gets its value from is nullable. While the `PatternTestResult` can indeed be null if the result is not successful, the `FilePatternMatch` never is because it is only ever constructed when `PatternTestResult` is successful. To accurately reflect nullability, the `FilePatternMatch.Stem` property is now non-nullable and the constructor parameter has been changed accordingly.
12+
13+
## Version introduced
14+
15+
.NET 10 RC 1
16+
17+
## Previous behavior
18+
19+
The <xref:Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch> constructor would accept a `null` for the `stem` parameter without any compile-time or run-time warnings or errors. The <xref:Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch.Stem?displayProperty=fullName> property was also annotated as being nullable (`string?`).
20+
21+
```csharp
22+
// This was allowed in previous versions
23+
var match = new FilePatternMatch("path/to/file.txt", null);
24+
string? stem = match.Stem; // Could be null
25+
```
26+
27+
## New behavior
28+
29+
Passing a `null` or possibly-null value to the `stem` argument in the <xref:Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch> constructor will yield a compile-time warning, and if `null` is passed in, a run-time <xref:System.ArgumentNullException> will be thrown. The <xref:Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch.Stem?displayProperty=fullName> property is now annotated as non-nullable (`string`).
30+
31+
```csharp
32+
// This now throws ArgumentNullException at runtime
33+
var match = new FilePatternMatch("path/to/file.txt", null); // Throws!
34+
35+
// The Stem property is now non-nullable
36+
string stem = match.Stem; // No null check needed
37+
```
38+
39+
## Type of breaking change
40+
41+
This change can affect [source compatibility](../../categories.md#source-compatibility) and is a [behavioral change](../../categories.md#behavioral-change).
42+
43+
## Reason for change
44+
45+
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. The `[MemberNotNullWhen()]` attribute is applied to the `PatternTestResult.Stem` property to tell the compiler it will not be null if it is successful.
46+
47+
## Recommended action
48+
49+
If a possibly-null value was passed in for the `stem` argument, review usage and update the call site to ensure `stem` cannot be passed in as `null`. If nullability warning suppressions were applied when consuming the `FilePatternMatch.Stem` property, such suppressions can be removed.
50+
51+
```csharp
52+
// Before: Check for null
53+
string? stem = match.Stem;
54+
if (stem != null)
55+
{
56+
// Use stem
57+
}
58+
59+
// After: No null check needed
60+
string stem = match.Stem;
61+
// Use stem directly
62+
```
63+
64+
## Affected APIs
65+
66+
- <xref:Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch.%23ctor(System.String,System.String)?displayProperty=fullName>
67+
- <xref:Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch.Stem?displayProperty=fullName>

docs/core/compatibility/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ items:
5858
href: core-libraries/10.0/sigterm-signal-handler.md
5959
- name: Explicit struct Size disallowed with InlineArray
6060
href: core-libraries/10.0/inlinearray-explicit-size-disallowed.md
61+
- name: FilePatternMatch.Stem changed to non-nullable
62+
href: core-libraries/10.0/filepatternmatch-stem-nonnullable.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)