HHH-14575 Adapt BasicProxyFactoryImpl to be more native-image friendly

This commit is contained in:
Sanne Grinovero 2021-04-28 10:24:20 +01:00
parent 1023ee02b9
commit 0a4cd8e800
1 changed files with 9 additions and 1 deletions

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.bytecode.internal.bytebuddy;
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@ -28,6 +29,7 @@ public class BasicProxyFactoryImpl implements BasicProxyFactory {
private final Class proxyClass;
private final ProxyConfiguration.Interceptor interceptor;
private final Constructor proxyClassConstructor;
@SuppressWarnings({ "unchecked", "rawtypes" })
public BasicProxyFactoryImpl(Class superClass, Class[] interfaces, ByteBuddyState byteBuddyState) {
@ -49,12 +51,18 @@ public class BasicProxyFactoryImpl implements BasicProxyFactory {
.intercept( byteBuddyState.getProxyDefinitionHelpers().getInterceptorFieldAccessor() )
);
this.interceptor = new PassThroughInterceptor( proxyClass.getName() );
try {
proxyClassConstructor = proxyClass.getConstructor();
}
catch (NoSuchMethodException e) {
throw new AssertionFailure( "Could not access default constructor from newly generated basic proxy" );
}
}
@Override
public Object getProxy() {
try {
final ProxyConfiguration proxy = (ProxyConfiguration) proxyClass.newInstance();
final ProxyConfiguration proxy = (ProxyConfiguration) proxyClassConstructor.newInstance();
proxy.$$_hibernate_set_interceptor( this.interceptor );
return proxy;
}