Polish BeanValidationBeanRegistrationAotProcessor[Tests]

The log message for a NoClassDefFoundError is now a DEBUG level message
handled like a TypeNotPresentException and similar to the following.

DEBUG: Skipping validation constraint hint inference for class
org.example.CustomConstraint due to a NoClassDefFoundError for
com.example.MissingType

See gh-33949
This commit is contained in:
Sam Brannen
2024-11-27 12:35:13 +01:00
parent 9b0253e117
commit ea3bd7ae0c
2 changed files with 18 additions and 12 deletions

View File

@@ -131,15 +131,21 @@ class BeanValidationBeanRegistrationAotProcessor implements BeanRegistrationAotP
String className = clazz.getName(); String className = clazz.getName();
if (KotlinDetector.isKotlinType(clazz) && ex instanceof ArrayIndexOutOfBoundsException) { if (KotlinDetector.isKotlinType(clazz) && ex instanceof ArrayIndexOutOfBoundsException) {
// See https://hibernate.atlassian.net/browse/HV-1796 and https://youtrack.jetbrains.com/issue/KT-40857 // 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 " + className + if (logger.isWarnEnabled()) {
" due to an ArrayIndexOutOfBoundsException at validator level"); logger.warn("Skipping validation constraint hint inference for class " + className +
" due to an ArrayIndexOutOfBoundsException at validator level");
}
} }
else if (ex instanceof TypeNotPresentException) { else if (ex instanceof TypeNotPresentException || ex instanceof NoClassDefFoundError) {
logger.debug("Skipping validation constraint hint inference for class " + if (logger.isDebugEnabled()) {
className + " due to a TypeNotPresentException at validator level: " + ex.getMessage()); logger.debug("Skipping validation constraint hint inference for class %s due to a %s for %s"
.formatted(className, ex.getClass().getSimpleName(), ex.getMessage()));
}
} }
else { else {
logger.warn("Skipping validation constraint hint inference for class " + className, ex); if (logger.isWarnEnabled()) {
logger.warn("Skipping validation constraint hint inference for class " + className, ex);
}
} }
return; return;
} }

View File

@@ -137,7 +137,7 @@ class BeanValidationBeanRegistrationAotProcessorTests {
@Test // gh-33940 @Test // gh-33940
void shouldSkipConstraintWithMissingDependency() throws Exception { void shouldSkipConstraintWithMissingDependency() throws Exception {
FilteringClassLoader classLoader = new FilteringClassLoader(getClass().getClassLoader()); MissingDependencyClassLoader classLoader = new MissingDependencyClassLoader(getClass().getClassLoader());
Class<?> beanClass = classLoader.loadClass(ConstraintWithMissingDependency.class.getName()); Class<?> beanClass = classLoader.loadClass(ConstraintWithMissingDependency.class.getName());
process(beanClass); process(beanClass);
assertThat(this.generationContext.getRuntimeHints().reflection().typeHints()).isEmpty(); assertThat(this.generationContext.getRuntimeHints().reflection().typeHints()).isEmpty();
@@ -280,14 +280,14 @@ class BeanValidationBeanRegistrationAotProcessorTests {
static class ConstraintWithMissingDependency { static class ConstraintWithMissingDependency {
private final Filtered filtered = new Filtered(); MissingType missingType;
} }
static class Filtered {} static class MissingType {}
static class FilteringClassLoader extends OverridingClassLoader { static class MissingDependencyClassLoader extends OverridingClassLoader {
FilteringClassLoader(ClassLoader parent) { MissingDependencyClassLoader(ClassLoader parent) {
super(parent); super(parent);
} }
@@ -298,7 +298,7 @@ class BeanValidationBeanRegistrationAotProcessorTests {
@Override @Override
protected Class<?> loadClassForOverriding(String name) throws ClassNotFoundException { protected Class<?> loadClassForOverriding(String name) throws ClassNotFoundException {
if (name.contains("Filtered")) { if (name.contains("MissingType")) {
throw new NoClassDefFoundError(name); throw new NoClassDefFoundError(name);
} }
return super.loadClassForOverriding(name); return super.loadClassForOverriding(name);