Skip to content

Commit

Permalink
HHH-14575 Adapt BasicProxyFactoryImpl to be more native-image friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed Apr 28, 2021
1 parent 0e2b19a commit cb1c87a
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -49,12 +51,18 @@ public BasicProxyFactoryImpl(Class superClass, Class[] interfaces, ByteBuddyStat
.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;
}
Expand Down

0 comments on commit cb1c87a

Please sign in to comment.