DATACMNS-1079 - Disable generated property accessors if ClassLoader is encapsulated.

ClassGeneratingPropertyAccessorFactory does not work with Java 9 (encapsulated modules, without --permit-illegal-access), because making ClassLoader.defineClass accessible fails.

Therefore this change moves call to setAccessible to the check that ensures availability of the method so isSupported(…) returns false.

Original pull request: #224.
This commit is contained in:
Jens Schauder
2017-06-02 13:55:43 +02:00
committed by Mark Paluch
parent 07da629356
commit 59f52a9e35

View File

@@ -1463,7 +1463,6 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
try {
Method defineClass = getClassLoaderMethod(persistentEntity);
defineClass.setAccessible(true);
return (Class<?>) defineClass.invoke(classLoader, name, bytes, offset, len,
persistentEntity.getClass().getProtectionDomain());
@@ -1478,8 +1477,19 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
ClassLoader classLoader = entity.getType().getClassLoader();
Class<?> classLoaderClass = classLoader.getClass();
return ReflectionUtils.findMethod(classLoaderClass, "defineClass", String.class, byte[].class, Integer.TYPE,
Integer.TYPE, ProtectionDomain.class);
Method defineClass = ReflectionUtils.findMethod( //
classLoaderClass, //
"defineClass", //
String.class, //
byte[].class, //
Integer.TYPE, //
Integer.TYPE, //
ProtectionDomain.class //
);
defineClass.setAccessible(true);
return defineClass;
}
}
}