Add short circuit logic example to description for rule S2589

Our code gets dinged with rule java:S2589 ( for something like this:

if (c || (!c && b)) …

Obviously the guilty party didn’t understand short-circuit logic, or perhaps was ordered to put in null checks (c in our case is a null check expression).

In the rule description, the non-compliant examples are rather trivial and don’t include an example like this, which is probably more relevant to what novice programmers might do.

So I think it’d be useful to add such an example, something like:

if (c || (!c && b)) { // Short-circuit logic guarantees !c is true

if (c || b) {

This post specifically mentions the java repo but it would apply to any version of this rule in a language with short-circuit logic.

(Our SQ is old but the link above points to your webpage which is presumably up to date.)

Hey there Mister Pi, welcome back!
I see your point and it makes sense, unfortunately the page you linked in this post has not been updated with the latest rule specifications for quite a while, you should consider looking at rule specifications here since it should always be up to date with the latest specs!
I still think your example could be a good addition, I’ve created this ticket to add it to the rule specification.

Hello again, just for clarity and completeness, I found out that the problem with the rule description is actually a known issue related to the URL being used, you should be able to see the correct documentation for the rule here. There are problems with the URLs when specifying tags, types and so on.