Support Java nullability annotations
See original GitHub issue[@lucaswerkmeister] Several frameworks have attempted to improve on Java’s nullability support by introducing annotations for something being @Nullable
or @NotNull
/@NonNull
/@Nonnull
. We should recognize these annotations, and warn or error if:
- a Java
@Nullable
value (method return type, or field) is assigned to a Ceylon non-optional value or a Java@NotNull
, or - a Ceylon optional value or a Java
@Nullable
value is assigned to a Java@NotNull
value (method parameter, setter parameter, or field).
Behavior on unannotated elements should not change. Some frameworks define only one annotation because the other is the default, but we can’t detect that.
Test cases / examples: https://gist.github.com/lucaswerkmeister/07556232a9bd060dd593
Annotations to support (suggestion, potentially incomplete; list from Kotlin):
org.jetbrains.annotation
:@Nullable
,@NotNull
android.support.annotation
:@Nullable
,@NonNull
javax.annotation
:@Nullable
,@Nonnull
(JSR 305, not in main Java yet apparently)edu.umd.cs.findbugs.annotations
:@Nullable
,@NonNull
javax.validation.constraints
:@Null
(“must benull
” – wat?),@NotNull
lombok
:@NonNull
org.eclipse.jdt.annotation
:@Nullable
,@NonNull
– warning, without JS these links redirect you to the main help page for some stupid reasonorg.checkerframework.checker.nullness.qual
:@Nullable
,@NonNull
Alternatively, we could assume that any annotation named @Nullable
, @NotNull
, @NonNull
, @Nonnull
has this meaning. I think that’s probably a reasonable assumption.
[Migrated from ceylon/ceylon-model#8]
Issue Analytics
- State:
- Created 8 years ago
- Comments:20 (10 by maintainers)
Top GitHub Comments
OK, changed setters to inherit annotations from getter if there’s none on the setter param. Closing.
Cool!