An equality comparison is negated with ! instead of using the opposite operator
What it finds
!(a == b) says a != b in a roundabout way, and !(a != b) says a == b. The fix writes the comparison the other way round.
Only == and != are reported: !(a < b) differs from a >= b when either side is a floating-point NaN.
From the rule's source, negated_equality.rs.
class Compare { boolean differ(int a, int b, double x, double y) { boolean c = !(a == b);tx0 reports: !(... == ...) can be written with != boolean d = !(a != b);tx0 reports: !(... != ...) can be written with == boolean e = !(x < y); return c && d && e; }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:not-of-equality" = "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:not-of-equality] reason="..."tx0 explain tx0/java:not-of-equality shows the same in the terminal. Found a false positive? Report it.