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

Don't allow instanceof @Nullable C #3033

Closed
wmdietl opened this issue Jan 5, 2020 · 1 comment · Fixed by #3481
Closed

Don't allow instanceof @Nullable C #3033

wmdietl opened this issue Jan 5, 2020 · 1 comment · Fixed by #3481
Assignees
Milestone

Comments

@wmdietl
Copy link
Member

wmdietl commented Jan 5, 2020

instanceof is only true for a non-null expression https://docs.oracle.com/javase/specs/jls/se13/html/jls-15.html#jls-15.20.2.

Code like this:

if (nbl instanceof @Nullable C)

is misleading: the then-branch is not taken for a null value.

A @Nullable annotation on the type of an instanceof should raise an error.
Having a @NonNull annotation is redundant, and could cause a warning.

@smillst
Copy link
Member

smillst commented Jan 6, 2020

Related issue: #762

@mernst mernst added this to the Medium milestone Feb 24, 2020
smillst pushed a commit that referenced this issue Sep 10, 2020
Also, refine the expression of an `instanceof` if the reference type has an explicit annotation.

(Fixes #3033 and fixes #762.)
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

Successfully merging a pull request may close this issue.

4 participants