Improve diagnostics for CGLIB ClassLoader mismatch with --add-opens hint

Closes gh-28747
This commit is contained in:
Juergen Hoeller 2022-07-13 11:10:00 +02:00
parent d72aeac319
commit de1b938e2e
1 changed files with 11 additions and 1 deletions

View File

@ -490,7 +490,7 @@ public class ReflectUtils {
return defineClass(className, b, loader, protectionDomain, null);
}
@SuppressWarnings("deprecation") // on JDK 9
@SuppressWarnings({"deprecation", "serial"})
public static Class defineClass(String className, byte[] b, ClassLoader loader,
ProtectionDomain protectionDomain, Class<?> contextClass) throws Exception {
@ -578,6 +578,16 @@ public class ReflectUtils {
catch (InvocationTargetException ex) {
throw new CodeGenerationException(ex.getTargetException());
}
catch (IllegalAccessException ex) {
throw new CodeGenerationException(ex) {
@Override
public String getMessage() {
return "ClassLoader mismatch for [" + contextClass.getName() +
"]: JVM should be started with --add-opens=java.base/java.lang=ALL-UNNAMED " +
"for ClassLoader.defineClass to be accessible on " + loader.getClass().getName();
}
};
}
catch (Throwable ex) {
throw new CodeGenerationException(ex);
}