Which rule? “NullPointerException” should not be explicitly thrown [S1695]
Why do you believe it’s a false-positive/false-negative? The contract for Comparable requires a NullPointerException should be thrown if the input is null.
Are you using
SonarQube - v10.6 (92116)
How can we reproduce the problem?
class ComparableClass implements Comparable<ComparableClass> {
@Override
public int compareTo(@Nullable ComparableClass o) {
if (o == null) {
throw new NullPointerException("Cannot compare to null");
}
return 0;
}
}
interface ComparableInterface extends Comparable<ComparableInterface> {
@Override
default int compareTo(@Nullable ComparableInterface o) {
if (o == null) {
throw new NullPointerException("Cannot compare to null");
}
return 0;
}
}