java:S1481 - loop for false positive

Hi, why sonar lint is pointing “java: S1481” for variable “word” in an enhanced loop for? Follows code example:

List<String> list = new ArrayList<>();
list.add("Hello");
list.add("World");

for (String word : list) {
	if(word.isEmpty()) {
		System.out.println("empty..");
	}
}

Hi,

Can you tell us what is your IDE, what is the version of SonarLint you are using, and if you are using connected mode, what is the version of the Java analyzer installed on your SonarQube server ?

Thanks

@Julien_HENRY I’m using Eclipse 2020-06 (4.16.0) on Ubuntu 18.04, SonarLint as Eclipse plugin version 5.3.0.

Thanks

I’m not able to reproduce. Could you please enable verbose + analysis logs in the SonarLint console, then trigger an analysis on the offending file and share the logs here.

@Julien_HENRY follow the logs, I omitted real name for confidentiality.

sonarlint_logs.txt (90.6 KB)

Thanks. I’m still not sure how to reproduce, but I suspect something related to classpath/type resolution: https://jira.sonarsource.com/browse/SLE-348

What is the JVM you are using to run Eclipse? You can find this information in Help -> About Eclipse platform -> Installation Details -> Configuration tab
On my side I have:
eclipse.vm=/usr/lib/jvm/java-11-openjdk/bin/java

I’m using Open JDK 8.

eclipse.vm=/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

I created another project just in cause to test this issue, and the error not happening. I think this is something about the project configuration.

Is there anything in the classpath of your project that could conflict with JDK classes? If you look for java.lang.String (using Open Type), does it appears somewhere else than in the JDK?

OK, I was finally able to reproduce. I still think this is related to https://jira.sonarsource.com/browse/SLE-348 but I will do more tests.
Thanks for the report.