Inappropriate code example for S2301 - Java

The following post reports inappropriate code in the example of the S2301 rule: Inappropriate code example for S2301

This was reported on SonarJS, however the same example also exists on sonar-java:

The same issue possibly also exists for other languages.

Propose that the example provided in the other report is also applied to the Java (and other language) examples.

Hi,

Welcome to the community and thanks for this report!

Can you give your context for this? I.e. are you on SonarQube Cloud? SonarQube for IDE (flavor and version)? SonarQube self-managed (flavor and version)?

 
Thx,
Ann

Hi.

This was initially spotted by a colleague using SonarLint 8.4.0 in IntelliJ IDEA 2025.3. It’s an older version of the plugin as it binds to an older version of SonarQube server (self-managed) Version 7.9.2 (yes, we really do need to upgrade but are restricted due to the project).

On seeing the example text I checked the ruleset on our SonarQube server, and then checked whether the same example existed within the SonarQube codebase (to check if it had been addressed on the newer versions).

I cannot currently try to recreate on a newer version of SonarQube (I don’t have access until we upgrade) - I raised this based on the source on the “master” branch within github, which currently includes the inappropriate example for S2301.

1 Like

Hi,

Thanks for the explanation. I’ll flag this for the language experts.

And in a separate thread, I’d love to explore how we can get you to a current version of SonarQube. I’m 85% certain that accommodations could be made on a current SonarQube version for the project that’s holding you on a version that’s nearly 6 years :nauseated_face: old.

 
Ann

Thank you for pointing this out!

The rule is currently implemented only for JavaScript and Java, so other languages are unaffected. I did not find any other inappropriate rules.

The fix is underway, and you can track the progress here: SONARJAVA-6007.

The fix has been merged and will be included in the next release.

2 Likes

Thanks for addressing this.

Our upgrade to a newer version of SonarQube is in-hand with our internal tools team.