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

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.