Repository navigation
[java] Fix #6925: ImmutableField: false positive on picocli @Option/@Parameters fields - #6936
Conversation
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.
|
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 |
|
Compared to main: (comment created at 2026-08-13 20:08:47+00:00 for f9cba69) |
# Conflicts: # docs/pages/release_notes.md
UncleOwen
left a comment
There was a problem hiding this comment.
Guess we can make this configurable next time.
Describe the PR
Ignore private fields annotated with picocli
CommandLine.OptionorCommandLine.Parametersin 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
finalis a false positive, same pattern as the existinglombok.Setterfield exclusion.Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)Tests
./mvnw -pl pmd-java -am test -Dtest=ImmutableFieldTest -Dsurefire.failIfNoSpecifiedTests=false— 54 tests, 0 failures (Java 21).