ecoCode icon indicating copy to clipboard operation
ecoCode copied to clipboard

The rule "The variable value is not assigned" (JAVA) can report false positives.

Open inguemark-spec opened this issue 3 years ago • 1 comments

The rule "The variable value is not assigned" (JAVA) can report false positives.

For example :

private void test() {

    Object value = getValue ();

    if (value instanceof String stringValue)
    {
        Logger.getLogger("this is a String : " + stringValue);
    }

    if (value instanceof Integer intValue)
    {
        Logger.getLogger("this is a Integer : " + intValue);
    }

}

In this case, the variable is indeed used in the condition, and is then cast.

inguemark-spec avatar Jul 01 '22 16:07 inguemark-spec

Note: This is a Java 17 language feature https://docs.oracle.com/en/java/javase/17/language/pattern-matching-instanceof-operator.html

wokier avatar Jul 04 '22 08:07 wokier