Skip to content

Commit ea3bd7a

Browse files
committed
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
1 parent 9b0253e commit ea3bd7a

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

spring-context/src/main/java/org/springframework/validation/beanvalidation/BeanValidationBeanRegistrationAotProcessor.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,21 @@ private static void processAheadOfTime(Class<?> clazz, Set<Class<?>> visitedClas
131131
String className = clazz.getName();
132132
if (KotlinDetector.isKotlinType(clazz) && ex instanceof ArrayIndexOutOfBoundsException) {
133133
// See https://hibernate.atlassian.net/browse/HV-1796 and https://youtrack.jetbrains.com/issue/KT-40857
134-
logger.warn("Skipping validation constraint hint inference for class " + className +
135-
" due to an ArrayIndexOutOfBoundsException at validator level");
134+
if (logger.isWarnEnabled()) {
135+
logger.warn("Skipping validation constraint hint inference for class " + className +
136+
" due to an ArrayIndexOutOfBoundsException at validator level");
137+
}
136138
}
137-
else if (ex instanceof TypeNotPresentException) {
138-
logger.debug("Skipping validation constraint hint inference for class " +
139-
className + " due to a TypeNotPresentException at validator level: " + ex.getMessage());
139+
else if (ex instanceof TypeNotPresentException || ex instanceof NoClassDefFoundError) {
140+
if (logger.isDebugEnabled()) {
141+
logger.debug("Skipping validation constraint hint inference for class %s due to a %s for %s"
142+
.formatted(className, ex.getClass().getSimpleName(), ex.getMessage()));
143+
}
140144
}
141145
else {
142-
logger.warn("Skipping validation constraint hint inference for class " + className, ex);
146+
if (logger.isWarnEnabled()) {
147+
logger.warn("Skipping validation constraint hint inference for class " + className, ex);
148+
}
143149
}
144150
return;
145151
}

spring-context/src/test/java/org/springframework/validation/beanvalidation/BeanValidationBeanRegistrationAotProcessorTests.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void shouldProcessRecursiveGenericsWithoutInfiniteRecursion(Class<?> beanClass)
137137

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

281281
static class ConstraintWithMissingDependency {
282282

283-
private final Filtered filtered = new Filtered();
283+
MissingType missingType;
284284
}
285285

286-
static class Filtered {}
286+
static class MissingType {}
287287

288-
static class FilteringClassLoader extends OverridingClassLoader {
288+
static class MissingDependencyClassLoader extends OverridingClassLoader {
289289

290-
FilteringClassLoader(ClassLoader parent) {
290+
MissingDependencyClassLoader(ClassLoader parent) {
291291
super(parent);
292292
}
293293

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

299299
@Override
300300
protected Class<?> loadClassForOverriding(String name) throws ClassNotFoundException {
301-
if (name.contains("Filtered")) {
301+
if (name.contains("MissingType")) {
302302
throw new NoClassDefFoundError(name);
303303
}
304304
return super.loadClassForOverriding(name);

0 commit comments

Comments
 (0)