Skip to content

Commit 2c1203d

Browse files
committed
AnnotationTypeFilter prevents ASM-based loading of java.* and javax.* interfaces as well
Issue: SPR-11719
1 parent 6ee0596 commit 2c1203d

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

spring-core/src/main/java/org/springframework/core/type/filter/AnnotationTypeFilter.java

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -19,8 +19,10 @@
1919
import java.lang.annotation.Annotation;
2020
import java.lang.annotation.Inherited;
2121

22+
import org.springframework.core.annotation.AnnotationUtils;
2223
import org.springframework.core.type.AnnotationMetadata;
2324
import org.springframework.core.type.classreading.MetadataReader;
25+
import org.springframework.util.ClassUtils;
2426

2527
/**
2628
* A simple filter which matches classes with a given annotation,
@@ -49,7 +51,7 @@ public class AnnotationTypeFilter extends AbstractTypeHierarchyTraversingFilter
4951
* @param annotationType the annotation type to match
5052
*/
5153
public AnnotationTypeFilter(Class<? extends Annotation> annotationType) {
52-
this(annotationType, true);
54+
this(annotationType, true, false);
5355
}
5456

5557
/**
@@ -84,16 +86,26 @@ protected boolean matchSelf(MetadataReader metadataReader) {
8486

8587
@Override
8688
protected Boolean matchSuperClass(String superClassName) {
87-
if (Object.class.getName().equals(superClassName)) {
88-
return Boolean.FALSE;
89+
return hasAnnotation(superClassName);
90+
}
91+
92+
@Override
93+
protected Boolean matchInterface(String interfaceName) {
94+
return hasAnnotation(interfaceName);
95+
}
96+
97+
protected Boolean hasAnnotation(String typeName) {
98+
if (Object.class.getName().equals(typeName)) {
99+
return false;
89100
}
90-
else if (superClassName.startsWith("java.")) {
101+
else if (typeName.startsWith("java")) {
91102
try {
92-
Class<?> clazz = getClass().getClassLoader().loadClass(superClassName);
93-
return (clazz.getAnnotation(this.annotationType) != null);
103+
Class<?> clazz = ClassUtils.forName(typeName, getClass().getClassLoader());
104+
return ((this.considerMetaAnnotations ? AnnotationUtils.getAnnotation(clazz, this.annotationType) :
105+
clazz.getAnnotation(this.annotationType)) != null);
94106
}
95-
catch (ClassNotFoundException ex) {
96-
// Class not found - can't determine a match that way.
107+
catch (Throwable ex) {
108+
// Class not regularly loadable - can't determine a match that way.
97109
}
98110
}
99111
return null;

0 commit comments

Comments
 (0)