JSR-303 released constraint annotations @NotNull and @Null, but not @Nullable.
@NotNull is no doubt useful, as the first thing someone asks when he sees a method or field of a non-primitive type is "Can that thing be null?" @NotNull answers that question clearly.
@Null seems to be not very useful, but I understand its symmetry to @NotNull, so it makes sense.
What's missing, IMHO, is an annotation that *explicitly* declares that the annotated element can be null or non-null, which is why I'm proposing that @Nullable be added to JSR 303 (or its successor). Without it, the developer that sees a nullable type will still ask "Can that thing be null?" They may assume so, since it's not annotated with @NotNull, but it's not guaranteed. In the world since JSR 303's release, one would expect to be able to clearly know whether something is explicitly allowed to be null, to be non-null, or to be either, without having to resort to RTFMing.
There would be no explicit validator implementation corresponding to @Nullable, as it would always return true (or the validator impl could be hardcoded to always return true, but that seems a waste).
I'm also asking that JSR 303 publish this annotation in the javax.validation.constraints package, so as not to be confused with JSR 305's @javax.annotation.Nullable annotation, which is used for static code analysis.
|