Skip to content

[java] Fix #6602: Fix false negative in LocalVariableCouldBeFinalRule#6603

Merged
adangel merged 3 commits into
pmd:mainfrom
UncleOwen:issue-6602-java]-false-negative-in-LocalVariableCouldBeFinal
May 14, 2026
Merged

[java] Fix #6602: Fix false negative in LocalVariableCouldBeFinalRule#6603
adangel merged 3 commits into
pmd:mainfrom
UncleOwen:issue-6602-java]-false-negative-in-LocalVariableCouldBeFinal

Conversation

@UncleOwen
Copy link
Copy Markdown
Member

Describe the PR

Special handling for multiple declarations in one line was applied unconditionally. Should have been only applied if those multiple declaration were inside an ASTForInit.

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 5 complexity · 0 duplication

Metric Results
Complexity 5
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@pmd-actions-helper
Copy link
Copy Markdown
Contributor

pmd-actions-helper Bot commented Apr 17, 2026

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 268 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-05-07 15:25:01+00:00 for f119b54)

@UncleOwen UncleOwen changed the title [java] Fix #6601: Fix false negative in LocalVariableCouldBeFinalRule [java] Fix #6602: Fix false negative in LocalVariableCouldBeFinalRule Apr 17, 2026
Special handling for multiple declarations in one line was applied
unconditionally. Should have been only applied if those multiple
declaration were inside an ASTForInit.
@UncleOwen UncleOwen force-pushed the issue-6602-java]-false-negative-in-LocalVariableCouldBeFinal branch from 9d91fe6 to 133c2e1 Compare April 24, 2026 14:16
Copy link
Copy Markdown
Member

@adangel adangel left a comment

Choose a reason for hiding this comment

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

Can you add please the message verification in the rule test? (to verify we are actually reporting on "j").

Otherwise this PR looks fine, and I made up my mind and agree with your solution (to keep the special handling for for-init).

Thanks!

@adangel adangel added the needs:user-input Maintainers are waiting for feedback from author label May 7, 2026
Copy link
Copy Markdown
Member

@adangel adangel left a comment

Choose a reason for hiding this comment

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

Thanks!

adangel added a commit that referenced this pull request May 14, 2026
@adangel adangel merged commit b4de583 into pmd:main May 14, 2026
13 checks passed
@adangel adangel removed the needs:user-input Maintainers are waiting for feedback from author label May 14, 2026
@UncleOwen UncleOwen deleted the issue-6602-java]-false-negative-in-LocalVariableCouldBeFinal branch May 14, 2026 10:58
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.

[java] LocalVariableCouldBeFinal: False negative when multiple variables are declared at once

2 participants