From b24d1964c2d8a71235c0549de24c975438325cb0 Mon Sep 17 00:00:00 2001 From: yuvarajapril91 Date: Tue, 5 Aug 2025 12:03:55 +0530 Subject: [PATCH] Add TYPE_USE to @NonNull for type-use annotation support This allows @NonNull to be used in type-use positions (such as generic type parameters and return types), in addition to methods, parameters, and fields. This enables broader compatibility with modern null-safety tools and aligns with common usage in the Java ecosystem. Signed-off-by: yuvarajapril91 --- .../src/main/java/org/springframework/lang/NonNull.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/lang/NonNull.java b/spring-core/src/main/java/org/springframework/lang/NonNull.java index c98400968144..6a0d6568329e 100644 --- a/spring-core/src/main/java/org/springframework/lang/NonNull.java +++ b/spring-core/src/main/java/org/springframework/lang/NonNull.java @@ -31,9 +31,9 @@ *

Leverages JSR-305 meta-annotations to indicate nullability in Java to common * tools with JSR-305 support and used by Kotlin to infer nullability of Spring API. * - *

Should be used at the parameter, return value, and field level. Method - * overrides should repeat parent {@code @NonNull} annotations unless they behave - * differently. + *

Should be used at the parameter, return value, field, and type-use level, including + * generics and other type usages. Method overrides should repeat parent {@code @NonNull} + * annotations unless they behave differently. * *

Use {@code @NonNullApi} (scope = parameters + return values) and/or {@code @NonNullFields} * (scope = fields) to set the default behavior to non-nullable in order to avoid annotating @@ -47,7 +47,7 @@ * @see NonNullFields * @see Nullable */ -@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) +@Target({ElementType.TYPE_USE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @Documented @Nonnull