pmd icon indicating copy to clipboard operation
pmd copied to clipboard

[java] False Positive: PMD Incorrectly report violation for UnnecessaryImport with Static Import of assertNull

Open soyo114 opened this issue 2 years ago • 0 comments

Affects PMD Version:7.0.0-rc4

Rule:UnnecessaryImport

https://docs.pmd-code.org/latest/pmd_rules_java_codestyle.html#unnecessaryimport

Description: According the rule description, if a method, such as assertNull, is statically imported and used, PMD should not report it as a violation. However, the provided sample code, conforming to the rule's specifications, is incorrectly flagged as a violation. This discrepancy indicates a false positive in the PMD analysis. Code Sample demonstrating the issue:

import org.junit.Test;
import static org.junit.Assert.assertNull;
public class TestFoo{
    @Test
    public void testfoo(Object a) throws Exception {
        assertNull(a);
    }
}

Expected outcome:

PMD reports a violation at line 2, but that's wrong. That's a false positive.

Running PMD through: [CLI]

soyo114 avatar Dec 22 '23 07:12 soyo114