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.)