From ad2c0f8410e3b8642e65545afe77e38614069b08 Mon Sep 17 00:00:00 2001 From: Sebastien Deleuze Date: Wed, 31 May 2017 12:36:59 +0200 Subject: [PATCH] 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 --- .../src/main/java/org/springframework/lang/Nullable.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/lang/Nullable.java b/spring-core/src/main/java/org/springframework/lang/Nullable.java index ab68cb9a77..9a6b8a6cc2 100644 --- a/spring-core/src/main/java/org/springframework/lang/Nullable.java +++ b/spring-core/src/main/java/org/springframework/lang/Nullable.java @@ -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 { }