Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if statement on a boolean does not prevent a dereferenced nullable error #942

Closed
sdeleuze opened this issue Mar 26, 2024 · 1 comment
Closed

Comments

@sdeleuze
Copy link

sdeleuze commented Mar 26, 2024

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?

@msridhar
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants