BigDecimal.equals is used, which also compares the scale, so 2.0 and 2.00 differ
What it finds
price.equals(limit) on BigDecimal compares the scale as well as the value: new BigDecimal("2.0").equals(new BigDecimal("2.00")) is false. compareTo(...) == 0 compares the numbers.
Reported when the receiver is known to be a BigDecimal; calls in assertions are left alone, since tests may check the scale on purpose.
From the rule's source, scale_sensitive_equals.rs.
import java.math.BigDecimal; class Totals { boolean matches(BigDecimal price, BigDecimal limit) { boolean r = price.equals(limit);tx0 reports: price.equals(...) also compares the scale return r || price.compareTo(limit) == 0; }} 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:scale-sensitive-equals" = "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:scale-sensitive-equals] reason="..."tx0 explain tx0/java:scale-sensitive-equals shows the same in the terminal. Found a false positive? Report it.