-
Notifications
You must be signed in to change notification settings - Fork 69
fix string comparison structs crash when compared with default values #432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/Microsoft.Performance.SDK.Tests/StringWithCaseInsensitiveComparisonTests.cs
Outdated
Show resolved
Hide resolved
helenkzhang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with suggestions
d9e9f59 to
2d21c03
Compare
There was a problem hiding this 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 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.
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