A byte, short or char is compared with a constant outside its range, so the result never changes
What it finds
A byte holds -128 to 127, so b == 0xFF is always false: the byte read as 255 is -1 once promoted to int. Likewise a char is never negative and a short never exceeds 32767. A comparison with a constant outside the range of the other operand's type has the same result for every value, which the language specification's ranges of the integral types make certain.
Reported is a comparison of a byte, short or char variable or array element with an integer literal outside the range of that type.
From the rule's source, out_of_range_comparison.rs.
class Bytes { boolean check(byte b, byte[] data, char c, short s) { boolean x = b == 0xFF;tx0 reports: a byte runs from -128 to 127, so b == 0xFF never changes boolean y = data[0] == 200;tx0 reports: a byte runs from -128 to 127 boolean z = c == -1;tx0 reports: a char runs from 0 to 65535 boolean w = s > 40000;tx0 reports: a short runs boolean fine = b == -1 || (b & 0xFF) == 0xFF || c >= 0 || data[1] == 127; return x || y || z || w || fine; }} 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:out-of-range-comparison" = "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:out-of-range-comparison] reason="..."tx0 explain tx0/java:out-of-range-comparison shows the same in the terminal. Found a false positive? Report it.