Repository navigation
Java: Detect Objects.equals calls on arrays - #23169
Open
zhangxinyao88 wants to merge 1 commit into
Open
zhangxinyao88 wants to merge 1 commit into
zhangxinyao88 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The PR description lacks DCA results for the final query change, including an assessment of changed results and any unexpected regressions.
1 open issue
What changed in this PR
Extends java/equals-on-arrays to detect identity comparisons through java.util.Objects.equals when both arguments have compatible array types. This addresses the helper-API case in #21547; arrays widened to Object remain outside this change.
Changes:
- Adds detection for compatible array arguments to
Objects.equals. - Adds five positive and nine negative test cases with updated expected results.
- Updates query help and adds a release note.
| File | Description |
|---|---|
java/ql/test/query-tests/EqualsArray/ObjectsEquals.java |
Adds positive and negative helper-API test cases. |
java/ql/test/query-tests/EqualsArray/EqualsArray.expected |
Records five new expected alerts. |
java/ql/src/Likely Bugs/Comparison/EqualsArray.ql |
Detects Objects.equals calls with compatible arrays. |
java/ql/src/Likely Bugs/Comparison/EqualsArray.qhelp |
Documents array identity behavior in Objects.equals. |
java/ql/src/change-notes/2026-11-19-objects-equals-arrays.md |
Announces the expanded query coverage. |
Review effort: Balanced (adaptive)
Comment on lines
+28
to
+30
| m.hasQualifiedName("java.util", "Objects", "equals") and | ||
| recvtype = ma.getArgument(0).getType() and | ||
| haveIntersection(recvtype, ma.getArgument(1).getType().(Array)) |
This branch has not been deployed
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.

Extend
java/equals-on-arraysto reportjava.util.Objects.equalscalls with compatible array arguments. These calls compare object identity, so arrays with equal contents can compare unequal.Addresses the
Objects.equalscase in #21547.Validation with CodeQL CLI 2.27.4 passed the EqualsArray query tests, including five new positive cases and nine negative cases. QL formatting, query-help generation, query-ID and repository consistency checks also passed.