A conditional expression chooses between true and false
What it finds
ready ? true : false is ready, and ready ? false : true is !ready: the conditional adds nothing but words.
The fix replaces the expression with the condition, negated where needed. It is offered when the condition is a primitive boolean; for a Boolean the conditional also unboxes, and nothing is offered.
From the rule's source, boolean_ternary.rs.
class Checks { boolean ready(boolean a, int n, Boolean boxed) { boolean x = a ? true : false;tx0 reports: this conditional is just a boolean y = n > 3 ? false : true;tx0 reports: this conditional is just !(n > 3) boolean z = boxed ? true : false;tx0 reports: this conditional is just boxed return x && y && z; }} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:boolean-ternary" = "warning"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:boolean-ternary] reason="..."tx0 explain tx0/java:boolean-ternary shows the same in the terminal. Found a false positive? Report it.