java:S2166 rule not working

I have this code:

@SuppressWarnings("serial")
class TooManyRootsException extends RuntimeException {
    /**
     * Creates an exception with the given message.
     *
     * @param message The message to be shown.
     */
    public TooManyRootsException(String message) {
        super(message);
    }
}

Sonarlint gives me a false positive for rule java:S2166 “Classes named like “Exception” should extend “Exception” or a subclass”. If I remove the “Exception” part of the name, Sonarlint does not give the a positive. Why is that?

Hi,

I’m not able to reproduce in SonarLint Eclipse with just this code snippet.

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

IDE: Eclipse
Version: 5.0
Not sure what the rest means, I installed it from the Eclipse Marketplace.
Hope that helps.

If you don’t know what is connected mode, then you are certainly not using it :slight_smile:.

Could you please follow those steps:

  • open the SonarLint console (in Eclipse console view)
  • enable verbose + analysis logs
  • clear the console
  • close and reopen the offending file (TooManyRootsException.java)
  • copy paste the logs produced in the console by the analysis

It might be useful to read the FAQ first, but if one step is not clear, let me know.

Trigger: EDITOR_OPEN
Clear markers on 0 excluded files
SonarLint processing file /DiscordBot/src/main/java/bot/discord/minimlparsing/TooManyRootsException.java...
Standalone mode (project not bound)
Starting analysis with configuration:
[
  baseDir: C:\Users\troya\OneDrive\Desktop\java programs\DiscordBot
  extraProperties: {sonar.java.target=13, sonar.java.libraries=C:\Program Files\Java\jdk-13.0.2\lib\jrt-fs.jar,C:\Users\troya\.m2\repository\net\dv8tion\JDA\4.1.1_122\JDA-4.1.1_122.jar,C:\Users\troya\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar,C:\Users\troya\.m2\repository\org\jetbrains\annotations\16.0.1\annotations-16.0.1.jar,C:\Users\troya\.m2\repository\com\neovisionaries\nv-websocket-client\2.9\nv-websocket-client-2.9.jar,C:\Users\troya\.m2\repository\com\squareup\okhttp3\okhttp\3.13.0\okhttp-3.13.0.jar,C:\Users\troya\.m2\repository\com\squareup\okio\okio\1.17.2\okio-1.17.2.jar,C:\Users\troya\.m2\repository\org\apache\commons\commons-collections4\4.1\commons-collections4-4.1.jar,C:\Users\troya\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.10.1\jackson-databind-2.10.1.jar,C:\Users\troya\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.10.1\jackson-annotations-2.10.1.jar,C:\Users\troya\.m2\repository\com\sedmelluq\lavaplayer\1.3.34\lavaplayer-1.3.34.jar,C:\Users\troya\.m2\repository\com\sedmelluq\lava-common\1.1.0\lava-common-1.1.0.jar,C:\Users\troya\.m2\repository\com\sedmelluq\lavaplayer-natives\1.3.13\lavaplayer-natives-1.3.13.jar,C:\Users\troya\.m2\repository\org\apache\httpcomponents\httpclient\4.5.10\httpclient-4.5.10.jar,C:\Users\troya\.m2\repository\org\apache\httpcomponents\httpcore\4.4.12\httpcore-4.4.12.jar,C:\Users\troya\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar,C:\Users\troya\.m2\repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar,C:\Users\troya\.m2\repository\commons-io\commons-io\2.6\commons-io-2.6.jar,C:\Users\troya\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.10.0\jackson-core-2.10.0.jar,C:\Users\troya\.m2\repository\org\jsoup\jsoup\1.12.1\jsoup-1.12.1.jar,C:\Users\troya\.m2\repository\net\iharder\base64\2.3.9\base64-2.3.9.jar,C:\Users\troya\.m2\repository\com\google\apis\google-api-services-youtube\v3-rev222-1.25.0\google-api-services-youtube-v3-rev222-1.25.0.jar,C:\Users\troya\.m2\repository\com\google\api-client\google-api-client\1.25.0\google-api-client-1.25.0.jar,C:\Users\troya\.m2\repository\com\google\oauth-client\google-oauth-client\1.25.0\google-oauth-client-1.25.0.jar,C:\Users\troya\.m2\repository\com\google\http-client\google-http-client\1.25.0\google-http-client-1.25.0.jar,C:\Users\troya\.m2\repository\com\google\j2objc\j2objc-annotations\1.1\j2objc-annotations-1.1.jar,C:\Users\troya\.m2\repository\com\google\http-client\google-http-client-jackson2\1.25.0\google-http-client-jackson2-1.25.0.jar,C:\Users\troya\.m2\repository\com\google\guava\guava\20.0\guava-20.0.jar,C:\Users\troya\.m2\repository\org\slf4j\slf4j-api\2.0.0-alpha1\slf4j-api-2.0.0-alpha1.jar,C:\Users\troya\.m2\repository\org\slf4j\slf4j-nop\2.0.0-alpha1\slf4j-nop-2.0.0-alpha1.jar,C:/Users/troya/OneDrive/Desktop/java programs/random projects/bin, sonar.java.source=13, sonar.java.binaries=C:/Users/troya/OneDrive/Desktop/java programs/DiscordBot/target/classes, sonar.java.test.binaries=C:/Users/troya/OneDrive/Desktop/java programs/DiscordBot/target/test-classes, sonar.java.test.libraries=C:/Users/troya/OneDrive/Desktop/java programs/DiscordBot/target/classes,C:\Program Files\Java\jdk-13.0.2\lib\jrt-fs.jar,C:\Users\troya\.m2\repository\net\dv8tion\JDA\4.1.1_122\JDA-4.1.1_122.jar,C:\Users\troya\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar,C:\Users\troya\.m2\repository\org\jetbrains\annotations\16.0.1\annotations-16.0.1.jar,C:\Users\troya\.m2\repository\com\neovisionaries\nv-websocket-client\2.9\nv-websocket-client-2.9.jar,C:\Users\troya\.m2\repository\com\squareup\okhttp3\okhttp\3.13.0\okhttp-3.13.0.jar,C:\Users\troya\.m2\repository\com\squareup\okio\okio\1.17.2\okio-1.17.2.jar,C:\Users\troya\.m2\repository\org\apache\commons\commons-collections4\4.1\commons-collections4-4.1.jar,C:\Users\troya\.m2\repository\net\sf\trove4j\trove4j\3.0.3\trove4j-3.0.3.jar,C:\Users\troya\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.10.1\jackson-databind-2.10.1.jar,C:\Users\troya\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.10.1\jackson-annotations-2.10.1.jar,C:\Users\troya\.m2\repository\com\sedmelluq\lavaplayer\1.3.34\lavaplayer-1.3.34.jar,C:\Users\troya\.m2\repository\com\sedmelluq\lava-common\1.1.0\lava-common-1.1.0.jar,C:\Users\troya\.m2\repository\com\sedmelluq\lavaplayer-natives\1.3.13\lavaplayer-natives-1.3.13.jar,C:\Users\troya\.m2\repository\org\apache\httpcomponents\httpclient\4.5.10\httpclient-4.5.10.jar,C:\Users\troya\.m2\repository\org\apache\httpcomponents\httpcore\4.4.12\httpcore-4.4.12.jar,C:\Users\troya\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar,C:\Users\troya\.m2\repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar,C:\Users\troya\.m2\repository\commons-io\commons-io\2.6\commons-io-2.6.jar,C:\Users\troya\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.10.0\jackson-core-2.10.0.jar,C:\Users\troya\.m2\repository\org\jsoup\jsoup\1.12.1\jsoup-1.12.1.jar,C:\Users\troya\.m2\repository\net\iharder\base64\2.3.9\base64-2.3.9.jar,C:\Users\troya\.m2\repository\com\google\apis\google-api-services-youtube\v3-rev222-1.25.0\google-api-services-youtube-v3-rev222-1.25.0.jar,C:\Users\troya\.m2\repository\com\google\api-client\google-api-client\1.25.0\google-api-client-1.25.0.jar,C:\Users\troya\.m2\repository\com\google\oauth-client\google-oauth-client\1.25.0\google-oauth-client-1.25.0.jar,C:\Users\troya\.m2\repository\com\google\http-client\google-http-client\1.25.0\google-http-client-1.25.0.jar,C:\Users\troya\.m2\repository\com\google\j2objc\j2objc-annotations\1.1\j2objc-annotations-1.1.jar,C:\Users\troya\.m2\repository\com\google\http-client\google-http-client-jackson2\1.25.0\google-http-client-jackson2-1.25.0.jar,C:\Users\troya\.m2\repository\com\google\guava\guava\20.0\guava-20.0.jar,C:\Users\troya\.m2\repository\org\slf4j\slf4j-api\2.0.0-alpha1\slf4j-api-2.0.0-alpha1.jar,C:\Users\troya\.m2\repository\org\slf4j\slf4j-nop\2.0.0-alpha1\slf4j-nop-2.0.0-alpha1.jar,C:/Users/troya/OneDrive/Desktop/java programs/random projects/bin}
  excludedRules: []
  includedRules: []
  inputFiles: [
    file:/C:/Users/troya/OneDrive/Desktop/java%20programs/DiscordBot/src/main/java/bot/discord/minimlparsing/TooManyRootsException.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:/C:/Users/troya/OneDrive/Desktop/java%20programs/DiscordBot/src/main/java/bot/discord/minimlparsing/TooManyRootsException.java' is detected to be 'java'
1 file indexed
Execute Sensor: JavaSquidSensor
Configured Java source version (sonar.java.source): 13
JavaClasspath initialization
JavaClasspath initialization (done) | time=2ms
JavaTestClasspath initialization
JavaTestClasspath initialization (done) | time=3ms
----- Classpath analyzed by Squid:
C:\Users\troya\OneDrive\Desktop\java programs\DiscordBot\target\classes
C:\Program Files\Java\jdk-13.0.2\lib\jrt-fs.jar
C:\Users\troya\.m2\repository\net\dv8tion\JDA\4.1.1_122\JDA-4.1.1_122.jar
C:\Users\troya\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar
C:\Users\troya\.m2\repository\org\jetbrains\annotations\16.0.1\annotations-16.0.1.jar
C:\Users\troya\.m2\repository\com\neovisionaries\nv-websocket-client\2.9\nv-websocket-client-2.9.jar
C:\Users\troya\.m2\repository\com\squareup\okhttp3\okhttp\3.13.0\okhttp-3.13.0.jar
C:\Users\troya\.m2\repository\com\squareup\okio\okio\1.17.2\okio-1.17.2.jar
C:\Users\troya\.m2\repository\org\apache\commons\commons-collections4\4.1\commons-collections4-4.1.jar
C:\Users\troya\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.10.1\jackson-databind-2.10.1.jar
C:\Users\troya\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.10.1\jackson-annotations-2.10.1.jar
C:\Users\troya\.m2\repository\com\sedmelluq\lavaplayer\1.3.34\lavaplayer-1.3.34.jar
C:\Users\troya\.m2\repository\com\sedmelluq\lava-common\1.1.0\lava-common-1.1.0.jar
C:\Users\troya\.m2\repository\com\sedmelluq\lavaplayer-natives\1.3.13\lavaplayer-natives-1.3.13.jar
C:\Users\troya\.m2\repository\org\apache\httpcomponents\httpclient\4.5.10\httpclient-4.5.10.jar
C:\Users\troya\.m2\repository\org\apache\httpcomponents\httpcore\4.4.12\httpcore-4.4.12.jar
C:\Users\troya\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar
C:\Users\troya\.m2\repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar
C:\Users\troya\.m2\repository\commons-io\commons-io\2.6\commons-io-2.6.jar
C:\Users\troya\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.10.0\jackson-core-2.10.0.jar
C:\Users\troya\.m2\repository\org\jsoup\jsoup\1.12.1\jsoup-1.12.1.jar
C:\Users\troya\.m2\repository\net\iharder\base64\2.3.9\base64-2.3.9.jar
C:\Users\troya\.m2\repository\com\google\apis\google-api-services-youtube\v3-rev222-1.25.0\google-api-services-youtube-v3-rev222-1.25.0.jar
C:\Users\troya\.m2\repository\com\google\api-client\google-api-client\1.25.0\google-api-client-1.25.0.jar
C:\Users\troya\.m2\repository\com\google\oauth-client\google-oauth-client\1.25.0\google-oauth-client-1.25.0.jar
C:\Users\troya\.m2\repository\com\google\http-client\google-http-client\1.25.0\google-http-client-1.25.0.jar
C:\Users\troya\.m2\repository\com\google\j2objc\j2objc-annotations\1.1\j2objc-annotations-1.1.jar
C:\Users\troya\.m2\repository\com\google\http-client\google-http-client-jackson2\1.25.0\google-http-client-jackson2-1.25.0.jar
C:\Users\troya\.m2\repository\com\google\guava\guava\20.0\guava-20.0.jar
C:\Users\troya\.m2\repository\org\slf4j\slf4j-api\2.0.0-alpha1\slf4j-api-2.0.0-alpha1.jar
C:\Users\troya\.m2\repository\org\slf4j\slf4j-nop\2.0.0-alpha1\slf4j-nop-2.0.0-alpha1.jar
C:\Users\troya\OneDrive\Desktop\java programs\random projects\bin
-----
----- Classpath analyzed by Squid:
C:\Users\troya\OneDrive\Desktop\java programs\DiscordBot\target\test-classes
C:\Users\troya\OneDrive\Desktop\java programs\DiscordBot\target\classes
C:\Program Files\Java\jdk-13.0.2\lib\jrt-fs.jar
C:\Users\troya\.m2\repository\net\dv8tion\JDA\4.1.1_122\JDA-4.1.1_122.jar
C:\Users\troya\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar
C:\Users\troya\.m2\repository\org\jetbrains\annotations\16.0.1\annotations-16.0.1.jar
C:\Users\troya\.m2\repository\com\neovisionaries\nv-websocket-client\2.9\nv-websocket-client-2.9.jar
C:\Users\troya\.m2\repository\com\squareup\okhttp3\okhttp\3.13.0\okhttp-3.13.0.jar
C:\Users\troya\.m2\repository\com\squareup\okio\okio\1.17.2\okio-1.17.2.jar
C:\Users\troya\.m2\repository\org\apache\commons\commons-collections4\4.1\commons-collections4-4.1.jar
C:\Users\troya\.m2\repository\net\sf\trove4j\trove4j\3.0.3\trove4j-3.0.3.jar
C:\Users\troya\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.10.1\jackson-databind-2.10.1.jar
C:\Users\troya\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.10.1\jackson-annotations-2.10.1.jar
C:\Users\troya\.m2\repository\com\sedmelluq\lavaplayer\1.3.34\lavaplayer-1.3.34.jar
C:\Users\troya\.m2\repository\com\sedmelluq\lava-common\1.1.0\lava-common-1.1.0.jar
C:\Users\troya\.m2\repository\com\sedmelluq\lavaplayer-natives\1.3.13\lavaplayer-natives-1.3.13.jar
C:\Users\troya\.m2\repository\org\apache\httpcomponents\httpclient\4.5.10\httpclient-4.5.10.jar
C:\Users\troya\.m2\repository\org\apache\httpcomponents\httpcore\4.4.12\httpcore-4.4.12.jar
C:\Users\troya\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar
C:\Users\troya\.m2\repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar
C:\Users\troya\.m2\repository\commons-io\commons-io\2.6\commons-io-2.6.jar
C:\Users\troya\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.10.0\jackson-core-2.10.0.jar
C:\Users\troya\.m2\repository\org\jsoup\jsoup\1.12.1\jsoup-1.12.1.jar
C:\Users\troya\.m2\repository\net\iharder\base64\2.3.9\base64-2.3.9.jar
C:\Users\troya\.m2\repository\com\google\apis\google-api-services-youtube\v3-rev222-1.25.0\google-api-services-youtube-v3-rev222-1.25.0.jar
C:\Users\troya\.m2\repository\com\google\api-client\google-api-client\1.25.0\google-api-client-1.25.0.jar
C:\Users\troya\.m2\repository\com\google\oauth-client\google-oauth-client\1.25.0\google-oauth-client-1.25.0.jar
C:\Users\troya\.m2\repository\com\google\http-client\google-http-client\1.25.0\google-http-client-1.25.0.jar
C:\Users\troya\.m2\repository\com\google\j2objc\j2objc-annotations\1.1\j2objc-annotations-1.1.jar
C:\Users\troya\.m2\repository\com\google\http-client\google-http-client-jackson2\1.25.0\google-http-client-jackson2-1.25.0.jar
C:\Users\troya\.m2\repository\com\google\guava\guava\20.0\guava-20.0.jar
C:\Users\troya\.m2\repository\org\slf4j\slf4j-api\2.0.0-alpha1\slf4j-api-2.0.0-alpha1.jar
C:\Users\troya\.m2\repository\org\slf4j\slf4j-nop\2.0.0-alpha1\slf4j-nop-2.0.0-alpha1.jar
C:\Users\troya\OneDrive\Desktop\java programs\random projects\bin
-----
Java Main Files AST scan
1 source files to be analyzed
Initializing metadata of file file:/C:/Users/troya/OneDrive/Desktop/java%20programs/DiscordBot/src/main/java/bot/discord/minimlparsing/TooManyRootsException.java
Java Main Files AST scan (done) | time=611ms
1/1 source files have been analyzed
Java Test Files AST scan
0 source files to be analyzed
Java Test 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 1 issue(s)
Done in 713 ms
0/0 source files have been analyzed

Thanks, I see nothing suspicious here. I also tried to use a JDK 13 as target, but I’m still unable to reproduce.
Is your code snippet a single class? Or an inner class of a bigger file?

Can you also double check that the inherited class is really java.lang.RuntimeException and not something else in a different package?

It is a normal class from a bigger project.
Even when specifing java.lang.RuntimeException the positive persists.

Hum, I start to be out of ideas. Can you try to create a new project in Eclipse, with only this class, and see if the false positive is still there? This is to find if the issue is specific to your project, or to your environment.

It’s still positive.

Then I have no idea. On, my side it is working fine (Windows, SonarLint 5.0 as well):

I will try with a JDK 13 but I don’t see why it would make any difference.

Can you share a reproducer (sample project zipped)?

https://www.zipshare.com/download/eyJhcmNoaXZlSWQiOiJhZGI4ZGE5Ni1mZTNkLTRiNGYtYmM4MC02YmI0YTg0MDJhZjMiLCJlbWFpbCI6InRyb3lhbmtydUBnbWFpbC5jb20ifQ==
This is a ZIP folder with a test project.

I opened your project and no issues for me.

One thing I forgot to ask, is what is the JVM you are using to start Eclipse? You can check by opening Help -> About Eclipse -> Installation Details -> Configuration

eclipse.vm=C:\Program Files\Java\jre1.8.0_51\bin\server\jvm.dll

Perfect, that was the missing part of the puzzle :slight_smile: I am now able to reproduce.

We will investigate and I will keep you posted. You can also follow this ticket: https://jira.sonarsource.com/browse/SLE-348

1 Like

I forgot to say one workaround in the meantime is to run Eclipse with a more recent JDK.

That fixed it actually.