-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
a:false-positivePMD flags a piece of code that is not problematicPMD flags a piece of code that is not problematicin:type-resolutionAffects the type resolution codeAffects the type resolution code
Milestone
Description
Affects PMD Version:
confirmed from 6.9.0 to 6.17.0 and 6.18
Rule:
UnusedImports
Description:
False positives from UnusedImports in some specific conditions:
- Import with wildcard (example: import java.util.*)
- Using only calls to static methos who take parameters and return in java.lang (String, Object, etc)
Code Sample demonstrating the issue:
package demo;
import java.util.*;
public class Demo {
public void testFunction() {
Objects.toString(null);
}
}
Running PMD through: CLI and Ant
bash run.sh pmd -d src/ -R category/java/bestpractices.xml/UnusedImports -auxclasspath classes
sep 15, 2019 12:51:53 AM net.sourceforge.pmd.PMD processFiles
ADVERTENCIA: This analysis could be faster, please consider using Incremental Analysis: https://pmd.github.io/pmd-6.17.0/pmd_userdocs_incremental_analysis.html
src/demo/Demo.java:3: Avoid unused imports such as 'java.util'
Curiously, placing the following test code in UnusedImports.xml works fine:
<test-code>
<description>False positive in Unused imports with Wildcard</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
package net.sourceforge.pmd.lang.java.rule.bestpractices.unusedimports;
import java.util.*;
public class Demo {
public void testFunction() {
Objects.toString(null);
}
}
]]></code>
</test-code>
Metadata
Metadata
Assignees
Labels
a:false-positivePMD flags a piece of code that is not problematicPMD flags a piece of code that is not problematicin:type-resolutionAffects the type resolution codeAffects the type resolution code