An odd check compares % 2 with 1, which fails for negative numbers
What it finds
n % 2 == 1 is false for every negative odd n: the remainder takes the sign of the dividend, so -3 % 2 is -1. n % 2 != 0 tells odd numbers apart whatever their sign.
Reported for int and long dividends, except lengths, sizes, counts and absolute values, which are never negative.
From the rule's source, odd_remainder.rs.
class Parity { boolean odd(int n, long m, String s) { boolean r = n % 2 == 1;tx0 reports: n % 2 == 1 is false for negative odd numbers r = 1 != m % 2;tx0 reports: 1 != m % 2 is false for negative odd numbers r = n % 2 != 0; r = s.length() % 2 == 1; return r; }} 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:odd-remainder" = "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:odd-remainder] reason="..."tx0 explain tx0/java:odd-remainder shows the same in the terminal. Found a false positive? Report it.