We use Asserts.check() and Args.check() but sonar does not see these checks and always report NullPointerException.
Rule: Null pointers should not be dereferenced
Code sample:
Args.check(nonNull(value), "value cannot be null");
methodUsingValue(value); // <--- FP
A "NullPointerException" could be thrown; "value" is nullable here.
Here below the implementations of both methods
public static void check(final boolean expression, final String message) {
if (!expression) {
throw new IllegalArgumentException(message);
}
}
public static void check(final boolean expression, final String message) {
if (!expression) {
throw new IllegalStateException(message);
}
}
Any news about this false positive? or a won’t fix? or a workaround to use other support nullCheck SonarCloud-supported primitives?
If we extract such a redundant if-block checking for null value, guess it will result to a redundant smells error, and with such a dummy false-positive, we are talking of tons of pollution.