Skip to content

Commit aa4e56b

Browse files
philwebbjhoeller
authored andcommitted
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
1 parent 37255af commit aa4e56b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ class ConfigurationClassParser {
140140

141141
private final DeferredImportSelectorHandler deferredImportSelectorHandler = new DeferredImportSelectorHandler();
142142

143+
private final SourceClass objectSourceClass = new SourceClass(Object.class);
144+
143145

144146
/**
145147
* Create a new {@link ConfigurationClassParser} instance that will be used
@@ -639,8 +641,8 @@ private SourceClass asSourceClass(ConfigurationClass configurationClass) throws
639641
* Factory method to obtain a {@link SourceClass} from a {@link Class}.
640642
*/
641643
SourceClass asSourceClass(@Nullable Class<?> classType) throws IOException {
642-
if (classType == null) {
643-
return new SourceClass(Object.class);
644+
if (classType == null || classType.getName().startsWith("java.lang.annotation")) {
645+
return this.objectSourceClass;
644646
}
645647
try {
646648
// Sanity test that we can reflectively read annotations,
@@ -671,8 +673,8 @@ private Collection<SourceClass> asSourceClasses(String... classNames) throws IOE
671673
* Factory method to obtain a {@link SourceClass} from a class name.
672674
*/
673675
SourceClass asSourceClass(@Nullable String className) throws IOException {
674-
if (className == null) {
675-
return new SourceClass(Object.class);
676+
if (className == null || className.startsWith("java.lang.annotation")) {
677+
return this.objectSourceClass;
676678
}
677679
if (className.startsWith("java")) {
678680
// Never use ASM for core java types

0 commit comments

Comments
 (0)