- What language is this for? Java
- Which rule? javabugs:S6651: Conditionally executed code should be reachable
- Why do you believe it’s a false-positive/false-negative? The condition really can resolve to true or false
- Are you using
- SonarQube Server / Community Build - which version? v2025.1 (102418)
- How can we reproduce the problem? Give us a self-contained snippet of code
In this example, both inputs are expected to be positive, but we do not know which value will be larger.
If aLong < anInt
then the value of diff
will be negative.
But SonarQube seems to believe it will always be positive.
long method(int anInt, long aLong) {
long diff = (aLong - anInt) % 3;
return diff < 0 ? diff + 3 : diff;
}