If a boolean expression doesn’t change the evaluation of the condition, then it is entirely unnecessary, and can be removed. If it is gratuitous because it does not match the programmer’s intent, then it’s a bug and the expression should be fixed.
if (a) {
if (a) { // Noncompliant
doSomething();
}
}
if (a) {
if (b) {
doSomething();
}
}
// or
if (a) {
doSomething();
}
- MITRE, CWE-571 - Expression is Always True
- MITRE, CWE-570 - Expression is Always False