Fallback to ClassLoader.defineClass for Lookup.defineClass LinkageError

Issue: SPR-16902
This commit is contained in:
Juergen Hoeller
2018-07-10 22:13:57 +02:00
parent 3a4b5c2ade
commit 6887802526

View File

@@ -493,15 +493,18 @@ public class ReflectUtils {
Class c = null;
if (contextClass != null && privateLookupInMethod != null && lookupDefineClassMethod != null) {
try {
MethodHandles.Lookup lookup =
(MethodHandles.Lookup) privateLookupInMethod.invoke(null, contextClass, MethodHandles.lookup());
MethodHandles.Lookup lookup = (MethodHandles.Lookup)
privateLookupInMethod.invoke(null, contextClass, MethodHandles.lookup());
c = (Class) lookupDefineClassMethod.invoke(lookup, b);
}
catch (InvocationTargetException ex) {
if (!(ex.getTargetException() instanceof IllegalArgumentException)) {
throw new CodeGenerationException(ex.getTargetException());
Throwable target = ex.getTargetException();
if (target.getClass() != LinkageError.class && target.getClass() != IllegalArgumentException.class) {
throw new CodeGenerationException(target);
}
// in case of IllegalArgumentException: fall through to defineClass
// in case of plain LinkageError (class already defined)
// or IllegalArgumentException (class in different package):
// fall through to traditional ClassLoader.defineClass below
}
catch (Throwable ex) {
throw new CodeGenerationException(ex);