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

The 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 that foo is equal to 4 at this point and 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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy