Unfortunately I haven’t found a good way to reproduce the issue but now I know a little bit more about it. I have uploaded the example code I used above here: https://github.com/philippecade/sonarlint.bug
When I only have this project in Eclipse, the issue doesn’t appear. I can only see it when this project is in a workspace with ~30 other projects, some connected to Sonar and some not.
The issue only happens if the project in question is not connected to a Sonar server.
It is a regression from version 4.3.0.
I don’t think that it depends on a particular code construct, the issue is also reported in a simple for loop for example: for (Foo f: list) { f.foo(); } <-- Remove this unused “f” local variable
Not sure if this is enough information for you. I’m willing to help further if you have a debug build or something like that.
Trigger: EDITOR_OPEN
Clear markers on 0 excluded files
SonarLint processing file /sonarlint.bug/src/sonarlint/bug/LdapUtils.java...
Standalone mode (project not bound)
Starting analysis with configuration:
[
baseDir: /home/julien/tmp/sonarlint.bug/sonarlint.bug
extraProperties: {sonar.java.target=11, sonar.java.libraries=/lib/jvm/java-11/lib/jrt-fs.jar, sonar.java.source=11, sonar.java.binaries=/home/julien/tmp/sonarlint.bug/sonarlint.bug/bin, sonar.java.test.binaries=, sonar.java.test.libraries=/lib/jvm/java-11/lib/jrt-fs.jar,/home/julien/tmp/sonarlint.bug/sonarlint.bug/bin}
excludedRules: []
includedRules: []
ruleParameters: {}
inputFiles: [
file:/home/julien/tmp/sonarlint.bug/sonarlint.bug/src/sonarlint/bug/LdapUtils.java (UTF-8)
]
]
TypeScript sensor excluded
Available languages:
* PHP => "php"
* Python => "py"
* Java => "java"
* HTML => "web"
* JSP => "jsp"
* JavaScript => "js"
* TypeScript => "ts"
Start analysis
Declared extensions of language PHP were converted to php: **/*.php,**/*.php3,**/*.php4,**/*.php5,**/*.phtml,**/*.inc
Declared extensions of language Python were converted to py: **/*.py
Declared extensions of language Java were converted to java: **/*.java,**/*.jav
Declared extensions of language HTML were converted to web: **/*.html,**/*.xhtml,**/*.cshtml,**/*.vbhtml,**/*.aspx,**/*.ascx,**/*.rhtml,**/*.erb,**/*.shtm,**/*.shtml
Declared extensions of language JSP were converted to jsp: **/*.jsp,**/*.jspf,**/*.jspx
Declared extensions of language JavaScript were converted to js: **/*.js,**/*.jsx,**/*.vue
Declared extensions of language TypeScript were converted to ts: **/*.ts,**/*.tsx
Index files
Language of file 'file:/home/julien/tmp/sonarlint.bug/sonarlint.bug/src/sonarlint/bug/LdapUtils.java' is detected to be 'java'
1 file indexed
Execute Sensor: JavaSquidSensor
Configured Java source version (sonar.java.source): 11
JavaClasspath initialization
JavaClasspath initialization (done) | time=1ms
JavaTestClasspath initialization
JavaTestClasspath initialization (done) | time=0ms
----- Classpath analyzed by Squid:
/home/julien/tmp/sonarlint.bug/sonarlint.bug/bin
/lib/jvm/java-11/lib/jrt-fs.jar
-----
----- Classpath analyzed by Squid:
/lib/jvm/java-11/lib/jrt-fs.jar
/home/julien/tmp/sonarlint.bug/sonarlint.bug/bin
-----
----- Classpath analyzed by Squid:
/home/julien/.sonarlint/plugins/b6c533956f13adda5b74dea132d39d7b/sonar-java-plugin-6.4.0.21967.jar
/home/julien/tmp/sonarlint.bug/sonarlint.bug/bin
/lib/jvm/java-11/lib/jrt-fs.jar
-----
Java Main Files AST scan
1 source files to be analyzed
Initializing metadata of file file:/home/julien/tmp/sonarlint.bug/sonarlint.bug/src/sonarlint/bug/LdapUtils.java
1/1 source files have been analyzed
Java Main Files AST scan (done) | time=517ms
Java Test Files AST scan
0 source files to be analyzed
Java Test Files AST scan (done) | time=4ms
Java Generated Files AST scan
0/0 source files have been analyzed
0 source files to be analyzed
Java Generated Files AST scan (done) | time=1ms
'PHP sensor' skipped because there is no related file in current project
'Analyzer for "php.ini" files' skipped because there is no related file in current project
'Python Sensor' skipped because there is no related file in current project
Execute Sensor: JavaXmlSensor
Execute Sensor: HTML
'JavaScript analysis' skipped because there is no related file in current project
Found 31 issue(s)
Done in 582 ms
0/0 source files have been analyzed
This is what I get in the Eclipse that shows the error:
Trigger: EDITOR_OPEN
Clear markers on 0 excluded files
SonarLint processing file /sonarlint.bug/src/sonarlint/bug/LdapUtils.java...
Standalone mode (project not bound)
Starting analysis with configuration:
[
baseDir: D:\Users\xphc\Desktop\git\sonarlint.bug\sonarlint.bug
extraProperties: {sonar.java.target=11, sonar.java.libraries=D:\install\software\Java\jre11.0.5+10-jfx11-windows\lib\jrt-fs.jar, sonar.java.source=11, sonar.java.binaries=D:/Users/xphc/Desktop/git/sonarlint.bug/sonarlint.bug/bin, sonar.java.test.binaries=, sonar.java.test.libraries=D:\install\software\Java\jre11.0.5+10-jfx11-windows\lib\jrt-fs.jar,D:/Users/xphc/Desktop/git/sonarlint.bug/sonarlint.bug/bin}
excludedRules: []
includedRules: []
ruleParameters: {}
inputFiles: [
file:/D:/Users/xphc/Desktop/git/sonarlint.bug/sonarlint.bug/src/sonarlint/bug/LdapUtils.java (UTF-8)
]
]
TypeScript sensor excluded
Available languages:
* PHP => "php"
* Python => "py"
* Java => "java"
* HTML => "web"
* JSP => "jsp"
* JavaScript => "js"
* TypeScript => "ts"
Start analysis
Declared extensions of language PHP were converted to php: **/*.php,**/*.php3,**/*.php4,**/*.php5,**/*.phtml,**/*.inc
Declared extensions of language Python were converted to py: **/*.py
Declared extensions of language Java were converted to java: **/*.java,**/*.jav
Declared extensions of language HTML were converted to web: **/*.html,**/*.xhtml,**/*.cshtml,**/*.vbhtml,**/*.aspx,**/*.ascx,**/*.rhtml,**/*.erb,**/*.shtm,**/*.shtml
Declared extensions of language JSP were converted to jsp: **/*.jsp,**/*.jspf,**/*.jspx
Declared extensions of language JavaScript were converted to js: **/*.js,**/*.jsx,**/*.vue
Declared extensions of language TypeScript were converted to ts: **/*.ts,**/*.tsx
Index files
Language of file 'file:/D:/Users/xphc/Desktop/git/sonarlint.bug/sonarlint.bug/src/sonarlint/bug/LdapUtils.java' is detected to be 'java'
1 file indexed
Execute Sensor: JavaSquidSensor
Configured Java source version (sonar.java.source): 11
JavaClasspath initialization
JavaClasspath initialization (done) | time=1ms
JavaTestClasspath initialization
JavaTestClasspath initialization (done) | time=0ms
----- Classpath analyzed by Squid:
D:\Users\xphc\Desktop\git\sonarlint.bug\sonarlint.bug\bin
D:\install\software\Java\jre11.0.5+10-jfx11-windows\lib\jrt-fs.jar
-----
----- Classpath analyzed by Squid:
D:\install\software\Java\jre11.0.5+10-jfx11-windows\lib\jrt-fs.jar
D:\Users\xphc\Desktop\git\sonarlint.bug\sonarlint.bug\bin
-----
----- Classpath analyzed by Squid:
C:\Users\xphc\.sonarlint\plugins\b6c533956f13adda5b74dea132d39d7b\sonar-java-plugin-6.4.0.21967.jar
D:\Users\xphc\Desktop\git\sonarlint.bug\sonarlint.bug\bin
D:\install\software\Java\jre11.0.5+10-jfx11-windows\lib\jrt-fs.jar
-----
Java Main Files AST scan
1 source files to be analyzed
Initializing metadata of file file:/D:/Users/xphc/Desktop/git/sonarlint.bug/sonarlint.bug/src/sonarlint/bug/LdapUtils.java
Java Main Files AST scan (done) | time=3164ms
Java Test Files AST scan
0 source files to be analyzed
1/1 source files have been analyzed
Java Test Files AST scan (done) | time=2ms
Java Generated Files AST scan
0 source files to be analyzed
Java Generated Files AST scan (done) | time=0ms
'PHP sensor' skipped because there is no related file in current project
'Analyzer for "php.ini" files' skipped because there is no related file in current project
'Python Sensor' skipped because there is no related file in current project
Execute Sensor: JavaXmlSensor
Execute Sensor: HTML
'JavaScript analysis' skipped because there is no related file in current project
Found 24 issue(s)
0/0 source files have been analyzed
0/0 source files have been analyzed
Done in 121229 ms
I see your project is configured to use a JRE, not a JDK. Could it be the reason of the difference? Could you try to configure a JDK instead? I will try to reproduce on my side.
I was able to reproduce. This is because you run Eclipse with a JDK 8, but your project is configured to use a Java 11 runtime.
We have a ticket on our side to track this issue: https://jira.sonarsource.com/browse/SLE-348
I will update it and try to make its resolution prioritized.
In the meantime, a workaround is to configure Eclipse to run with a more recent JDK.