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

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

There is a newer version: 8.6.0.37351
Show newest version

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:

  • An if statement was changed during debugging and that debug code has been committed.
  • Some value was left unset.
  • Some logic is not doing what the programmer thought it did.

In any of these cases, unconditional if statements should be removed.

Noncompliant Code Example

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

Compliant Solution

doSomething(); 
...

See

This rule is deprecated, use {rule:squid:S2583} instead.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy