Skip to content

Conversation

@xj-ms
Copy link
Contributor

@xj-ms xj-ms commented Dec 10, 2025

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

helenkzhang
helenkzhang previously approved these changes Dec 10, 2025
Copy link
Contributor

@helenkzhang helenkzhang left a comment

Choose a reason for hiding this comment

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

Approved with suggestions

Copy link

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 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.

@xj-ms xj-ms merged commit 4172f89 into main Dec 11, 2025
11 checks passed
@xj-ms xj-ms deleted the user/jing/string-comparison branch December 11, 2025 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants