Skip to content

[java] Fix #6925: ImmutableField: false positive on picocli @Option/@Parameters fields - #6936

Merged
UncleOwen merged 2 commits into
pmd:mainfrom
arimu1:fix/6925-immutablefield-picocli
Aug 13, 2026
Merged

UncleOwen merged 2 commits into
pmd:mainfrom
arimu1:fix/6925-immutablefield-picocli

Conversation

@arimu1

@arimu1 arimu1 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Describe the PR

Ignore private fields annotated with picocli CommandLine.Option or CommandLine.Parameters in the ImmutableField rule.

picocli injects option/parameter values into those fields at runtime (including when a Java initializer provides a default). Treating them as candidates for final is a false positive, same pattern as the existing lombok.Setter field exclusion.

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)

Tests

./mvnw -pl pmd-java -am test -Dtest=ImmutableFieldTest -Dsurefire.failIfNoSpecifiedTests=false — 54 tests, 0 failures (Java 21).

pmd#6925)

picocli injects values into fields annotated with CommandLine.Option
or CommandLine.Parameters at runtime, so those fields should not be
reported as candidates for final. Treat the annotations like the
existing lombok.Setter field exclusion.
@UncleOwen

Copy link
Copy Markdown
Member

Sounds like there could be a lot more libraries with a lot more annotations out there that need to be exempt from this check. What do you think about making this a property, where lombok.Setter, picocli.CommandLine.Option, and picocli.CommandLine.Parameters are the defaults?

@pmd-actions-helper

pmd-actions-helper Bot commented Aug 5, 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 4 violations, 16 errors and 9 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-13 20:08:47+00:00 for f9cba69)

@UncleOwen UncleOwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Guess we can make this configurable next time.

@UncleOwen UncleOwen added this to the 7.27.0 milestone Aug 13, 2026
@UncleOwen
UncleOwen merged commit cdef01e into pmd:main Aug 13, 2026
13 checks passed
@adangel adangel changed the title [java] ImmutableField: false positive on picocli @Option/@Parameters fields [java] Fix #6925: ImmutableField: false positive on picocli @Option/@Parameters fields Aug 15, 2026
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] ImmutableField: False positive on picocli annotated fields

2 participants