From 1fa92d6b5ee40927339fa64ebe464120511cecaa Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Fri, 26 May 2023 10:37:30 +0800 Subject: [PATCH] HV-1950 Suppress java.lang.NoClassDefFoundError: com/sun/el/ExpressionFactoryImpl It will mislead user that hibernate validator will rely on particular EL implementation. --- .../ResourceBundleMessageInterpolator.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/engine/src/main/java/org/hibernate/validator/messageinterpolation/ResourceBundleMessageInterpolator.java b/engine/src/main/java/org/hibernate/validator/messageinterpolation/ResourceBundleMessageInterpolator.java index b7164aa1a8..3994fc5848 100644 --- a/engine/src/main/java/org/hibernate/validator/messageinterpolation/ResourceBundleMessageInterpolator.java +++ b/engine/src/main/java/org/hibernate/validator/messageinterpolation/ResourceBundleMessageInterpolator.java @@ -38,6 +38,7 @@ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI * @author Adam Stawicki * @author Guillaume Smet + * @author Yanming Zhou */ public class ResourceBundleMessageInterpolator extends AbstractMessageInterpolator { @@ -200,11 +201,16 @@ private static ExpressionFactory buildExpressionFactory() { // Finally we try the CL of the EL implementation itself. This is necessary for OSGi now that the // implementation is separated from the API. - run( SetContextClassLoader.action( ExpressionFactoryImpl.class.getClassLoader() ) ); - if ( canLoadExpressionFactory() ) { - ExpressionFactory expressionFactory = ELManager.getExpressionFactory(); - LOG.debug( "Loaded expression factory via com.sun.el classloader" ); - return expressionFactory; + try { + run( SetContextClassLoader.action( ExpressionFactoryImpl.class.getClassLoader() ) ); + if ( canLoadExpressionFactory() ) { + ExpressionFactory expressionFactory = ELManager.getExpressionFactory(); + LOG.debug( "Loaded expression factory via com.sun.el classloader" ); + return expressionFactory; + } + } + catch (NoClassDefFoundError err) { + // ignore } } catch (Throwable e) {