All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S2583.html Maven / Gradle / Ivy

There is a newer version: 8.6.0.37351
Show newest version

Conditional statements using a condition which cannot be anything but FALSE have the effect of making blocks of code non-functional. If the condition cannot evaluate to anything but TRUE, the conditional statement is completely redundant, and makes the code less readable.

It is quite likely that the code does not match the programmer's intent.

Either the condition should be removed or it should be updated so that it does not always evaluate to TRUE or FALSE.

Noncompliant Code Example

//foo can't be both equal and not equal to bar in the same expression
if(foo == bar && something && foo != bar) {...}
private void compute(int foo) {
  if (foo == 4) {
    doSomething();
    // We know foo is equal to 4 at this point, so the next condition is always false
    if (foo > 4) {...}
    ...
  }
  ...
}
private void compute(boolean foo) {
  if (foo) {
    return;
  }
  doSomething();
  // foo is always false here
  if (foo){...}
  ...
}

See

  • MITRE, CWE-489 - Leftover Debug Code
  • MITRE, CWE-570 - Expression is Always False
  • MITRE, CWE-571 - Expression is Always True
  • MISRA C:2004, 13.7 - Boolean operations whose results are invariant shall not be permitted.
  • MISRA C:2012, 14.3 - Controlling expressions shall not be invariant




© 2015 - 2025 Weber Informatics LLC | Privacy Policy