In this rule SonarQube the compliant code doesn’t match the non-compliant code. For instance, there are two non-compliant blocks but only one compliant. Wouldn’t it be more clear if the compliant code were basically a replacement for the non-compliant code?
Thank you for the report! I created SONARJAVA-5789 to track this issue.
Thanks. You said have two compliant examples. Actually, I found the second non-compliant example to be similar enough to the first one that I’m not sure if there’s even a reason to have it (unless there’s something subtle I’m missing). Either way (one or two), the compliant and non-compliant should be consistent.
Also, you might want to add a note about version numbers. I guess “this was added in Java X” implies “this rule is only triggered if the compilation target >= X” but there’s some ambiguity about this feature because wasn’t it added sort of experimentally in J12 and not made official until J14?