From a36c0a50e674de0c3c00d89efd26b4b55829231f Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 14 Dec 2015 15:13:29 +0100 Subject: [PATCH] Defensive error reporting when StandardAnnotationMetadata introspects declared methods Issue: SPR-13791 --- .../core/type/StandardAnnotationMetadata.java | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java b/spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java index b389b1cf4c8..668a4b5cf38 100644 --- a/spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java @@ -131,27 +131,37 @@ public class StandardAnnotationMetadata extends StandardClassMetadata implements @Override public boolean hasAnnotatedMethods(String annotationName) { - Method[] methods = getIntrospectedClass().getDeclaredMethods(); - for (Method method : methods) { - if (!method.isBridge() && method.getAnnotations().length > 0 && - AnnotatedElementUtils.isAnnotated(method, annotationName)) { - return true; + try { + Method[] methods = getIntrospectedClass().getDeclaredMethods(); + for (Method method : methods) { + if (!method.isBridge() && method.getAnnotations().length > 0 && + AnnotatedElementUtils.isAnnotated(method, annotationName)) { + return true; + } } + return false; + } + catch (Throwable ex) { + throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex); } - return false; } @Override public Set getAnnotatedMethods(String annotationName) { - Method[] methods = getIntrospectedClass().getDeclaredMethods(); - Set annotatedMethods = new LinkedHashSet(); - for (Method method : methods) { - if (!method.isBridge() && method.getAnnotations().length > 0 && - AnnotatedElementUtils.isAnnotated(method, annotationName)) { - annotatedMethods.add(new StandardMethodMetadata(method, this.nestedAnnotationsAsMap)); + try { + Method[] methods = getIntrospectedClass().getDeclaredMethods(); + Set annotatedMethods = new LinkedHashSet(); + for (Method method : methods) { + if (!method.isBridge() && method.getAnnotations().length > 0 && + AnnotatedElementUtils.isAnnotated(method, annotationName)) { + annotatedMethods.add(new StandardMethodMetadata(method, this.nestedAnnotationsAsMap)); + } } + return annotatedMethods; + } + catch (Throwable ex) { + throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex); } - return annotatedMethods; } }