HHH-12427 Prevent classloader leak in ByteBuddy based BasicProxyFactoryImpl
This commit is contained in:
parent
511a5a3618
commit
e7bd213c9e
|
@ -9,8 +9,6 @@ package org.hibernate.bytecode.internal.bytebuddy;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
@ -28,8 +26,6 @@ import net.bytebuddy.matcher.ElementMatchers;
|
||||||
|
|
||||||
public class BasicProxyFactoryImpl implements BasicProxyFactory {
|
public class BasicProxyFactoryImpl implements BasicProxyFactory {
|
||||||
|
|
||||||
private static final ConcurrentMap<Set<Class>, Class> CACHE = new ConcurrentHashMap<Set<Class>, Class>();
|
|
||||||
|
|
||||||
private static final Class[] NO_INTERFACES = new Class[0];
|
private static final Class[] NO_INTERFACES = new Class[0];
|
||||||
|
|
||||||
private final Class proxyClass;
|
private final Class proxyClass;
|
||||||
|
@ -47,10 +43,7 @@ public class BasicProxyFactoryImpl implements BasicProxyFactory {
|
||||||
key.addAll( Arrays.asList( interfaces ) );
|
key.addAll( Arrays.asList( interfaces ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
Class proxyClass = CACHE.get( key );
|
this.proxyClass = new ByteBuddy()
|
||||||
|
|
||||||
if ( proxyClass == null ) {
|
|
||||||
proxyClass = new ByteBuddy()
|
|
||||||
.with( TypeValidation.DISABLED )
|
.with( TypeValidation.DISABLED )
|
||||||
.with( new AuxiliaryType.NamingStrategy.SuffixingRandom( "HibernateBasicProxy" ) )
|
.with( new AuxiliaryType.NamingStrategy.SuffixingRandom( "HibernateBasicProxy" ) )
|
||||||
.subclass( superClass == null ? Object.class : superClass )
|
.subclass( superClass == null ? Object.class : superClass )
|
||||||
|
@ -63,13 +56,6 @@ public class BasicProxyFactoryImpl implements BasicProxyFactory {
|
||||||
.make()
|
.make()
|
||||||
.load( BasicProxyFactory.class.getClassLoader() )
|
.load( BasicProxyFactory.class.getClassLoader() )
|
||||||
.getLoaded();
|
.getLoaded();
|
||||||
Class previousProxy = CACHE.putIfAbsent( key, proxyClass );
|
|
||||||
if ( previousProxy != null ) {
|
|
||||||
proxyClass = previousProxy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.proxyClass = proxyClass;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getProxy() {
|
public Object getProxy() {
|
||||||
|
|
Loading…
Reference in New Issue