A conditional expression mixes different numeric boxes, so both are unboxed and converted
What it finds
Object value = flag ? count : ratio; with an Integer and a Double does not keep the Integer: when both branches are numeric boxes of different classes, the conditional operator unboxes them and promotes to the wider type, as the language specification's rules for numeric conditional expressions say. The result is a Double even when flag is true, and a null in either branch throws a NullPointerException.
Reported is a conditional expression whose two branches have numeric box types that differ, as far as this file shows.
From the rule's source, mixed_box_conditional.rs.
class Values { Object pick(boolean flag, Integer count, Double ratio, Integer other) { Object a = flag ? count : ratio;tx0 reports: Integer and Double branches are unboxed Object b = flag ? count : other; Object c = flag ? (Object) count : ratio; return a == null ? b : c; }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/java:mixed-box-conditional" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:mixed-box-conditional] reason="..."tx0 explain tx0/java:mixed-box-conditional shows the same in the terminal. Found a false positive? Report it.