Skip to content

Commit e6c0152

Browse files
committed
Force AOT resolution of Spring Factories constructors
This commit forces the resolution of all declared constructors when registering `RuntimeHints` for Spring factories. Resolving constructors can throw additional `NoClassDefFoundError` at runtime and during native image compilation, if a type exposed by the constructor is missing from the current classloader. See gh-27955
1 parent 8b6dcb9 commit e6c0152

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoaderRuntimeHintsRegistrar.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.core.io.support;
1818

19+
import java.lang.reflect.Constructor;
1920
import java.util.List;
2021
import java.util.Map;
2122
import java.util.function.Consumer;
@@ -88,9 +89,12 @@ private void registerHints(RuntimeHints hints, ClassLoader classLoader,
8889
@Nullable
8990
private Class<?> resolveClassName(ClassLoader classLoader, String factoryClassName) {
9091
try {
91-
return ClassUtils.resolveClassName(factoryClassName, classLoader);
92+
Class<?> className = ClassUtils.resolveClassName(factoryClassName, classLoader);
93+
// Force resolution of all constructors to catch
94+
Constructor<?>[] constructors = className.getDeclaredConstructors();
95+
return className;
9296
}
93-
catch (Exception ex) {
97+
catch (Throwable ex) {
9498
return null;
9599
}
96100
}

0 commit comments

Comments
 (0)