A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/1404 below:

[java] UnusedImports false positive with static ondemand import with method call · Issue #1404 · pmd/pmd · GitHub

Affects PMD Version: 6.9.0-SNAPSHOT

Rule: UnusedImports

Description: PMD flags the static import as unused, when it isn't.
This seems to be something different than #1209 . We obviously don't see, that the constant is used in a method call.

Code Sample demonstrating the issue:

package net.sourceforge.pmd.lang.java.rule.bestpractices.unusedimports;

import static net.sourceforge.pmd.lang.java.rule.bestpractices.unusedimports.ClassWithStringConstants.*;

public class ClassWithImport {

    public static void main(String[] args) {
        if (CONST1.equals("a")) {
            System.out.println("CONST1 is a");
        }
        // using this works fine:
        // System.out.println("CONST1 is " + CONST1);
        // also this works:
        // if ("a".equals(CONST1)) { ... }
    }
}

With ClassWithStringConstants being:

package net.sourceforge.pmd.lang.java.rule.bestpractices.unusedimports;

public class ClassWithStringConstants {

    private ClassWithStringConstants() {
        // Utility class
    }

    public static final String CONST1 = "a";
    public static final String CONST2 = "b";
}

Running PMD through: any


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