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

Forbid @NonNull on java.lang.Void #1061

Open
wmdietl opened this issue Jan 11, 2025 · 0 comments
Open

Forbid @NonNull on java.lang.Void #1061

wmdietl opened this issue Jan 11, 2025 · 0 comments

Comments

@wmdietl
Copy link
Member

wmdietl commented Jan 11, 2025

@Nullable is the default for Void.

However, nothing forbids someone from writing:

import org.checkerframework.checker.nullness.qual.NonNull;
class VoidUse {
  void foo(@NonNull Void v) {
      v.toString();
  }
}

This passes the Nullness Checker without a warning.
The only possible call of that method would pass null, the only value of type Void.

It's unlikely that anyone would write this code, but we should forbid explicit usage of @NonNull on Void.

We have an UpperBound annotation, but not a corresponding LowerBound annotation.
Void should have a lower bound of @Nullable to forbid uses with @NonNull.

It would also be nicer to move the default from Nullable to Void, to make it more directly discoverable.

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

No branches or pull requests

1 participant