Skip to content

Commit 16fdda0

Browse files
committed
Debug log messages for value retrieval exceptions
Issue: SPR-15481
1 parent d298561 commit 16fdda0

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ public static <A extends Annotation> A getAnnotation(Annotation ann, Class<A> an
161161
}
162162
catch (Throwable ex) {
163163
handleIntrospectionFailure(annotatedElement, ex);
164+
return null;
164165
}
165-
return null;
166166
}
167167

168168
/**
@@ -192,8 +192,8 @@ public static <A extends Annotation> A getAnnotation(AnnotatedElement annotatedE
192192
}
193193
catch (Throwable ex) {
194194
handleIntrospectionFailure(annotatedElement, ex);
195+
return null;
195196
}
196-
return null;
197197
}
198198

199199
/**
@@ -232,8 +232,8 @@ public static Annotation[] getAnnotations(AnnotatedElement annotatedElement) {
232232
}
233233
catch (Throwable ex) {
234234
handleIntrospectionFailure(annotatedElement, ex);
235+
return null;
235236
}
236-
return null;
237237
}
238238

239239
/**
@@ -254,8 +254,8 @@ public static Annotation[] getAnnotations(Method method) {
254254
}
255255
catch (Throwable ex) {
256256
handleIntrospectionFailure(method, ex);
257+
return null;
257258
}
258-
return null;
259259
}
260260

261261
/**
@@ -473,8 +473,8 @@ private static <A extends Annotation> Set<A> getRepeatableAnnotations(AnnotatedE
473473
}
474474
catch (Throwable ex) {
475475
handleIntrospectionFailure(annotatedElement, ex);
476+
return Collections.emptySet();
476477
}
477-
return Collections.emptySet();
478478
}
479479

480480
/**
@@ -1320,7 +1320,9 @@ else if (aliasPresent) {
13201320
* Retrieve the <em>value</em> of the {@code value} attribute of a
13211321
* single-element Annotation, given an annotation instance.
13221322
* @param annotation the annotation instance from which to retrieve the value
1323-
* @return the attribute value, or {@code null} if not found
1323+
* @return the attribute value, or {@code null} if not found unless the attribute
1324+
* value cannot be retrieved due to an {@link AnnotationConfigurationException},
1325+
* in which case such an exception will be rethrown
13241326
* @see #getValue(Annotation, String)
13251327
*/
13261328
public static Object getValue(Annotation annotation) {
@@ -1331,8 +1333,11 @@ public static Object getValue(Annotation annotation) {
13311333
* Retrieve the <em>value</em> of a named attribute, given an annotation instance.
13321334
* @param annotation the annotation instance from which to retrieve the value
13331335
* @param attributeName the name of the attribute value to retrieve
1334-
* @return the attribute value, or {@code null} if not found
1336+
* @return the attribute value, or {@code null} if not found unless the attribute
1337+
* value cannot be retrieved due to an {@link AnnotationConfigurationException},
1338+
* in which case such an exception will be rethrown
13351339
* @see #getValue(Annotation)
1340+
* @see #rethrowAnnotationConfigurationException(Throwable)
13361341
*/
13371342
public static Object getValue(Annotation annotation, String attributeName) {
13381343
if (annotation == null || !StringUtils.hasText(attributeName)) {
@@ -1343,7 +1348,13 @@ public static Object getValue(Annotation annotation, String attributeName) {
13431348
ReflectionUtils.makeAccessible(method);
13441349
return method.invoke(annotation);
13451350
}
1346-
catch (Exception ex) {
1351+
catch (InvocationTargetException ex) {
1352+
rethrowAnnotationConfigurationException(ex.getTargetException());
1353+
throw new IllegalStateException(
1354+
"Could not obtain value for annotation attribute '" + attributeName + "' in " + annotation, ex);
1355+
}
1356+
catch (Throwable ex) {
1357+
handleIntrospectionFailure(annotation.getClass(), ex);
13471358
return null;
13481359
}
13491360
}
@@ -1399,7 +1410,8 @@ public static Object getDefaultValue(Class<? extends Annotation> annotationType,
13991410
try {
14001411
return annotationType.getDeclaredMethod(attributeName).getDefaultValue();
14011412
}
1402-
catch (Exception ex) {
1413+
catch (Throwable ex) {
1414+
handleIntrospectionFailure(annotationType, ex);
14031415
return null;
14041416
}
14051417
}
@@ -1868,9 +1880,9 @@ static void handleIntrospectionFailure(AnnotatedElement element, Throwable ex) {
18681880
logger = loggerToUse;
18691881
}
18701882
if (element instanceof Class && Annotation.class.isAssignableFrom((Class<?>) element)) {
1871-
// Meta-annotation lookup on an annotation type
1883+
// Meta-annotation or (default) value lookup on an annotation type
18721884
if (loggerToUse.isDebugEnabled()) {
1873-
loggerToUse.debug("Failed to introspect meta-annotations on [" + element + "]: " + ex);
1885+
loggerToUse.debug("Failed to meta-introspect annotation [" + element + "]: " + ex);
18741886
}
18751887
}
18761888
else {
@@ -1966,7 +1978,7 @@ private void process(AnnotatedElement element) {
19661978
else if (ObjectUtils.nullSafeEquals(this.containerAnnotationType, currentAnnotationType)) {
19671979
this.result.addAll(getValue(element, ann));
19681980
}
1969-
else if (!isInJavaLangAnnotationPackage(ann)) {
1981+
else if (!isInJavaLangAnnotationPackage(currentAnnotationType)) {
19701982
process(currentAnnotationType);
19711983
}
19721984
}

0 commit comments

Comments
 (0)