Skip to content

SONARJAVA-6384 Fix S2160 FP when parent uses EqualsBuilder.reflectionEquals - #5899

Merged
rombirli merged 2 commits into
masterfrom
rombirli/s2160-reflection-equals-fp
Aug 10, 2026
Merged

SONARJAVA-6384 Fix S2160 FP when parent uses EqualsBuilder.reflectionEquals#5899
rombirli merged 2 commits into
masterfrom
rombirli/s2160-reflection-equals-fp

Conversation

@rombirli

@rombirli rombirli commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes false positive on S2160 when a superclass implements equals via Apache Commons Lang EqualsBuilder.reflectionEquals (lang and lang3), which already compares subclass fields by reflection.
  • When the parent equals body is available in the same compilation unit and calls reflectionEquals, the rule no longer asks subclasses to override equals.
  • Cross-file parents (no AST declaration) keep the previous behavior.

Test plan

  • Unit test EqualsNotOverriddenInSubclassCheckTest (lang3 + lang compliant cases; append-only parent still Noncompliant)
  • CI green on this PR

…Equals

Skip the missing-equals issue when a parent equals implementation relies on
Apache Commons Lang reflectionEquals, which already compares subclass fields.
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

SONARJAVA-6384

Cover the null-declaration and already-found reflectionEquals paths, and
bump autoscan expected FPs now that bytecode-less analysis cannot see
EqualsBuilder.reflectionEquals.
@sonarqube-next

sonarqube-next Bot commented Aug 7, 2026

Copy link
Copy Markdown

@rombirli
rombirli merged commit d3006af into master Aug 10, 2026
18 checks passed
@rombirli
rombirli deleted the rombirli/s2160-reflection-equals-fp branch August 10, 2026 06:34
@gitar-bot

gitar-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Fixes a false positive in S2160 when a parent class implements equals using Apache Commons Lang reflectionEquals. No issues found.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

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.

2 participants