Rule:
S2589 Boolean expressions should not be gratuitous
Environment:
- SonarQube Version: 10.0.0.68432
Description:
As shown in the following code sample. It should be reported as noncompliant with rule S2589 because the condition c != 0 will always be false, as c is a constant initialized to 0.
Here’s the code sample that triggers the false negative:
public class booleanExpression {
public static final int c=0;
public static void booleanExpressionMethod() {
if (c != 0) { // FN; "c" is always "0"
System.out.println("c == 0");
}
}
}