uber/NullAway

`if` statement on a boolean does not prevent a dereferenced nullable error

sdeleuze opened this issue · 1 comments

Another frequent source of irrelevant errors in Spring Framework is this kind of code (with more complex conditions with additional && and/or reuse of the state of the boolean in other places):

@Nullable
protected ResourceLoader resourceLoader;

// ...

boolean resourceLoaderNotNull = (this.resourceLoader != null);
if (resourceLoaderNotNull) {
	currentThread.setContextClassLoader(this.resourceLoader.getClassLoader());
}

Which trigger the following error:

error: [NullAway] dereferenced expression this.resourceLoader is @Nullable
                        currentThread.setContextClassLoader(this.resourceLoader.getClassLoader());

Would it be possible for NullAway to understand this use case?

This is a duplicate of #98 I believe. Let's continue discussion there. I am open to considering this case, but it will take some careful thought.