Affects PMD Version: Observed after upgrade from 6.17.0 to 6.18.0
Rule: category/java/codestyle.xml/UnnecessaryFullyQualifiedName
Description: Violation reported: Unnecessary use of fully qualified name 'Importable.getInner' due to existing same package import 'pkg.*'
Similar to #1316 - but I see no method with the same name as import here.
Similar to #1216 - but it was closed in 6.6.
Similar to #1790 - but I didn't observe it in my case with 6.17.
Similar to #1951 (delivered with 6.18) - but I think there is no name clash in my case.
Code Sample demonstrating the issue:
https://github.com/pzrep/pmd_UnnecessaryFullyQualifiedName-6.18.0
with:
mkdir target
javac -d target src/main/java/pkg/Import*
/pmd-bin-6.18.0/bin/run.sh pmd -d src/main/java -f text -R category/java/codestyle.xml/UnnecessaryFullyQualifiedName -auxclasspath target
result:
Sep 15, 2019 12:31:01 PM net.sourceforge.pmd.PMD processFiles
WARNING: This analysis could be faster, please consider using Incremental Analysis: https://pmd.github.io/pmd-6.18.0/pmd_userdocs_incremental_analysis.html
/tmp/pmd_UnnecessaryFullyQualifiedName-6.18.0/src/main/java/pkg/Importer.java:4: Unnecessary use of fully qualified name 'Importable.getInner' due to existing same package import 'pkg.*'
while with 6.17:
Sep 15, 2019 12:30:26 PM net.sourceforge.pmd.PMD processFiles
WARNING: This analysis could be faster, please consider using Incremental Analysis: https://pmd.github.io/pmd-6.17.0/pmd_userdocs_incremental_analysis.html
Running PMD through: found with Maven, above sample with CLI
This is a similar problem, also a regression from 6.17:
/pmd-bin-6.18.0/bin/run.sh pmd -f text -R category/java/codestyle.xml/UnnecessaryFullyQualifiedName -d Problem.java
package java.util;
public class Problem {
{
Collections.emptySet(); // false positive for UnnecessaryFullyQualifiedName
}
}
Then, with @davidburstrom's case, I think issue could be abstracted to not tied to inner classes, but rather to something classpath-related. In his case rt.jar/java.util.* is in regular CP, and in my case violation is not reported if auxCP is not set.
Just for completeness an example using an enum.
class Sql {
Map<String, String> load() {
//Unnecessary use of fully qualified name 'PathType.RESOURCE'
return type == PathType.RESOURCE ? loadFromResource() : loadFromFileSystem();
}
public enum PathType {
FILE_SYSTEM,
RESOURCE;
}
}
public class DatabaseRepository {
static {
//Unnecessary use of fully qualified name 'Sql.PathType.RESOURCE'
final Sql sql = new Sql("db/sql/queries.sql", Sql.PathType.RESOURCE);
QUERIES = ImmutableMap.copyOf(sql.load());
}
}
I ran into this problem when upgrading the PMD eclipse plugin from 4.6 to 4.7. When any enum value or inner class is referenced by another class in the same package, the reference is flagged as "UnnecesssaryFullyQualifiedName".
@pzygielo @davidburstrom @mmoehring thanks for all the working samples! PR is coming up!
Checked it with just released 6.19.0, and it's very very fine now.
Thanks!
Most helpful comment
Checked it with just released 6.19.0, and it's very very fine now.
Thanks!