Sonar.java.source: less than vs. not equal?

Some rules (mostly smells) are basically “you should use this new feature because it’s much better than the old way” and they naturally don’t apply for older Java source. Some rule descriptions are pretty explicit about this. For instance, the description for java:S2196 (Switches should be used for sequences of simple “String” tests) explicitly says “this rule is automatically disabled when the project’s sonar.java.source is lower than 7.”

But others are not so clear.

java:S3824 (“Map.get” and value test should be replaced with single method call): the description says “this rule is automatically disabled when the project’s sonar.java.source is not 8” – so does that mean it’s also not flagged if the source is GREATER than 8 (because the feature was taken away or broken in 9+)? Or should the description say “less than 8”?

java:S3725 (Java 8’s “Files.exists” should not be used): same question. The description specifically mentions JDK8 – does that mean the efficiency issue was fixed in JDK9?

java:S5194 (Use Java 12 “switch” expression) is pretty clear that it relates to a feature added in 12, but makes no mention of sonar.java.source. For consistency, it should mention something like “this rule is automatically disabled when the project’s sonar.java.source is lower than 12.” Just so we know it’s not a 12-specific thing where, say, the feature was changed in a later version.

(To avoid issues with my version of SQ, I pulled these descriptions off of Java static code analysis: Components should not be vulnerable to intent redirection so they should be up to date.)

1 Like

Thanks for reporting the issue, we will go over some of the rules descriptions in the future.

You can also open a pull request on the rspec repository where we store our rules documentation.

So I still have the questions about S3824 and S3725 (whether they still apply for versions greater than 8), especially the latter, which was presented as an efficiency issue (i.e., was the efficiency problem fixed in 9?).