Hi, I found a false positive in SonarQube 26.7.0 with sonar-java 8.34 when an integer comparison is known to be false.
Affected tool
SonarQube 26.7.0.124771; sonar-java 8.34 (build 44906)
Affected checker
SonarQube java:S2259
Minimal reproducer
class S2259IntegerCondition {
void test() {
if (32 != 32) {
Object object = null;
object.toString();
}
}
}
Reproduction command
sonar-scanner --version
sonar-scanner -Dsonar.projectKey=s2259-reproducer -Dsonar.sources=sonarqube-s2259-fp-integer-condition.java -Dsonar.host.url="$SONAR_HOST_URL" -Dsonar.token="$SONAR_TOKEN"
Current behavior
SonarQube reports sonarqube-s2259-fp-integer-condition.java:5: java:S2259: A NullPointerException could be thrown; object is nullable here.
Expected behavior
S2259 should not report this dereference because 32 != 32 is false and the branch is unreachable.