A value is compared with true or false
What it finds
if (done == true) says if (done) at more length, and done == false says !done.
The fix drops the comparison. For a primitive boolean it is safe. For a Boolean that may be null both forms throw, but the fixed one no longer unboxes where the value is used as an object, so the fix is offered as unsafe when the type is not known to be boolean.
From the rule's source, bool_literal_comparison.rs.
class Flags { boolean check(boolean done, Boolean boxed, java.util.List<String> list) { boolean r = done == true;tx0 reports: done == true can be written done r = done != true;tx0 reports: done != true can be written !done r = false == list.isEmpty();tx0 reports: false == list.isEmpty() can be written !list.isEmpty() r = (done && r) == false;tx0 reports: can be written !(done && r) r = boxed == Boolean.TRUE; r = true == false; return r; }} 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:bool-literal-comparison" = "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:bool-literal-comparison] reason="..."tx0 explain tx0/java:bool-literal-comparison shows the same in the terminal. Found a false positive? Report it.