From c67542418921ece5be42b1aef7beadd5b36c9737 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 7 Jun 2017 16:59:24 -0700 Subject: [PATCH] Restore AnnotationUtils null argument support Update AnnotationUtils to restore support for `null` arguments in certain methods. Some existing upstream projects were relying on this behavior. Issue: SPR-15642 --- .../core/annotation/AnnotationUtils.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 2e117642b38..48abacda1ec 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -533,6 +533,9 @@ public abstract class AnnotationUtils { @Nullable public static A findAnnotation(Method method, Class annotationType) { Assert.notNull(method, "Method must not be null"); + if (annotationType == null) { + return null; + } AnnotationCacheKey cacheKey = new AnnotationCacheKey(method, annotationType); A result = (A) findAnnotationCache.get(cacheKey); @@ -655,6 +658,10 @@ public abstract class AnnotationUtils { @Nullable private static A findAnnotation(Class clazz, Class annotationType, boolean synthesize) { Assert.notNull(clazz, "Class must not be null"); + if (annotationType == null) { + return null; + } + AnnotationCacheKey cacheKey = new AnnotationCacheKey(clazz, annotationType); A result = (A) findAnnotationCache.get(cacheKey); if (result == null) { @@ -1310,7 +1317,7 @@ public abstract class AnnotationUtils { */ @Nullable public static Object getValue(Annotation annotation, String attributeName) { - if (!StringUtils.hasText(attributeName)) { + if (annotation == null || !StringUtils.hasText(attributeName)) { return null; } try { @@ -1350,6 +1357,9 @@ public abstract class AnnotationUtils { */ @Nullable public static Object getDefaultValue(Annotation annotation, String attributeName) { + if (annotation == null) { + return null; + } return getDefaultValue(annotation.annotationType(), attributeName); } @@ -1375,7 +1385,7 @@ public abstract class AnnotationUtils { */ @Nullable public static Object getDefaultValue(Class annotationType, String attributeName) { - if (!StringUtils.hasText(attributeName)) { + if (annotationType == null || !StringUtils.hasText(attributeName)) { return null; } try { @@ -1430,7 +1440,7 @@ public abstract class AnnotationUtils { @SuppressWarnings("unchecked") static A synthesizeAnnotation(A annotation, @Nullable Object annotatedElement) { - if (annotation instanceof SynthesizedAnnotation) { + if (annotation == null || annotation instanceof SynthesizedAnnotation) { return annotation; }