Validate declared annotations before deciding between reflection and ASM

Issue: SPR-16564
This commit is contained in:
Juergen Hoeller
2018-03-12 13:40:26 +01:00
parent 1b1a69a144
commit 50e980c02f
3 changed files with 51 additions and 23 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.context.annotation;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.net.UnknownHostException;
import java.util.ArrayDeque;
import java.util.ArrayList;
@@ -55,6 +56,7 @@ import org.springframework.core.OrderComparator;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
@@ -659,8 +661,11 @@ class ConfigurationClassParser {
return new SourceClass(Object.class);
}
try {
// Sanity test that we can read annotations, if not fall back to ASM
classType.getAnnotations();
// Sanity test that we can reflectively read annotations,
// including Class attributes; if not -> fall back to ASM
for (Annotation ann : classType.getAnnotations()) {
AnnotationUtils.validateAnnotation(ann);
}
return new SourceClass(classType);
}
catch (Throwable ex) {