pmd icon indicating copy to clipboard operation
pmd copied to clipboard

[java] UnnecessaryFullyQualifiedName false positive when nested and non-nested classes with the same name and in the same package are used together

Open OlegAndreych opened this issue 3 years ago • 0 comments

One can find a project to reproduce this issue here: https://github.com/OlegAndreych/PMDNestedClassFQNTest.

package some.pkg;

public class Test {
}
package some.pkg;

public class OuterTest {
    public static class Test{
        private final some.pkg.Test test; // line 5 - false positive

        public Test(some.pkg.Test test){ // line 7 - false positive

            this.test = test;
        }
    }
}

PMD Reports the following violations:

[INFO] PMD Failure: some.pkg.OuterTest$Test:5 Rule:UnnecessaryFullyQualifiedName Priority:4 Unnecessary use of fully qualified name 'some.pkg.Test' due to existing same package import 'some.pkg.*'.
[INFO] PMD Failure: some.pkg.OuterTest$Test:7 Rule:UnnecessaryFullyQualifiedName Priority:4 Unnecessary use of fully qualified name 'some.pkg.Test' due to existing same package import 'some.pkg.*'.

Both are false positives - the fully qualified name is necessary, since the enclosing class has the same name (Test).

OlegAndreych avatar Aug 08 '22 07:08 OlegAndreych