I have the following line of code (where "next" is a BigDecimal):
if (next.compareTo(maximum) == 1) {
maximum = next;
}
On the equality comparison, SonarQube gives me this warning:
Only the sign of the result should be examined.sonarqube-inject
What does it actually mean and how can I fix that ?
You should only test if it's greater than zero:
if (next.compareTo(maximum) > 0) {
maximum = next;
}
From the API docs of the compareTo Method:
Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With