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

False positive potential null pointer access warning, inside a statement controlled by boolean expression that guarantees a non-null #98

Open
Jack-McKalling opened this issue Apr 8, 2024 · 0 comments

Comments

@Jack-McKalling
Copy link

final Object obj = ...
final boolean test = obj != null;
if (test) {
    obj.getClass();
}

This gives a potential null pointer access warning on obj.getClass();, but it cannot be null.

I think this happens just because of the code prior to it including a null check somewhere. But in this case, the compiler should be able to figure out that the statement is conditioned by a boolean that already specifically claims that the object is not null.

Workaround; it works fine if the boolean declaration is moved into the condition as a literal expression like if (obj != null)
But the simplicity of above code should be recoverable in the first place.

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

1 participant