Merge branch '6.2.x'
This commit is contained in:
@@ -127,18 +127,25 @@ class BeanValidationBeanRegistrationAotProcessor implements BeanRegistrationAotP
|
||||
try {
|
||||
descriptor = validator.getConstraintsForClass(clazz);
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
catch (RuntimeException | LinkageError ex) {
|
||||
String className = clazz.getName();
|
||||
if (KotlinDetector.isKotlinType(clazz) && ex instanceof ArrayIndexOutOfBoundsException) {
|
||||
// See https://hibernate.atlassian.net/browse/HV-1796 and https://youtrack.jetbrains.com/issue/KT-40857
|
||||
logger.warn("Skipping validation constraint hint inference for class " + clazz +
|
||||
" due to an ArrayIndexOutOfBoundsException at validator level");
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Skipping validation constraint hint inference for class " + className +
|
||||
" due to an ArrayIndexOutOfBoundsException at validator level");
|
||||
}
|
||||
}
|
||||
else if (ex instanceof TypeNotPresentException) {
|
||||
logger.debug("Skipping validation constraint hint inference for class " +
|
||||
clazz + " due to a TypeNotPresentException at validator level: " + ex.getMessage());
|
||||
else if (ex instanceof TypeNotPresentException || ex instanceof NoClassDefFoundError) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Skipping validation constraint hint inference for class %s due to a %s for %s"
|
||||
.formatted(className, ex.getClass().getSimpleName(), ex.getMessage()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
logger.warn("Skipping validation constraint hint inference for class " + clazz, ex);
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Skipping validation constraint hint inference for class " + className, ex);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.springframework.beans.factory.aot.BeanRegistrationAotContribution;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.RegisteredBean;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.OverridingClassLoader;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
|
||||
@@ -134,6 +135,14 @@ class BeanValidationBeanRegistrationAotProcessorTests {
|
||||
.withMemberCategory(MemberCategory.DECLARED_FIELDS)).accepts(this.generationContext.getRuntimeHints());
|
||||
}
|
||||
|
||||
@Test // gh-33940
|
||||
void shouldSkipConstraintWithMissingDependency() throws Exception {
|
||||
MissingDependencyClassLoader classLoader = new MissingDependencyClassLoader(getClass().getClassLoader());
|
||||
Class<?> beanClass = classLoader.loadClass(ConstraintWithMissingDependency.class.getName());
|
||||
process(beanClass);
|
||||
assertThat(this.generationContext.getRuntimeHints().reflection().typeHints()).isEmpty();
|
||||
}
|
||||
|
||||
private void process(Class<?> beanClass) {
|
||||
BeanRegistrationAotContribution contribution = createContribution(beanClass);
|
||||
if (contribution != null) {
|
||||
@@ -269,4 +278,31 @@ class BeanValidationBeanRegistrationAotProcessorTests {
|
||||
Optional<BeanWithRecursiveOptional> optional;
|
||||
}
|
||||
|
||||
static class ConstraintWithMissingDependency {
|
||||
|
||||
MissingType missingType;
|
||||
}
|
||||
|
||||
static class MissingType {}
|
||||
|
||||
static class MissingDependencyClassLoader extends OverridingClassLoader {
|
||||
|
||||
MissingDependencyClassLoader(ClassLoader parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleForOverriding(String className) {
|
||||
return className.startsWith(BeanValidationBeanRegistrationAotProcessorTests.class.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> loadClassForOverriding(String name) throws ClassNotFoundException {
|
||||
if (name.contains("MissingType")) {
|
||||
throw new NoClassDefFoundError(name);
|
||||
}
|
||||
return super.loadClassForOverriding(name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user