Affects PMD Version:
6.4.0
Rule:
https://pmd.github.io/pmd-6.4.0/pmd_rules_java_bestpractices.html#unusedimports
Description:
A false positive is generated for the UnusedImports rule on static import of default (package-private) access functions.
Code Sample demonstrating the issue:
src/main/java/com/github/pmd/Imports.java
:
package com.github.pmd; import static com.github.pmd.ProtectedUtils.*; import static com.github.pmd.PublicUtils.*; public class Imports { int importtest() { int i = 0; i = f1(i); i = g1(i); i = f2(i); i = g2(i); i = f3(i); i = g3(i); return i; } }
On line three PMD complains …/src/main/java/com/github/pmd/Imports.java:3: Avoid unused imports such as 'com.github.pmd.ProtectedUtils'
, line four is fine.
src/main/java/com/github/pmd/ProtectedUtils.java
:
package com.github.pmd; final class ProtectedUtils { private ProtectedUtils() { } static int f1(int x) { return x + 1; } static int f2(int x) { return x + 1; } static int f3(int x) { return x + 1; } }
src/main/java/com/github/pmd/PublicUtils.java
:
package com.github.pmd; public class PublicUtils { private PublicUtils() { } public static int g1(int x) { return x + 1; } public static int g2(int x) { return x + 1; } public static int g3(int x) { return x + 1; } }
Running PMD through: Gradle
Example build.gradle
:
plugins { id 'java-library' id 'pmd' } group 'com.github.pmd' version '1.0' apply plugin: 'java' apply plugin: 'java-library' sourceCompatibility = 1.8 repositories { jcenter() } pmd { consoleOutput = true toolVersion = '6.4.0' ruleSets = ['category/java/bestpractices.xml'] }
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4