Skip to content

Commit

Permalink
Polish BeanValidationBeanRegistrationAotProcessor[Tests]
Browse files Browse the repository at this point in the history
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 spring-projectsgh-33949
  • Loading branch information
sbrannen committed Nov 27, 2024
1 parent 9b0253e commit ea3bd7a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,21 @@ private static void processAheadOfTime(Class<?> clazz, Set<Class<?>> visitedClas
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 " + className +
" 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 " +
className + " 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 " + className, ex);
if (logger.isWarnEnabled()) {
logger.warn("Skipping validation constraint hint inference for class " + className, ex);
}
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void shouldProcessRecursiveGenericsWithoutInfiniteRecursion(Class<?> beanClass)

@Test // gh-33940
void shouldSkipConstraintWithMissingDependency() throws Exception {
FilteringClassLoader classLoader = new FilteringClassLoader(getClass().getClassLoader());
MissingDependencyClassLoader classLoader = new MissingDependencyClassLoader(getClass().getClassLoader());
Class<?> beanClass = classLoader.loadClass(ConstraintWithMissingDependency.class.getName());
process(beanClass);
assertThat(this.generationContext.getRuntimeHints().reflection().typeHints()).isEmpty();
Expand Down Expand Up @@ -280,14 +280,14 @@ static class BeanWithRecursiveOptional {

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);
}

Expand All @@ -298,7 +298,7 @@ protected boolean isEligibleForOverriding(String className) {

@Override
protected Class<?> loadClassForOverriding(String name) throws ClassNotFoundException {
if (name.contains("Filtered")) {
if (name.contains("MissingType")) {
throw new NoClassDefFoundError(name);
}
return super.loadClassForOverriding(name);
Expand Down

0 comments on commit ea3bd7a

Please sign in to comment.