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
This commit is contained in:
parent
8b6dcb9ccc
commit
e6c0152916
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.core.io.support;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
|
@ -88,9 +89,12 @@ class SpringFactoriesLoaderRuntimeHintsRegistrar implements RuntimeHintsRegistra
|
|||
@Nullable
|
||||
private Class<?> resolveClassName(ClassLoader classLoader, String factoryClassName) {
|
||||
try {
|
||||
return ClassUtils.resolveClassName(factoryClassName, classLoader);
|
||||
Class<?> className = ClassUtils.resolveClassName(factoryClassName, classLoader);
|
||||
// Force resolution of all constructors to catch
|
||||
Constructor<?>[] constructors = className.getDeclaredConstructors();
|
||||
return className;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue