NullPointerException detected after Asserts.check() and Args.check()

Hi,

How to avoid FP using SonarCloud ?

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);
        }
    }

How to fix this ?
Thanks

1 Like

Hey there.

I’ve moved your post to the section on reporting false-postives. Please review the following post:

And update your thread accordingly!

Colin

Updated thanks for the update.

Hi SonarCloud team,

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.

Thanks