False positive in eclipse for S5960 - Remove this assertion from production code

Hi community,
I am getting false positive in STS 3.9.0 (Eclipse 4.13.0) for S5960 - Remove this assertion from production code.
This is clearly in a Junit test marked by @Test annotation and @RunWith(JUnit4.class).
Am I the first with this issue?
Thanks, - HTL

Hello @htl and welcome to the community!
In order to help pinning down the issue, could you provide:

  • A minimal working example
  • The name and version of the assertion library used


test-sonarlint.zip (752 Bytes)

hi Dorian,
example attached
version of SonarLInt --v
SonarLint for Eclipse org.sonarlint.eclipse.feature.feature.group SonarSource
(not sure where to look for the version of the assertion library.)

Hello @htl, thank you for getting back with sample code.
I see from your example that you are using the JUnit4 assertions so that should be fine.
However, I cannot reproduce the issue with your sample.

Can you check if your IDE properly identifies that part of the code as tests?
If your project uses maven or gradle as a build tool, is there an explicit path to the test sources in your pom.xml or build.gradle?



hi Dorian,
I upgraded “org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.8” to 3.1 and still getting the error. STS 3.9 definitely thinks it is a Test. No, build.gradle has no explicit path to rules.
Please see attachments.
Thanks for looking into this.

I have updated build.gradle, as well as Eclipse preferences with sonar properties: sonar.sources and sonar.tests. it did not do anything in the Eclipse sonarLint warning for S5960.
Only @SuppressWarnings({ “java:S5960”}) is working. but it needed to be in every test file.

  • HTL

I have disabled the rule in eclipse preferences. I am good now. Not sure how production code could have assert statement, it will not compile in my opinion. Our sonarqube do not have this rule, it came to me via new SonarLint installation from Eclipse Marketplace.
Thanks for all you help.

  • HTL

Hi @htl

SonarLint uses project classpath metadata to determine if a file is a test or production code. I don’t know if this is working for Gradle projects. You can check in project settings if your test file is included is a source folder marked as ‘contains test source’:

You can also influence SonarLint by setting ‘test file regular expressions’ in global settings:

For example you can try to set: **/*Test.java or something more specific.

Thank you Julien and Dorian

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