Skip to content

Java: Detect Objects.equals calls on arrays - #23169

Open
zhangxinyao88 wants to merge 1 commit into
github:mainfrom
zhangxinyao88:codex/java-objects-equals-arrays
Open

zhangxinyao88 wants to merge 1 commit into
github:mainfrom
zhangxinyao88:codex/java-objects-equals-arrays

Conversation

@zhangxinyao88

Copy link
Copy Markdown

Extend java/equals-on-arrays to report java.util.Objects.equals calls with compatible array arguments. These calls compare object identity, so arrays with equal contents can compare unequal.

Addresses the Objects.equals case 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.

@zhangxinyao88
zhangxinyao88 requested a review from a team as a code owner November 19, 2026 06:16
Copilot AI adaptive review requested due to automatic review settings November 19, 2026 06:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants