Skip to content

Commit 9c45755

Browse files
committed
AnnotationTypeFilter prevents ASM-based loading of java.* interfaces as well
Issue: SPR-11719 (cherry picked from commit 945335d)
1 parent 5962fc2 commit 9c45755

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

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

+18-7
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,6 +19,7 @@
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;
2425

@@ -49,7 +50,7 @@ public class AnnotationTypeFilter extends AbstractTypeHierarchyTraversingFilter
4950
* @param annotationType the annotation type to match
5051
*/
5152
public AnnotationTypeFilter(Class<? extends Annotation> annotationType) {
52-
this(annotationType, true);
53+
this(annotationType, true, false);
5354
}
5455

5556
/**
@@ -84,13 +85,23 @@ protected boolean matchSelf(MetadataReader metadataReader) {
8485

8586
@Override
8687
protected Boolean matchSuperClass(String superClassName) {
87-
if (Object.class.getName().equals(superClassName)) {
88-
return Boolean.FALSE;
88+
return hasAnnotation(superClassName);
89+
}
90+
91+
@Override
92+
protected Boolean matchInterface(String interfaceName) {
93+
return hasAnnotation(interfaceName);
94+
}
95+
96+
protected Boolean hasAnnotation(String typeName) {
97+
if (Object.class.getName().equals(typeName)) {
98+
return false;
8999
}
90-
else if (superClassName.startsWith("java.")) {
100+
else if (typeName.startsWith("java.")) {
91101
try {
92-
Class<?> clazz = getClass().getClassLoader().loadClass(superClassName);
93-
return (clazz.getAnnotation(this.annotationType) != null);
102+
Class<?> clazz = getClass().getClassLoader().loadClass(typeName);
103+
return ((this.considerMetaAnnotations ? AnnotationUtils.getAnnotation(clazz, this.annotationType) :
104+
clazz.getAnnotation(this.annotationType)) != null);
94105
}
95106
catch (ClassNotFoundException ex) {
96107
// Class not found - can't determine a match that way.

0 commit comments

Comments
 (0)