Fix false positive for Equals/CompareTo with nullable reference types#21328
Draft
Fix false positive for Equals/CompareTo with nullable reference types#21328
Conversation
Removes instanceof ObjectType checks from method signatures in System.qll to support nullable reference types (object?). This fixes false positives when Equals(object?) is used instead of Equals(object), as they are the same underlying type with different nullability annotations. Fixes: - SystemIComparableInterface.getCompareToMethod() - SystemObjectClass.getEqualsMethod() - SystemObjectClass.getStaticEqualsMethod() - SystemObjectClass.getReferenceEqualsMethod() Co-authored-by: hvitved <3667920+hvitved@users.noreply.github.com>
Adds test cases for Equals methods with nullable reference type parameters (object?) to verify the fix works correctly. Co-authored-by: hvitved <3667920+hvitved@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix false positive alert for IEquatable Equals implementation
Fix false positive for Equals/CompareTo with nullable reference types
Feb 16, 2026
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.
Problem
CodeQL queries
ClassDoesNotImplementEquals.qlandIncorrectEqualsSignature.qlincorrectly flag classes implementingEquals(object?)as not implementingEquals(object):Changes
Removed redundant
instanceof ObjectTypeparameter type checks from framework method identifiers inSystem.qll:SystemIComparableInterface.getCompareToMethod()SystemObjectClass.getEqualsMethod()SystemObjectClass.getStaticEqualsMethod()SystemObjectClass.getReferenceEqualsMethod()These methods identify specific framework methods where declaring type + method name + parameter count already provide unique identification. The parameter type checks were unnecessary and caused false positives with nullable reference types.
Tests
NullableTest.cswith nullableEqualsimplementationsEquals.csfor nullable patternsOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.