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)) {
			testObject.getId();
}

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!

Best,
Quentin

1 Like

Hi this happens also with the latest version of SonarQube 7.9.1