Which rule? S5411 Avoid using boxed “Boolean” types directly in boolean expressions
Why do you believe it’s a false-positive/false-negative? the value has effectively been null-checked already, as this is an Optional
Are you using
SonarQube - v10.6 (92116)
How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
// In reality, this is a method from an API beyond our control which
// happens to return Optional<Boolean>. Whether or not we agree with
// that design choice, we can't change it ;-)
public Optional<Boolean> method1() { ... }
public String method2() {
return method1()
// triggers on b
.map(b -> b ? "truthy" : "falsey")
.orElse("mystery");
}