From b08883b65c19cbed6e7a93990194977f5af73e0a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 3 Jun 2024 12:45:11 +0200 Subject: [PATCH] Avoid NoSuchMethodException for annotation attribute checks Closes gh-32921 --- .../core/annotation/AnnotationUtils.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 34a59d672085..506e286030de 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 @@ -1052,16 +1052,16 @@ public static Object getValue(@Nullable Annotation annotation, @Nullable String return null; } try { - Method method = annotation.annotationType().getDeclaredMethod(attributeName); - return invokeAnnotationMethod(method, annotation); - } - catch (NoSuchMethodException ex) { - return null; + for (Method method : annotation.annotationType().getDeclaredMethods()) { + if (method.getName().equals(attributeName) && method.getParameterCount() == 0) { + return invokeAnnotationMethod(method, annotation); + } + } } catch (Throwable ex) { handleValueRetrievalFailure(annotation, ex); - return null; } + return null; } /**