Skip runtime hint registration for constraint with missing dependencies

Prior to this commit, AOT processing for bean validation failed with a
NoClassDefFoundError for constraints with missing dependencies.

With this commit, the processing no longer fails, and a warning is
logged instead.

See gh-33940
Closes gh-33949

Co-authored-by: Sam Brannen <sam.brannen@broadcom.com>
This commit is contained in:
Stefano Cordio
2024-11-23 16:10:47 +01:00
committed by Sam Brannen
parent f3753e6d64
commit 9b0253e117
2 changed files with 41 additions and 4 deletions

View File

@@ -127,18 +127,19 @@ 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 +
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());
className + " due to a TypeNotPresentException at validator level: " + ex.getMessage());
}
else {
logger.warn("Skipping validation constraint hint inference for class " + clazz, ex);
logger.warn("Skipping validation constraint hint inference for class " + className, ex);
}
return;
}