diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BasicProxyFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BasicProxyFactoryImpl.java index dc7eeb11f5..ee493ca6c0 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BasicProxyFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BasicProxyFactoryImpl.java @@ -26,9 +26,7 @@ import net.bytebuddy.matcher.ElementMatchers; public class BasicProxyFactoryImpl implements BasicProxyFactory { private static final Class[] NO_INTERFACES = new Class[0]; - private static final NamingStrategy PROXY_NAMING = Environment.useLegacyProxyClassnames() ? - new NamingStrategy.SuffixingRandom( "HibernateBasicProxy$" ) : - new NamingStrategy.SuffixingRandom( "HibernateBasicProxy" ); + private static final String PROXY_NAMING_SUFFIX = Environment.useLegacyProxyClassnames() ? "HibernateBasicProxy$" : "HibernateBasicProxy"; private final Class proxyClass; @@ -48,7 +46,7 @@ public class BasicProxyFactoryImpl implements BasicProxyFactory { } this.proxyClass = bytebuddy.getCurrentyByteBuddy() - .with( PROXY_NAMING ) + .with( new NamingStrategy.SuffixingRandom( PROXY_NAMING_SUFFIX, new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( superClassOrMainInterface.getName() ) ) ) .subclass( superClass == null ? Object.class : superClass ) .implement( interfaces == null ? NO_INTERFACES : interfaces ) .defineField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME, ProxyConfiguration.Interceptor.class, Visibility.PRIVATE ) diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java index 9c2085de21..05e8e865e5 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java @@ -38,8 +38,8 @@ import net.bytebuddy.matcher.ElementMatchers; public class BytecodeProviderImpl implements BytecodeProvider { private static final ByteBuddyState bytebuddy = new ByteBuddyState(); - private static final NamingStrategy.SuffixingRandom instantiatorName = new NamingStrategy.SuffixingRandom( "HibernateInstantiator" ); - private static final NamingStrategy.SuffixingRandom optimizerName = new NamingStrategy.SuffixingRandom( "HibernateAccessOptimizer" ); + private static final String INSTANTIATOR_PROXY_NAMING_SUFFIX = "HibernateInstantiator"; + private static final String OPTIMIZER_PROXY_NAMING_SUFFIX = "HibernateAccessOptimizer"; private static final ElementMatcher.Junction newInstanceMethodName = ElementMatchers.named( "newInstance" ); private static final ElementMatcher.Junction getPropertyValuesMethodName = ElementMatchers.named( "getPropertyValues" ); private static final ElementMatcher.Junction setPropertyValuesMethodName = ElementMatchers.named( "setPropertyValues" ); @@ -62,7 +62,8 @@ public class BytecodeProviderImpl implements BytecodeProvider { final Constructor constructor = findConstructor( clazz ); final Class fastClass = bytebuddy.getCurrentyByteBuddy() - .with( instantiatorName ) + .with( new NamingStrategy.SuffixingRandom( INSTANTIATOR_PROXY_NAMING_SUFFIX, + new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( clazz.getName() ) ) ) .subclass( ReflectionOptimizer.InstantiationOptimizer.class ) .method( newInstanceMethodName ) .intercept( MethodCall.construct( constructor ) ) @@ -71,7 +72,8 @@ public class BytecodeProviderImpl implements BytecodeProvider { .getLoaded(); final Class bulkAccessor = bytebuddy.getCurrentyByteBuddy() - .with( optimizerName ) + .with( new NamingStrategy.SuffixingRandom( OPTIMIZER_PROXY_NAMING_SUFFIX, + new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( clazz.getName() ) ) ) .subclass( ReflectionOptimizer.AccessOptimizer.class ) .method( getPropertyValuesMethodName ) .intercept( new Implementation.Simple( new GetPropertyValues( clazz, getters ) ) ) diff --git a/hibernate-core/src/main/java/org/hibernate/proxy/pojo/bytebuddy/ByteBuddyProxyFactory.java b/hibernate-core/src/main/java/org/hibernate/proxy/pojo/bytebuddy/ByteBuddyProxyFactory.java index dc5c2cd51c..0f8d0cd753 100644 --- a/hibernate-core/src/main/java/org/hibernate/proxy/pojo/bytebuddy/ByteBuddyProxyFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/proxy/pojo/bytebuddy/ByteBuddyProxyFactory.java @@ -47,9 +47,7 @@ import static org.hibernate.internal.CoreLogging.messageLogger; public class ByteBuddyProxyFactory implements ProxyFactory, Serializable { private static final CoreMessageLogger LOG = messageLogger( ByteBuddyProxyFactory.class ); - private static final NamingStrategy PROXY_NAMING = Environment.useLegacyProxyClassnames() ? - new NamingStrategy.SuffixingRandom( "HibernateProxy$" ) : - new NamingStrategy.SuffixingRandom( "HibernateProxy" ); + private static final String PROXY_NAMING_SUFFIX = Environment.useLegacyProxyClassnames() ? "HibernateProxy$" : "HibernateProxy"; private Class persistentClass; private String entityName; @@ -102,7 +100,7 @@ public class ByteBuddyProxyFactory implements ProxyFactory, Serializable { return cacheForProxies.findOrInsert( persistentClass.getClassLoader(), new TypeCache.SimpleKey(key), () -> ByteBuddyState.getStaticByteBuddyInstance() .ignore( isSynthetic().and( named( "getMetaClass" ).and( returns( td -> "groovy.lang.MetaClass".equals( td.getName() ) ) ) ) ) - .with( PROXY_NAMING ) + .with( new NamingStrategy.SuffixingRandom( PROXY_NAMING_SUFFIX, new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( persistentClass.getName() ) ) ) .subclass( interfaces.length == 1 ? persistentClass : Object.class, ConstructorStrategy.Default.IMITATE_SUPER_CLASS_OPENING ) .implement( (Type[]) interfaces ) .method( isVirtual().and( not( isFinalizer() ) ) )