HHH-15595 Delete ClassLoadingStrategyHelper

This commit is contained in:
Sanne Grinovero 2022-10-11 22:16:24 +01:00 committed by Sanne Grinovero
parent fe4091bd42
commit bf8040638c
2 changed files with 14 additions and 31 deletions

View File

@ -13,11 +13,11 @@ import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.returns;
import static org.hibernate.bytecode.spi.ClassLoadingStrategyHelper.resolveClassLoadingStrategy;
import static org.hibernate.internal.CoreLogging.messageLogger;
import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
@ -39,6 +39,7 @@ import net.bytebuddy.asm.MemberSubstitution;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.DynamicType.Unloaded;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.dynamic.scaffold.TypeValidation;
import net.bytebuddy.implementation.FieldAccessor;
import net.bytebuddy.implementation.MethodDelegation;
@ -56,6 +57,8 @@ public final class ByteBuddyState {
private static final CoreMessageLogger LOG = messageLogger( ByteBuddyState.class );
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
private static final boolean DEBUG = false;
private final ByteBuddy byteBuddy;
@ -381,4 +384,14 @@ public final class ByteBuddyState {
// do nothing
}
}
private static ClassLoadingStrategy<ClassLoader> resolveClassLoadingStrategy(Class<?> originalClass) {
try {
return ClassLoadingStrategy.UsingLookup.of( MethodHandles.privateLookupIn( originalClass, LOOKUP ) );
}
catch (Throwable e) {
throw new HibernateException( LOG.bytecodeEnhancementFailedUnableToGetPrivateLookupFor( originalClass.getName() ), e );
}
}
}

View File

@ -1,30 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.bytecode.spi;
import java.lang.invoke.MethodHandles;
import org.hibernate.HibernateException;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import static org.hibernate.internal.CoreLogging.messageLogger;
public class ClassLoadingStrategyHelper {
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
public static ClassLoadingStrategy<ClassLoader> resolveClassLoadingStrategy(Class<?> originalClass) {
try {
return ClassLoadingStrategy.UsingLookup.of( MethodHandles.privateLookupIn( originalClass, LOOKUP ) );
}
catch (Throwable e) {
throw new HibernateException( messageLogger( ClassLoadingStrategyHelper.class ).bytecodeEnhancementFailedUnableToGetPrivateLookupFor( originalClass.getName() ), e );
}
}
}