New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] UnusedImports false positive with static ondemand import with method call #1404

Closed
adangel opened this Issue Oct 22, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@adangel
Member

adangel commented Oct 22, 2018

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

@oowekyala

This comment has been minimized.

Member

oowekyala commented Oct 27, 2018

@adangel Thanks for fixing this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment