Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@
<!--
Provided dependencies
-->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.el</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
Expand All @@ -79,6 +74,11 @@
<!--
Optional dependencies
-->
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
Expand Down Expand Up @@ -115,6 +115,11 @@
<!--
Test dependencies
-->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.el</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
package org.hibernate.validator.messageinterpolation;

import java.lang.invoke.MethodHandles;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collections;
Expand All @@ -24,8 +27,6 @@
import org.hibernate.validator.spi.messageinterpolation.LocaleResolver;
import org.hibernate.validator.spi.resourceloading.ResourceBundleLocator;

import com.sun.el.ExpressionFactoryImpl;

import jakarta.el.ELManager;
import jakarta.el.ExpressionFactory;

Expand Down Expand Up @@ -200,7 +201,10 @@ 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() ) );
// Instead of running this:
// run( SetContextClassLoader.action( ExpressionFactoryImpl.class.getClassLoader() ) );
// we do some reflection "magic" to not have a dependency on an implementation of the expression language:
run( SetContextClassLoader.action( classLoaderForExpressionFactory( originalContextClassLoader ) ) );
if ( canLoadExpressionFactory() ) {
ExpressionFactory expressionFactory = ELManager.getExpressionFactory();
LOG.debug( "Loaded expression factory via com.sun.el classloader" );
Expand All @@ -218,6 +222,33 @@ private static ExpressionFactory buildExpressionFactory() {
throw LOG.getUnableToInitializeELExpressionFactoryException( null );
}

private static ClassLoader classLoaderForExpressionFactory(ClassLoader cl) throws Exception {
try {
Class<?> fu = cl.loadClass( "org.osgi.framework.FrameworkUtil" );
Method getBundle = fu.getMethod( "getBundle", Class.class );
Object currentBundle = getBundle.invoke( null, ResourceBundleMessageInterpolator.class );
if ( currentBundle != null ) {
Object context = cl.loadClass( "org.osgi.framework.Bundle" ).getMethod( "getBundleContext" ).invoke( currentBundle );
Object bundles = cl.loadClass( "org.osgi.framework.BundleContext" ).getMethod( "getBundles" ).invoke( context );
Method loadClass = cl.loadClass( "org.osgi.framework.Bundle" ).getMethod( "loadClass", String.class );
int n = Array.getLength( bundles );
for ( int i = 0; i < n; i++ ) {
try {
Object bundle = Array.get( bundles, i );
return ( (Class<?>) loadClass.invoke( bundle, "com.sun.el.ExpressionFactoryImpl" ) ).getClassLoader();
}
catch (Exception e) {
//
}
}
}
}
catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw e;
}
return null;
}

/**
* Instead of testing the different class loaders via {@link ELManager}, we directly access the
* {@link ExpressionFactory}. This avoids issues with loading the {@code ELUtil} class (used by {@code ELManager})
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@
<artifactId>jakarta.el</artifactId>
<version>${version.org.glassfish.jakarta.el}</version>
</dependency>
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
<version>${version.jakarta.el-api}</version>
</dependency>
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>classmate</artifactId>
Expand Down