Skip to content

Commit c675424

Browse files
committed
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
1 parent 7eaedf2 commit c675424

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ private static <A extends Annotation> A findAnnotation(
533533
@Nullable
534534
public static <A extends Annotation> A findAnnotation(Method method, Class<A> annotationType) {
535535
Assert.notNull(method, "Method must not be null");
536+
if (annotationType == null) {
537+
return null;
538+
}
536539

537540
AnnotationCacheKey cacheKey = new AnnotationCacheKey(method, annotationType);
538541
A result = (A) findAnnotationCache.get(cacheKey);
@@ -655,6 +658,10 @@ public static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> a
655658
@Nullable
656659
private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType, boolean synthesize) {
657660
Assert.notNull(clazz, "Class must not be null");
661+
if (annotationType == null) {
662+
return null;
663+
}
664+
658665
AnnotationCacheKey cacheKey = new AnnotationCacheKey(clazz, annotationType);
659666
A result = (A) findAnnotationCache.get(cacheKey);
660667
if (result == null) {
@@ -1310,7 +1317,7 @@ public static Object getValue(Annotation annotation) {
13101317
*/
13111318
@Nullable
13121319
public static Object getValue(Annotation annotation, String attributeName) {
1313-
if (!StringUtils.hasText(attributeName)) {
1320+
if (annotation == null || !StringUtils.hasText(attributeName)) {
13141321
return null;
13151322
}
13161323
try {
@@ -1350,6 +1357,9 @@ public static Object getDefaultValue(Annotation annotation) {
13501357
*/
13511358
@Nullable
13521359
public static Object getDefaultValue(Annotation annotation, String attributeName) {
1360+
if (annotation == null) {
1361+
return null;
1362+
}
13531363
return getDefaultValue(annotation.annotationType(), attributeName);
13541364
}
13551365

@@ -1375,7 +1385,7 @@ public static Object getDefaultValue(Class<? extends Annotation> annotationType)
13751385
*/
13761386
@Nullable
13771387
public static Object getDefaultValue(Class<? extends Annotation> annotationType, String attributeName) {
1378-
if (!StringUtils.hasText(attributeName)) {
1388+
if (annotationType == null || !StringUtils.hasText(attributeName)) {
13791389
return null;
13801390
}
13811391
try {
@@ -1430,7 +1440,7 @@ public static <A extends Annotation> A synthesizeAnnotation(
14301440

14311441
@SuppressWarnings("unchecked")
14321442
static <A extends Annotation> A synthesizeAnnotation(A annotation, @Nullable Object annotatedElement) {
1433-
if (annotation instanceof SynthesizedAnnotation) {
1443+
if (annotation == null || annotation instanceof SynthesizedAnnotation) {
14341444
return annotation;
14351445
}
14361446

0 commit comments

Comments
 (0)