HHH-15108 - tweak to not ignore exceptions in AggregateClassLoader.findClass()

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2023-03-16 22:08:49 +01:00 committed by Steve Ebersole
parent c6fa754f06
commit 26a173ff8e
2 changed files with 22 additions and 3 deletions

View File

@ -11,6 +11,9 @@ import java.net.URL;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Optional;
import org.hibernate.internal.util.ExceptionHelper;
public class AggregatedClassLoader extends ClassLoader {
private final ClassLoader[] individualClassLoaders;
@ -196,18 +199,21 @@ public class AggregatedClassLoader extends ClassLoader {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
final Iterator<ClassLoader> clIterator = newClassLoaderIterator();
Throwable t = null;
while ( clIterator.hasNext() ) {
final ClassLoader classLoader = clIterator.next();
try {
return classLoader.loadClass( name );
}
catch (Exception ignore) {
catch (Exception ex) {
ExceptionHelper.combine( ( t == null ? t = new Throwable() : t ), ex );
}
catch (LinkageError ignore) {
catch (LinkageError le) {
ExceptionHelper.combine( ( t == null ? t = new Throwable() : t ), le );
}
}
throw new ClassNotFoundException( "Could not load requested class : " + name );
throw new ClassNotFoundException( "Could not load requested class : " + name, ( t != null && t.getSuppressed().length > 0 ? t : null ) );
}
private static ClassLoader locateSystemClassLoader() {

View File

@ -29,6 +29,19 @@ public final class ExceptionHelper {
return toProcess;
}
public static <T extends Throwable> T combine(T throwable, T otherThrowable) {
T toThrow = throwable;
if ( otherThrowable != null ) {
if ( toThrow != null ) {
toThrow.addSuppressed( otherThrowable );
}
else {
toThrow = otherThrowable;
}
}
return toThrow;
}
@SuppressWarnings("unchecked")
private static <T extends Throwable> void doThrow0(Throwable e) throws T {
throw (T) e;