Skip to content

[java] ImmutableField - false positive with Lombok @Setter #4254

@zman0900

Description

@zman0900

Rule: ImmutableField

Given a simple class like:

import lombok.Setter;

public class Junk {
    @Setter
    private String value = "abc";

    public String something() {
        return "blah" + value;
    }
}

PMD 6.52.0 will report "Private field 'value' could be made final; it is only initialized in the declaration or constructor." This is a false positive because there is a generated setValue(String) method that can modify value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions