HHH-12800 Use a class loading strategy suitable for the JDK used

The previously chosen strategy used misc.Unsafe which is not possible
anymore with JDK 11.
This commit is contained in:
Guillaume Smet 2018-07-13 14:31:04 +02:00
parent 7e69797a45
commit 9d36d1d91f
2 changed files with 4 additions and 3 deletions

View File

@ -91,7 +91,7 @@ public final class ByteBuddyState {
return buddy;
}
public static ClassLoadingStrategy<?> resolveClassLoadingStrategy(Class<?> originalClass) {
public static ClassLoadingStrategy<ClassLoader> resolveClassLoadingStrategy(Class<?> originalClass) {
if ( ClassInjector.UsingLookup.isAvailable() ) {
// This is only enabled for JDK 9+

View File

@ -8,11 +8,11 @@ package org.hibernate.test.annotations.tuplizer.bytebuddysubclass;
import java.io.Serializable;
import org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.tuple.Instantiator;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.implementation.FixedValue;
import net.bytebuddy.matcher.ElementMatchers;
@ -42,7 +42,8 @@ public class MyEntityInstantiator implements Instantiator {
.method( ElementMatchers.named( "toString" ) )
.intercept( FixedValue.value( "transformed" ) )
.make()
.load( entityClass.getClassLoader(), ClassLoadingStrategy.Default.INJECTION )
// we use our internal helper to get a class loading strategy suitable for the JDK used
.load( entityClass.getClassLoader(), ByteBuddyState.resolveClassLoadingStrategy( entityClass ) )
.getLoaded();
try {