Improve @Nullable annotation

This commit makes Spring @Nullable annotation leveraging
JSR 305 @TypeQualifierNickname + @Nonnull(when= When.MAYBE)
instead of directly using @javax.annotation.Nullable which
seems not designed to be used as a meta-annotation.

It also removes @TypeQualifierDefault since the purpose of
this annotation when applied at method level is to only
change return value nullability, not parameters one.

Issue: SPR-15540
This commit is contained in:
Sebastien Deleuze
2017-05-31 12:36:59 +02:00
parent abcc4ac979
commit ad2c0f8410

View File

@@ -6,7 +6,9 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.annotation.meta.TypeQualifierDefault;
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierNickname;
import javax.annotation.meta.When;
/**
* Leverage JSR 305 meta-annotations to define the annotated element could be null
@@ -20,9 +22,9 @@ import javax.annotation.meta.TypeQualifierDefault;
* @see javax.annotation.Nullable
*/
@Documented
@javax.annotation.Nullable
@TypeQualifierNickname
@Nonnull(when= When.MAYBE)
@Target({ElementType.METHOD, ElementType.PARAMETER})
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface Nullable {
}