if statements with conditions that are always false have the effect of making blocks of code non-functional. if
statements with conditions that are always true are completely redundant, and make the code less readable.
There are three possible causes for the presence of such code:
In any of these cases, unconditional if statements should be removed.
if (true) {
doSomething();
}
...
if (false) {
doSomethingElse();
}
if (2 < 3 ) { ... } // Noncompliant; always false
int i = 0;
int j = 0;
// ...
j = foo();
if (j > 0 && i > 0) { ... } // Noncompliant; always false - i never set after initialization
boolean b = true;
//...
if (b || !b) { ... } // Noncompliant
doSomething(); ...
This rule is deprecated; use {rule:squid:S2583} instead.