Skip to content

Commit e6f1950

Browse files
committed
Missing @nullable annotations for findAnnotation/getValue/getDefaultValue
Note that synthesizeAnnotation has an assertion now, keeping its non-null policy. Issue: SPR-15642
1 parent 72cd244 commit e6f1950

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ private static <A extends Annotation> A findAnnotation(
531531
*/
532532
@SuppressWarnings("unchecked")
533533
@Nullable
534-
public static <A extends Annotation> A findAnnotation(Method method, Class<A> annotationType) {
534+
public static <A extends Annotation> A findAnnotation(Method method, @Nullable Class<A> annotationType) {
535535
Assert.notNull(method, "Method must not be null");
536536
if (annotationType == null) {
537537
return null;
@@ -656,7 +656,9 @@ public static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> a
656656
*/
657657
@SuppressWarnings("unchecked")
658658
@Nullable
659-
private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType, boolean synthesize) {
659+
private static <A extends Annotation> A findAnnotation(
660+
Class<?> clazz, @Nullable Class<A> annotationType, boolean synthesize) {
661+
660662
Assert.notNull(clazz, "Class must not be null");
661663
if (annotationType == null) {
662664
return null;
@@ -1316,7 +1318,7 @@ public static Object getValue(Annotation annotation) {
13161318
* @see #rethrowAnnotationConfigurationException(Throwable)
13171319
*/
13181320
@Nullable
1319-
public static Object getValue(Annotation annotation, String attributeName) {
1321+
public static Object getValue(@Nullable Annotation annotation, @Nullable String attributeName) {
13201322
if (annotation == null || !StringUtils.hasText(attributeName)) {
13211323
return null;
13221324
}
@@ -1356,7 +1358,7 @@ public static Object getDefaultValue(Annotation annotation) {
13561358
* @see #getDefaultValue(Class, String)
13571359
*/
13581360
@Nullable
1359-
public static Object getDefaultValue(Annotation annotation, String attributeName) {
1361+
public static Object getDefaultValue(@Nullable Annotation annotation, @Nullable String attributeName) {
13601362
if (annotation == null) {
13611363
return null;
13621364
}
@@ -1384,7 +1386,9 @@ public static Object getDefaultValue(Class<? extends Annotation> annotationType)
13841386
* @see #getDefaultValue(Annotation, String)
13851387
*/
13861388
@Nullable
1387-
public static Object getDefaultValue(Class<? extends Annotation> annotationType, String attributeName) {
1389+
public static Object getDefaultValue(
1390+
@Nullable Class<? extends Annotation> annotationType, @Nullable String attributeName) {
1391+
13881392
if (annotationType == null || !StringUtils.hasText(attributeName)) {
13891393
return null;
13901394
}
@@ -1440,7 +1444,8 @@ public static <A extends Annotation> A synthesizeAnnotation(
14401444

14411445
@SuppressWarnings("unchecked")
14421446
static <A extends Annotation> A synthesizeAnnotation(A annotation, @Nullable Object annotatedElement) {
1443-
if (annotation == null || annotation instanceof SynthesizedAnnotation) {
1447+
Assert.notNull(annotation, "Annotation must not be null");
1448+
if (annotation instanceof SynthesizedAnnotation) {
14441449
return annotation;
14451450
}
14461451

0 commit comments

Comments
 (0)