[Java] potential NullPointerException not detected

Template for a good bug report, formatted with Markdown:

  • SonarQube Version used: 8.9 LTS Community Edition. Scanner Version used:

I have an example where I observe a strange behaviour on code duplications:
Assume, this is the content of a Java file:
File A has a method:
public Object someMethodMayReturnNull() {
return something != null ? something.getSomething() : null;
File B called this method
Object obj = FileA.getInstance().someMethodMayReturnNull();
String result = obj.getXXX();

obj could be null, but sonarqube fails to detect in this scenrio

Hi @michalliu,

We currently don’t detect null pointer issues across files unless the called method is annotated with a @CheckForNull annotation.


I see, thanks for the answer.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.