Product: SonarQube Community (self-hosted)
sonar-java version: sonar-java 8.28.0.43176 on SonarQube Community Build 26.4.0.121862
Java source level: 21 (javac 21, source/target 17)
Rule
java:S5411 — Boxed “Boolean” should not be used in boolean expressions
Description
S5411 inconsistently detects unsafe Boolean unboxing. The rule reports a Boolean used in an if condition only when the value is first assigned to a local variable, but misses the equivalent direct method-call form, even though both can cause the same NullPointerException.
Reproducer
public class Sample {
public @interface NotNull {}
@NotNull
public Boolean get() {
return Boolean.TRUE;
}
// BEFORE — no S5411 reported
public void runDirect() {
if (get()) { // Boolean unboxed in condition
System.out.println("yes");
}
}
// AFTER — S5411 reported on `if (b)`
public void runViaLocal() {
Boolean b = get();
if (b) { // same Boolean, same unboxing
System.out.println("yes");
}
}
}