Optimize @Configuration class parsing a little

Update `ConfigurationClassParser` to skip `java.lang.annotation` types
which were often processed but would never provide useful results. Also
use a single shared immutable `SourceClass` instance to represent
`Object.class`.

Closes gh-22563
This commit is contained in:
Phillip Webb 2019-03-08 17:15:03 -08:00 committed by Juergen Hoeller
parent 37255afca4
commit aa4e56b251
1 changed files with 6 additions and 4 deletions

View File

@ -140,6 +140,8 @@ class ConfigurationClassParser {
private final DeferredImportSelectorHandler deferredImportSelectorHandler = new DeferredImportSelectorHandler();
private final SourceClass objectSourceClass = new SourceClass(Object.class);
/**
* Create a new {@link ConfigurationClassParser} instance that will be used
@ -639,8 +641,8 @@ class ConfigurationClassParser {
* Factory method to obtain a {@link SourceClass} from a {@link Class}.
*/
SourceClass asSourceClass(@Nullable Class<?> classType) throws IOException {
if (classType == null) {
return new SourceClass(Object.class);
if (classType == null || classType.getName().startsWith("java.lang.annotation")) {
return this.objectSourceClass;
}
try {
// Sanity test that we can reflectively read annotations,
@ -671,8 +673,8 @@ class ConfigurationClassParser {
* Factory method to obtain a {@link SourceClass} from a class name.
*/
SourceClass asSourceClass(@Nullable String className) throws IOException {
if (className == null) {
return new SourceClass(Object.class);
if (className == null || className.startsWith("java.lang.annotation")) {
return this.objectSourceClass;
}
if (className.startsWith("java")) {
// Never use ASM for core java types