Java: S5411 FN with inlined Boolean cast expression

Product: SonarQube Community Build 26.5.0.122743
sonar-java version: sonar-java 8.29 (build 43460)
sonar-java SE version: sonar-java-symbolic-execution 8.16.4 (build 1912)
Java source level: 21 (javac 21, source/target 21)

Rule

java:S5411 — Avoid using boxed “Boolean” types directly in boolean expressions

Description

There is a False Negative (FN) in rule java:S5411. The rule successfully detects implicit unboxing when a boxed Boolean is first assigned to a local variable and then used as a condition (in an if statement or ternary operator). However, it fails to trigger when the Boolean cast expression is directly inlined into the condition context.

Both forms result in the exact same implicit unboxing behavior at bytecode level and carry the identical risk of throwing a NullPointerException if the underlying object is a null value (e.g., when an Object reference holds null or is incorrectly cast). Since the two forms are semantically equivalent and equally prone to NPE, java:S5411 should consistently flag both.

Reproducer

public class BooleanCastExample {
​
    // Flagged by java:S5411 on `flag ?` (local variable form)
    public String convertA(Object value) {
        if (value == null) return "";
        Boolean flag = (Boolean) value;
        return flag ? "1" : "0";
    }
​
    // NOT flagged — semantically identical (inlined cast form)
    public String convertB(Object value) {
        if (value == null) return "";
        return (Boolean) value ? "1" : "0";
    }
​
    // Flagged by java:S5411 on `if (asBool)` (local variable form)
    public String describeA(Object flag) {
        if (flag == null) return "unknown";
        Boolean asBool = (Boolean) flag;
        if (asBool) return "yes";
        return "no";
    }
​
    // NOT flagged — semantically identical (inlined cast form)
    public String describeB(Object flag) {
        if (flag == null) return "unknown";
        if ((Boolean) flag) return "yes";
        return "no";
    }
}

Expected behavior

java:S5411 should flag unboxing on inlined cast expressions such as (Boolean) value ? ... and if ((Boolean) flag), treating them identically to when the cast result is stored in an intermediate local variable.

Actual behavior

java:S5411 is only raised when the cast result passes through an intermediate Boolean local variable. The inlined TypeCast expressions silently escape detection.