Skip to content

Commit

Permalink
AnnotationTypeFilter prevents ASM-based loading of java.* interfaces …
Browse files Browse the repository at this point in the history
…as well

Issue: SPR-11719
(cherry picked from commit 945335d)
  • Loading branch information
jhoeller committed Apr 24, 2014
1 parent 5962fc2 commit 9c45755
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.Inherited;

import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.classreading.MetadataReader;

Expand Down Expand Up @@ -49,7 +50,7 @@ public class AnnotationTypeFilter extends AbstractTypeHierarchyTraversingFilter
* @param annotationType the annotation type to match
*/
public AnnotationTypeFilter(Class<? extends Annotation> annotationType) {
this(annotationType, true);
this(annotationType, true, false);
}

/**
Expand Down Expand Up @@ -84,13 +85,23 @@ protected boolean matchSelf(MetadataReader metadataReader) {

@Override
protected Boolean matchSuperClass(String superClassName) {
if (Object.class.getName().equals(superClassName)) {
return Boolean.FALSE;
return hasAnnotation(superClassName);
}

@Override
protected Boolean matchInterface(String interfaceName) {
return hasAnnotation(interfaceName);
}

protected Boolean hasAnnotation(String typeName) {
if (Object.class.getName().equals(typeName)) {
return false;
}
else if (superClassName.startsWith("java.")) {
else if (typeName.startsWith("java.")) {
try {
Class<?> clazz = getClass().getClassLoader().loadClass(superClassName);
return (clazz.getAnnotation(this.annotationType) != null);
Class<?> clazz = getClass().getClassLoader().loadClass(typeName);
return ((this.considerMetaAnnotations ? AnnotationUtils.getAnnotation(clazz, this.annotationType) :
clazz.getAnnotation(this.annotationType)) != null);
}
catch (ClassNotFoundException ex) {
// Class not found - can't determine a match that way.
Expand Down

0 comments on commit 9c45755

Please sign in to comment.