Skip to content

[java] Fix dataflow state for conditional initializers - #6957

Merged
UncleOwen merged 4 commits into
pmd:mainfrom
subotac:fix/unused-assignment-conditional-increment
Aug 8, 2026
Merged

UncleOwen merged 4 commits into
pmd:mainfrom
subotac:fix/unused-assignment-conditional-increment

Conversation

@subotac

@subotac subotac commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Describe the PR

Preserve the dataflow state returned while visiting local variable initializers. Conditional initializers return a merged branch state; discarding it caused assignments such as i++ in one branch to be
reported as unused even when the variable was read afterwards.

A regression test covers the reported conditional-initializer case.

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes
  • Added in-code documentation if needed

@pmd-actions-helper

pmd-actions-helper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 25 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-08-08 19:01:32+00:00 for 492f1d7)

@subotac
subotac requested a review from UncleOwen August 7, 2026 21:11
@UncleOwen
UncleOwen merged commit 6a2104f into pmd:main Aug 8, 2026
13 checks passed
@UncleOwen UncleOwen added this to the 7.27.0 milestone Aug 8, 2026
@UncleOwen

Copy link
Copy Markdown
Member

Thanks!

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] UnusedAssignment: False positive about the ++ unary operator

2 participants