28
28
import java .util .Set ;
29
29
import java .util .WeakHashMap ;
30
30
31
+ import org .apache .commons .logging .Log ;
32
+ import org .apache .commons .logging .LogFactory ;
33
+
31
34
import org .springframework .core .BridgeMethodResolver ;
32
35
import org .springframework .util .Assert ;
33
36
import org .springframework .util .ObjectUtils ;
@@ -63,6 +66,8 @@ public abstract class AnnotationUtils {
63
66
/** The attribute name for annotations with a single element */
64
67
public static final String VALUE = "value" ;
65
68
69
+ private static final Log logger = LogFactory .getLog (AnnotationUtils .class );
70
+
66
71
private static final Map <Class <?>, Boolean > annotatedInterfaceCache = new WeakHashMap <Class <?>, Boolean >();
67
72
68
73
@@ -85,6 +90,9 @@ public static <T extends Annotation> T getAnnotation(Annotation ann, Class<T> an
85
90
catch (Exception ex ) {
86
91
// Assuming nested Class values not resolvable within annotation attributes...
87
92
// We're probably hitting a non-present optional arrangement - let's back out.
93
+ if (logger .isInfoEnabled ()) {
94
+ logger .info ("Failed to introspect annotations on [" + ann .annotationType () + "]: " + ex );
95
+ }
88
96
return null ;
89
97
}
90
98
}
@@ -93,16 +101,16 @@ public static <T extends Annotation> T getAnnotation(Annotation ann, Class<T> an
93
101
* Get a single {@link Annotation} of {@code annotationType} from the supplied
94
102
* Method, Constructor or Field. Meta-annotations will be searched if the annotation
95
103
* is not declared locally on the supplied element.
96
- * @param ae the Method, Constructor or Field from which to get the annotation
104
+ * @param annotatedElement the Method, Constructor or Field from which to get the annotation
97
105
* @param annotationType the annotation type to look for, both locally and as a meta-annotation
98
106
* @return the matching annotation, or {@code null} if none found
99
107
* @since 3.1
100
108
*/
101
- public static <T extends Annotation > T getAnnotation (AnnotatedElement ae , Class <T > annotationType ) {
109
+ public static <T extends Annotation > T getAnnotation (AnnotatedElement annotatedElement , Class <T > annotationType ) {
102
110
try {
103
- T ann = ae .getAnnotation (annotationType );
111
+ T ann = annotatedElement .getAnnotation (annotationType );
104
112
if (ann == null ) {
105
- for (Annotation metaAnn : ae .getAnnotations ()) {
113
+ for (Annotation metaAnn : annotatedElement .getAnnotations ()) {
106
114
ann = metaAnn .annotationType ().getAnnotation (annotationType );
107
115
if (ann != null ) {
108
116
break ;
@@ -114,6 +122,9 @@ public static <T extends Annotation> T getAnnotation(AnnotatedElement ae, Class<
114
122
catch (Exception ex ) {
115
123
// Assuming nested Class values not resolvable within annotation attributes...
116
124
// We're probably hitting a non-present optional arrangement - let's back out.
125
+ if (logger .isInfoEnabled ()) {
126
+ logger .info ("Failed to introspect annotations on [" + annotatedElement + "]: " + ex );
127
+ }
117
128
return null ;
118
129
}
119
130
}
@@ -132,6 +143,9 @@ public static Annotation[] getAnnotations(Method method) {
132
143
catch (Exception ex ) {
133
144
// Assuming nested Class values not resolvable within annotation attributes...
134
145
// We're probably hitting a non-present optional arrangement - let's back out.
146
+ if (logger .isInfoEnabled ()) {
147
+ logger .info ("Failed to introspect annotations on [" + method + "]: " + ex );
148
+ }
135
149
return null ;
136
150
}
137
151
}
@@ -191,6 +205,9 @@ public static <A extends Annotation> Set<A> getRepeatableAnnotation(AnnotatedEle
191
205
catch (Exception ex ) {
192
206
// Assuming nested Class values not resolvable within annotation attributes...
193
207
// We're probably hitting a non-present optional arrangement - let's back out.
208
+ if (logger .isInfoEnabled ()) {
209
+ logger .info ("Failed to introspect annotations on [" + annotatedElement + "]: " + ex );
210
+ }
194
211
}
195
212
return Collections .emptySet ();
196
213
}
@@ -266,6 +283,9 @@ private static boolean isInterfaceWithAnnotatedMethods(Class<?> iface) {
266
283
catch (Exception ex ) {
267
284
// Assuming nested Class values not resolvable within annotation attributes...
268
285
// We're probably hitting a non-present optional arrangement - let's back out.
286
+ if (logger .isInfoEnabled ()) {
287
+ logger .info ("Failed to introspect annotations on [" + ifcMethod + "]: " + ex );
288
+ }
269
289
}
270
290
}
271
291
annotatedInterfaceCache .put (iface , found );
@@ -317,6 +337,9 @@ private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A>
317
337
catch (Exception ex ) {
318
338
// Assuming nested Class values not resolvable within annotation attributes...
319
339
// We're probably hitting a non-present optional arrangement - let's back out.
340
+ if (logger .isInfoEnabled ()) {
341
+ logger .info ("Failed to introspect annotations on [" + clazz + "]: " + ex );
342
+ }
320
343
return null ;
321
344
}
322
345
}
@@ -441,6 +464,9 @@ public static boolean isAnnotationDeclaredLocally(Class<? extends Annotation> an
441
464
catch (Exception ex ) {
442
465
// Assuming nested Class values not resolvable within annotation attributes...
443
466
// We're probably hitting a non-present optional arrangement - let's back out.
467
+ if (logger .isInfoEnabled ()) {
468
+ logger .info ("Failed to introspect annotations on [" + clazz + "]: " + ex );
469
+ }
444
470
}
445
471
return declaredLocally ;
446
472
}
0 commit comments