BigDecimal.equals is used, which also compares the scale, so 2.0 and 2.00 differ

tx0/java:scale-sensitive-equalsrecommendedwarningbug

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.

Example from the rule's tests
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;  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

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.