Not validating Objects.nonNull

SonarQube Version 6.7.1
Java 1.8
For below Code sonar raise bug:
A “NullPointerException” could be thrown; “testObject” is nullable here.
But we are checking non null condition in if clause.

if (Objects.nonNull(testObject)) {

If we change if clause

if(testObject != null)

then sonarqube will not show this issue.

Hello @Deepak_Gusain,

I did not manage to reproduce your false positive with the current version of SonarJava.

Since your version is probably quite old (this test is 4 years old!), you should consider updating SonarJava!


1 Like

Hi this happens also with the latest version of SonarQube 7.9.1

In order to help you, can you provide a complete reproducer causing the issue?
I still don’t see any wrong behavior with the example given.