squid:UselessImportCheck false positive with lombok.var

Strangely, the following Java code :

import lombok.val;
import lombok.var;

class Foo {
    public void test() {
        var foo1 = "hello, ";
        val foo2 = 5;

        System.out.println(foo1 + foo2);
    }
}

triggers the squid:UselessImportCheck rule for import lombok.var, but not for import lombok.val. Both imports are used, so there should be no detected violation.

Please note that this is Java 7 code, so var is not a keyword in this context. To enforce this, the property sonar.java.source=1.7 has been set in the properties file of the analyzer.

Versions used : SonarQube 6.7.3, scanner 3.0.3.778, Java analyzer 5.11)

This is indeed a false positive due to the collision of supporting var syntax for java 10 and lombok functionality of var.

Ticket created to handle the issue: https://jira.sonarsource.com/browse/SONARJAVA-3154

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.