@@ -161,8 +161,8 @@ public static <A extends Annotation> A getAnnotation(Annotation ann, Class<A> an
161
161
}
162
162
catch (Throwable ex ) {
163
163
handleIntrospectionFailure (annotatedElement , ex );
164
+ return null ;
164
165
}
165
- return null ;
166
166
}
167
167
168
168
/**
@@ -192,8 +192,8 @@ public static <A extends Annotation> A getAnnotation(AnnotatedElement annotatedE
192
192
}
193
193
catch (Throwable ex ) {
194
194
handleIntrospectionFailure (annotatedElement , ex );
195
+ return null ;
195
196
}
196
- return null ;
197
197
}
198
198
199
199
/**
@@ -232,8 +232,8 @@ public static Annotation[] getAnnotations(AnnotatedElement annotatedElement) {
232
232
}
233
233
catch (Throwable ex ) {
234
234
handleIntrospectionFailure (annotatedElement , ex );
235
+ return null ;
235
236
}
236
- return null ;
237
237
}
238
238
239
239
/**
@@ -254,8 +254,8 @@ public static Annotation[] getAnnotations(Method method) {
254
254
}
255
255
catch (Throwable ex ) {
256
256
handleIntrospectionFailure (method , ex );
257
+ return null ;
257
258
}
258
- return null ;
259
259
}
260
260
261
261
/**
@@ -473,8 +473,8 @@ private static <A extends Annotation> Set<A> getRepeatableAnnotations(AnnotatedE
473
473
}
474
474
catch (Throwable ex ) {
475
475
handleIntrospectionFailure (annotatedElement , ex );
476
+ return Collections .emptySet ();
476
477
}
477
- return Collections .emptySet ();
478
478
}
479
479
480
480
/**
@@ -1320,7 +1320,9 @@ else if (aliasPresent) {
1320
1320
* Retrieve the <em>value</em> of the {@code value} attribute of a
1321
1321
* single-element Annotation, given an annotation instance.
1322
1322
* @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
1324
1326
* @see #getValue(Annotation, String)
1325
1327
*/
1326
1328
public static Object getValue (Annotation annotation ) {
@@ -1331,8 +1333,11 @@ public static Object getValue(Annotation annotation) {
1331
1333
* Retrieve the <em>value</em> of a named attribute, given an annotation instance.
1332
1334
* @param annotation the annotation instance from which to retrieve the value
1333
1335
* @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
1335
1339
* @see #getValue(Annotation)
1340
+ * @see #rethrowAnnotationConfigurationException(Throwable)
1336
1341
*/
1337
1342
public static Object getValue (Annotation annotation , String attributeName ) {
1338
1343
if (annotation == null || !StringUtils .hasText (attributeName )) {
@@ -1343,7 +1348,13 @@ public static Object getValue(Annotation annotation, String attributeName) {
1343
1348
ReflectionUtils .makeAccessible (method );
1344
1349
return method .invoke (annotation );
1345
1350
}
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 );
1347
1358
return null ;
1348
1359
}
1349
1360
}
@@ -1399,7 +1410,8 @@ public static Object getDefaultValue(Class<? extends Annotation> annotationType,
1399
1410
try {
1400
1411
return annotationType .getDeclaredMethod (attributeName ).getDefaultValue ();
1401
1412
}
1402
- catch (Exception ex ) {
1413
+ catch (Throwable ex ) {
1414
+ handleIntrospectionFailure (annotationType , ex );
1403
1415
return null ;
1404
1416
}
1405
1417
}
@@ -1868,9 +1880,9 @@ static void handleIntrospectionFailure(AnnotatedElement element, Throwable ex) {
1868
1880
logger = loggerToUse ;
1869
1881
}
1870
1882
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
1872
1884
if (loggerToUse .isDebugEnabled ()) {
1873
- loggerToUse .debug ("Failed to introspect meta-annotations on [" + element + "]: " + ex );
1885
+ loggerToUse .debug ("Failed to meta-introspect annotation [" + element + "]: " + ex );
1874
1886
}
1875
1887
}
1876
1888
else {
@@ -1966,7 +1978,7 @@ private void process(AnnotatedElement element) {
1966
1978
else if (ObjectUtils .nullSafeEquals (this .containerAnnotationType , currentAnnotationType )) {
1967
1979
this .result .addAll (getValue (element , ann ));
1968
1980
}
1969
- else if (!isInJavaLangAnnotationPackage (ann )) {
1981
+ else if (!isInJavaLangAnnotationPackage (currentAnnotationType )) {
1970
1982
process (currentAnnotationType );
1971
1983
}
1972
1984
}
0 commit comments