Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wkurniawan07 opened this issue Apr 13, 2017 · 3 comments · Fixed by #2899
Labels
a:false-positive PMD flags a piece of code that is not problematic in:symbol-table Affects the symbol table code in:type-resolution Affects the type resolution code
Milestone

Comments

@wkurniawan07
Copy link

wkurniawan07 commented Apr 13, 2017

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

@jsotuyod
Copy link
Member

Thanks for the report.

This is a known limitation. To be able to properly pinpoint which field we are referring to requires complete type resolution, which is currently lacking and is not trivial to implement.

Fortunately, we are planning to work on it in the near future, we even got proposals for google summer of code to tackle this, so we can expect a proper fix over the course of the year.

I'll keep this open to track the issue and let you know when a fix is ready.

@jsotuyod jsotuyod added the a:bug PMD crashes or fails to analyse a file. label Apr 13, 2017
@wkurniawan07
Copy link
Author

@jsotuyod much appreciated, thanks! 👍👍

@jsotuyod jsotuyod added the in:type-resolution Affects the type resolution code label Apr 18, 2017
@jsotuyod jsotuyod added the in:symbol-table Affects the symbol table code label Jun 18, 2017
@jsotuyod jsotuyod added a:false-positive PMD flags a piece of code that is not problematic and removed a:bug PMD crashes or fails to analyse a file. labels Aug 15, 2017
oowekyala added a commit to oowekyala/pmd that referenced this issue Nov 5, 2020
@oowekyala oowekyala added this to the 7.0.0 milestone Nov 10, 2020
@oowekyala oowekyala linked a pull request Nov 10, 2020 that will close this issue
5 tasks
@oowekyala oowekyala removed a link to a pull request Nov 10, 2020
5 tasks
@oowekyala oowekyala linked a pull request Nov 10, 2020 that will close this issue
5 tasks
@adangel
Copy link
Member

adangel commented Dec 11, 2020

Fixed via #2899 for PMD 7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic in:symbol-table Affects the symbol table code in:type-resolution Affects the type resolution code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants