fix string comparison structs crash when compared with default values#432
Merged
fix string comparison structs crash when compared with default values#432
Conversation
helenkzhang
reviewed
Dec 10, 2025
helenkzhang
reviewed
Dec 10, 2025
src/Microsoft.Performance.SDK.Tests/StringWithCaseInsensitiveComparisonTests.cs
Outdated
Show resolved
Hide resolved
helenkzhang
previously approved these changes
Dec 10, 2025
Contributor
helenkzhang
left a comment
There was a problem hiding this comment.
Approved with suggestions
d9e9f59 to
2d21c03
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes null reference exceptions that occur when string comparison structs (StringWithLogicalComparison and StringWithCaseInsensitiveComparison) are used with their default values. These structs serve as column data types in the SDK, and when instantiated via default values (without calling the constructor), their internal string field is null, causing crashes in comparison and ToString operations.
Key Changes:
- Added nullable annotations (
#nullable enable) and marked internal string fields as nullable to properly handle default struct values - Updated ToString() methods to return empty strings when the internal string is null
- Added null pointer checks in the comparison logic to prevent crashes when comparing default values
- Added comprehensive unit tests for both structs covering default value scenarios
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/Microsoft.Performance.SDK/StringWithLogicalComparison.cs |
Enabled nullable reference types, made source field nullable, and updated ToString methods to handle null values |
src/Microsoft.Performance.SDK/StringWithCaseInsensitiveComparison.cs |
Enabled nullable reference types, made source field nullable, and updated ToString methods to handle null values |
src/Microsoft.Performance.SDK/CompareNumericWithExceptionsMethods.cs |
Added null pointer checks at the start of comparison method to safely handle null strings from default struct values |
src/Microsoft.Performance.SDK.Tests/StringWithLogicalComparisonTests.cs |
New test file with comprehensive tests for logical comparison including default value scenarios |
src/Microsoft.Performance.SDK.Tests/StringWithCaseInsensitiveComparisonTests.cs |
New test file with tests for case-insensitive comparison including default value scenarios |
src/Microsoft.Performance.SDK.Tests/AssemblyInfo.cs |
New assembly info file with UnitTest attribute marker |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/Microsoft.Performance.SDK.Tests/StringWithCaseInsensitiveComparisonTests.cs
Show resolved
Hide resolved
src/Microsoft.Performance.SDK.Tests/StringWithCaseInsensitiveComparisonTests.cs
Show resolved
Hide resolved
jmaxson-ms
approved these changes
Dec 11, 2025
helenkzhang
approved these changes
Dec 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The string comparison structs are meant to be used as column data types. When their default values are used, the internal string will be null, which triggers a null reference exception in their comparison logic or ToString.
This PR fixes this issue, adds null annotations and unit tests