Skip to content

Commit bc492b9

Browse files
committed
Defensive error reporting when StandardAnnotationMetadata introspects declared methods
Issue: SPR-13791 (cherry picked from commit a36c0a5)
1 parent 8c83807 commit bc492b9

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private static <T> T process(AnnotatedElement element, String annotationType, bo
163163
new HashSet<AnnotatedElement>(), 0);
164164
}
165165
catch (Throwable ex) {
166-
throw new IllegalStateException("Failed to introspect annotations: " + element, ex);
166+
throw new IllegalStateException("Failed to introspect annotations on " + element, ex);
167167
}
168168
}
169169

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -126,25 +126,35 @@ public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotatio
126126

127127
@Override
128128
public boolean hasAnnotatedMethods(String annotationType) {
129-
Method[] methods = getIntrospectedClass().getDeclaredMethods();
130-
for (Method method : methods) {
131-
if (!method.isBridge() && AnnotatedElementUtils.isAnnotated(method, annotationType)) {
132-
return true;
129+
try {
130+
Method[] methods = getIntrospectedClass().getDeclaredMethods();
131+
for (Method method : methods) {
132+
if (!method.isBridge() && AnnotatedElementUtils.isAnnotated(method, annotationType)) {
133+
return true;
134+
}
133135
}
136+
return false;
137+
}
138+
catch (Throwable ex) {
139+
throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex);
134140
}
135-
return false;
136141
}
137142

138143
@Override
139144
public Set<MethodMetadata> getAnnotatedMethods(String annotationType) {
140-
Method[] methods = getIntrospectedClass().getDeclaredMethods();
141-
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>();
142-
for (Method method : methods) {
143-
if (!method.isBridge() && AnnotatedElementUtils.isAnnotated(method, annotationType)) {
144-
annotatedMethods.add(new StandardMethodMetadata(method, this.nestedAnnotationsAsMap));
145+
try {
146+
Method[] methods = getIntrospectedClass().getDeclaredMethods();
147+
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>();
148+
for (Method method : methods) {
149+
if (!method.isBridge() && AnnotatedElementUtils.isAnnotated(method, annotationType)) {
150+
annotatedMethods.add(new StandardMethodMetadata(method, this.nestedAnnotationsAsMap));
151+
}
145152
}
153+
return annotatedMethods;
154+
}
155+
catch (Throwable ex) {
156+
throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex);
146157
}
147-
return annotatedMethods;
148158
}
149159

150160
}

0 commit comments

Comments
 (0)