Skip to content

[java] ImmutableField: False positive on picocli annotated fields #6925

Closed

Description

@zman0900

Affects PMD Version: 7.26.0

Rule: ImmutableField

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/pmd/pmd_rules_java_design.html#immutablefield

Description:
Non-final private field annotated by picocli's @Option annotation (and probably their @Parameters annotation too) violates the ImmutableField rule, but picocli will write such a field when the associated option is provided on the command line.

See: https://picocli.info/#_options_and_parameters

Code Sample demonstrating the issue:

public class Demo {
    @Option(
            names = "--ref-date",
            description = "Reference date (yyyy-MM-dd) for calculating"
    )
    private LocalDate refDate = LocalDate.now().withDayOfMonth(1);

    public void something() {...}
}

Expected outcome: PMD either ignores the ImmutableField rule when these specific picocli annotations are present, or provides some option to configure a custom set of annotations that should have the same effect.

PMD reports a violation at line 6, but that's wrong. That's a false positive.

Running PMD through: Gradle

Activity

  1. added
    a:false-positive
    on Aug 4, 2026
  2. added this to the 7.27.0 milestone on Aug 13, 2026
  3. added a commit that references this issue on Aug 13, 2026
    cdef01e
  4. changed the title [-][java] ImmutableField: false positive on picocli annotated fields with default[/-] [+][java] ImmutableField: False positive on picocli annotated fields with default[/+] on Aug 20, 2026
  5. changed the title [-][java] ImmutableField: False positive on picocli annotated fields with default[/-] [+][java] ImmutableField: False positive on picocli annotated fields[/+] on Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positive

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions