20
20
import java .lang .reflect .Array ;
21
21
import java .lang .reflect .Field ;
22
22
import java .lang .reflect .Method ;
23
+ import java .lang .reflect .Modifier ;
23
24
import java .util .ArrayList ;
24
25
import java .util .LinkedHashSet ;
25
26
import java .util .List ;
28
29
29
30
import org .apache .commons .logging .Log ;
30
31
import org .apache .commons .logging .LogFactory ;
32
+
31
33
import org .springframework .asm .AnnotationVisitor ;
32
34
import org .springframework .asm .SpringAsmInfo ;
33
35
import org .springframework .asm .Type ;
36
38
import org .springframework .util .ObjectUtils ;
37
39
import org .springframework .util .ReflectionUtils ;
38
40
39
-
40
41
/**
41
42
* @author Chris Beams
42
43
* @author Juergen Hoeller
@@ -169,12 +170,11 @@ public RecursiveAnnotationAttributesVisitor(
169
170
public final void visitEnd () {
170
171
try {
171
172
Class <?> annotationClass = this .classLoader .loadClass (this .annotationType );
172
- this . doVisitEnd (annotationClass );
173
+ doVisitEnd (annotationClass );
173
174
}
174
175
catch (ClassNotFoundException ex ) {
175
- this .logger .debug ("Failed to classload type while reading annotation " +
176
- "metadata. This is a non-fatal error, but certain annotation " +
177
- "metadata may be unavailable." , ex );
176
+ this .logger .debug ("Failed to class-load type while reading annotation metadata. " +
177
+ "This is a non-fatal error, but certain annotation metadata may be unavailable." , ex );
178
178
}
179
179
}
180
180
@@ -183,26 +183,30 @@ protected void doVisitEnd(Class<?> annotationClass) {
183
183
}
184
184
185
185
private void registerDefaultValues (Class <?> annotationClass ) {
186
- // Check declared default values of attributes in the annotation type.
187
- Method [] annotationAttributes = annotationClass .getMethods ();
188
- for (Method annotationAttribute : annotationAttributes ) {
189
- String attributeName = annotationAttribute .getName ();
190
- Object defaultValue = annotationAttribute .getDefaultValue ();
191
- if (defaultValue != null && !this .attributes .containsKey (attributeName )) {
192
- if (defaultValue instanceof Annotation ) {
193
- defaultValue = AnnotationAttributes .fromMap (
194
- AnnotationUtils .getAnnotationAttributes ((Annotation )defaultValue , false , true ));
195
- }
196
- else if (defaultValue instanceof Annotation []) {
197
- Annotation [] realAnnotations = (Annotation []) defaultValue ;
198
- AnnotationAttributes [] mappedAnnotations = new AnnotationAttributes [realAnnotations .length ];
199
- for (int i = 0 ; i < realAnnotations .length ; i ++) {
200
- mappedAnnotations [i ] = AnnotationAttributes .fromMap (
201
- AnnotationUtils .getAnnotationAttributes (realAnnotations [i ], false , true ));
186
+ // Only do further scanning for public annotations; we'd run into IllegalAccessExceptions
187
+ // otherwise, and don't want to mess with accessibility in a SecurityManager environment.
188
+ if (Modifier .isPublic (annotationClass .getModifiers ())) {
189
+ // Check declared default values of attributes in the annotation type.
190
+ Method [] annotationAttributes = annotationClass .getMethods ();
191
+ for (Method annotationAttribute : annotationAttributes ) {
192
+ String attributeName = annotationAttribute .getName ();
193
+ Object defaultValue = annotationAttribute .getDefaultValue ();
194
+ if (defaultValue != null && !this .attributes .containsKey (attributeName )) {
195
+ if (defaultValue instanceof Annotation ) {
196
+ defaultValue = AnnotationAttributes .fromMap (
197
+ AnnotationUtils .getAnnotationAttributes ((Annotation ) defaultValue , false , true ));
198
+ }
199
+ else if (defaultValue instanceof Annotation []) {
200
+ Annotation [] realAnnotations = (Annotation []) defaultValue ;
201
+ AnnotationAttributes [] mappedAnnotations = new AnnotationAttributes [realAnnotations .length ];
202
+ for (int i = 0 ; i < realAnnotations .length ; i ++) {
203
+ mappedAnnotations [i ] = AnnotationAttributes .fromMap (
204
+ AnnotationUtils .getAnnotationAttributes (realAnnotations [i ], false , true ));
205
+ }
206
+ defaultValue = mappedAnnotations ;
202
207
}
203
- defaultValue = mappedAnnotations ;
208
+ this . attributes . put ( attributeName , defaultValue ) ;
204
209
}
205
- this .attributes .put (attributeName , defaultValue );
206
210
}
207
211
}
208
212
}
@@ -251,12 +255,16 @@ private void registerMetaAnnotations(Class<?> annotationClass) {
251
255
Set <String > metaAnnotationTypeNames = new LinkedHashSet <String >();
252
256
for (Annotation metaAnnotation : annotationClass .getAnnotations ()) {
253
257
metaAnnotationTypeNames .add (metaAnnotation .annotationType ().getName ());
254
- if (!this .attributesMap .containsKey (metaAnnotation .annotationType ().getName ())) {
255
- this .attributesMap .put (metaAnnotation .annotationType ().getName (),
256
- AnnotationUtils .getAnnotationAttributes (metaAnnotation , true , true ));
257
- }
258
- for (Annotation metaMetaAnnotation : metaAnnotation .annotationType ().getAnnotations ()) {
259
- metaAnnotationTypeNames .add (metaMetaAnnotation .annotationType ().getName ());
258
+ // Only do further scanning for public annotations; we'd run into IllegalAccessExceptions
259
+ // otherwise, and don't want to mess with accessibility in a SecurityManager environment.
260
+ if (Modifier .isPublic (metaAnnotation .annotationType ().getModifiers ())) {
261
+ if (!this .attributesMap .containsKey (metaAnnotation .annotationType ().getName ())) {
262
+ this .attributesMap .put (metaAnnotation .annotationType ().getName (),
263
+ AnnotationUtils .getAnnotationAttributes (metaAnnotation , true , true ));
264
+ }
265
+ for (Annotation metaMetaAnnotation : metaAnnotation .annotationType ().getAnnotations ()) {
266
+ metaAnnotationTypeNames .add (metaMetaAnnotation .annotationType ().getName ());
267
+ }
260
268
}
261
269
}
262
270
if (this .metaAnnotationMap != null ) {
0 commit comments