Closed lucaswerkmeister closed 8 years ago
Minor implementation note: assigning null
returned from a function marked @NotNull
to a Ceylon optional should not result in a runtime error.
And we probably shouldn't have compile time errors for:
if (exists x = getRequired()) { ... }
Moved to ceylon/ceylon-model#8.
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:@Nullable
value (method return type, or field) is assigned to a Ceylon non-optional value or a Java@NotNull
, or@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.