Skip to content

[java] AccessorMethodGeneration: Name clash with another public field not properly handled #342

@wkurniawan07

Description

@wkurniawan07

Rule Set: AccessorMethodGeneration (Java - Design), PMD 5.5.5

Description:

It appears that the rule AccessorMethodGeneration fails to resolve name clash with public field in another class with identical name.

Code Sample demonstrating the issue:

public class ClassA {

    public String field;

}
public class ClassB {

    private String field;

    private class ClassC {

        public void doSomething() {
            ClassA a = new ClassA();
            a.field = "abcd"; // should not be a violation here but reported as one
        }

    }

}

Changing ClassB#field to e.g. ClassB#field0 removes the violation.

Running PMD through: Gradle

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematicin:symbol-tableAffects the symbol table codein:type-resolutionAffects the type resolution code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions