Skip to content

Commit a36c0a5

Browse files
committed
Defensive error reporting when StandardAnnotationMetadata introspects declared methods
Issue: SPR-13791
1 parent 21329df commit a36c0a5

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java

+23-13
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,37 @@ public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotatio
131131

132132
@Override
133133
public boolean hasAnnotatedMethods(String annotationName) {
134-
Method[] methods = getIntrospectedClass().getDeclaredMethods();
135-
for (Method method : methods) {
136-
if (!method.isBridge() && method.getAnnotations().length > 0 &&
137-
AnnotatedElementUtils.isAnnotated(method, annotationName)) {
138-
return true;
134+
try {
135+
Method[] methods = getIntrospectedClass().getDeclaredMethods();
136+
for (Method method : methods) {
137+
if (!method.isBridge() && method.getAnnotations().length > 0 &&
138+
AnnotatedElementUtils.isAnnotated(method, annotationName)) {
139+
return true;
140+
}
139141
}
142+
return false;
143+
}
144+
catch (Throwable ex) {
145+
throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex);
140146
}
141-
return false;
142147
}
143148

144149
@Override
145150
public Set<MethodMetadata> getAnnotatedMethods(String annotationName) {
146-
Method[] methods = getIntrospectedClass().getDeclaredMethods();
147-
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>();
148-
for (Method method : methods) {
149-
if (!method.isBridge() && method.getAnnotations().length > 0 &&
150-
AnnotatedElementUtils.isAnnotated(method, annotationName)) {
151-
annotatedMethods.add(new StandardMethodMetadata(method, this.nestedAnnotationsAsMap));
151+
try {
152+
Method[] methods = getIntrospectedClass().getDeclaredMethods();
153+
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>();
154+
for (Method method : methods) {
155+
if (!method.isBridge() && method.getAnnotations().length > 0 &&
156+
AnnotatedElementUtils.isAnnotated(method, annotationName)) {
157+
annotatedMethods.add(new StandardMethodMetadata(method, this.nestedAnnotationsAsMap));
158+
}
152159
}
160+
return annotatedMethods;
161+
}
162+
catch (Throwable ex) {
163+
throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex);
153164
}
154-
return annotatedMethods;
155165
}
156166

157167
}

0 commit comments

Comments
 (0)