Defensive error reporting when StandardAnnotationMetadata introspects declared methods

Issue: SPR-13791
This commit is contained in:
Juergen Hoeller 2015-12-14 15:13:29 +01:00
parent 21329df7e1
commit a36c0a50e6
1 changed files with 23 additions and 13 deletions

View File

@ -131,27 +131,37 @@ public class StandardAnnotationMetadata extends StandardClassMetadata implements
@Override @Override
public boolean hasAnnotatedMethods(String annotationName) { public boolean hasAnnotatedMethods(String annotationName) {
Method[] methods = getIntrospectedClass().getDeclaredMethods(); try {
for (Method method : methods) { Method[] methods = getIntrospectedClass().getDeclaredMethods();
if (!method.isBridge() && method.getAnnotations().length > 0 && for (Method method : methods) {
AnnotatedElementUtils.isAnnotated(method, annotationName)) { if (!method.isBridge() && method.getAnnotations().length > 0 &&
return true; 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 @Override
public Set<MethodMetadata> getAnnotatedMethods(String annotationName) { public Set<MethodMetadata> getAnnotatedMethods(String annotationName) {
Method[] methods = getIntrospectedClass().getDeclaredMethods(); try {
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>(); Method[] methods = getIntrospectedClass().getDeclaredMethods();
for (Method method : methods) { Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>();
if (!method.isBridge() && method.getAnnotations().length > 0 && for (Method method : methods) {
AnnotatedElementUtils.isAnnotated(method, annotationName)) { if (!method.isBridge() && method.getAnnotations().length > 0 &&
annotatedMethods.add(new StandardMethodMetadata(method, this.nestedAnnotationsAsMap)); 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;
} }
} }