Skip to content

Commit ff9f5fd

Browse files
committed
Polish OnBeanCondition
Polish `OnBeanCondition` and make it easier to remove `BeanTypeRegistry` in the future. See gh-17594
1 parent ff9d0cf commit ff9f5fd

File tree

4 files changed

+319
-220
lines changed

4 files changed

+319
-220
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/FilteringSpringBootCondition.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void setBeanClassLoader(ClassLoader classLoader) {
8181
this.beanClassLoader = classLoader;
8282
}
8383

84-
protected List<String> filter(Collection<String> classNames, ClassNameFilter classNameFilter,
84+
protected final List<String> filter(Collection<String> classNames, ClassNameFilter classNameFilter,
8585
ClassLoader classLoader) {
8686
if (CollectionUtils.isEmpty(classNames)) {
8787
return Collections.emptyList();
@@ -95,6 +95,22 @@ protected List<String> filter(Collection<String> classNames, ClassNameFilter cla
9595
return matches;
9696
}
9797

98+
/**
99+
* Slightly faster variant of {@link ClassUtils#forName(String, ClassLoader)} that
100+
* doesn't deal with primitives, arrays or innter types.
101+
* @param className the class name to resolve
102+
* @param classLoader the class loader to use
103+
* @return a resolved class
104+
* @throws ClassNotFoundException if the class cannot be found
105+
*/
106+
protected static Class<?> resolve(String className, ClassLoader classLoader) throws ClassNotFoundException {
107+
if (classLoader != null) {
108+
return classLoader.loadClass(className);
109+
}
110+
return Class.forName(className);
111+
112+
}
113+
98114
protected enum ClassNameFilter {
99115

100116
PRESENT {
@@ -122,21 +138,14 @@ static boolean isPresent(String className, ClassLoader classLoader) {
122138
classLoader = ClassUtils.getDefaultClassLoader();
123139
}
124140
try {
125-
forName(className, classLoader);
141+
resolve(className, classLoader);
126142
return true;
127143
}
128144
catch (Throwable ex) {
129145
return false;
130146
}
131147
}
132148

133-
private static Class<?> forName(String className, ClassLoader classLoader) throws ClassNotFoundException {
134-
if (classLoader != null) {
135-
return classLoader.loadClass(className);
136-
}
137-
return Class.forName(className);
138-
}
139-
140149
}
141150

142151
}

0 commit comments

Comments
 (0)