Skip to content

Commit de1b938

Browse files
committed
Improve diagnostics for CGLIB ClassLoader mismatch with --add-opens hint
Closes gh-28747
1 parent d72aeac commit de1b938

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

spring-core/src/main/java/org/springframework/cglib/core/ReflectUtils.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ public static Class defineClass(String className, byte[] b, ClassLoader loader,
490490
return defineClass(className, b, loader, protectionDomain, null);
491491
}
492492

493-
@SuppressWarnings("deprecation") // on JDK 9
493+
@SuppressWarnings({"deprecation", "serial"})
494494
public static Class defineClass(String className, byte[] b, ClassLoader loader,
495495
ProtectionDomain protectionDomain, Class<?> contextClass) throws Exception {
496496

@@ -578,6 +578,16 @@ public static Class defineClass(String className, byte[] b, ClassLoader loader,
578578
catch (InvocationTargetException ex) {
579579
throw new CodeGenerationException(ex.getTargetException());
580580
}
581+
catch (IllegalAccessException ex) {
582+
throw new CodeGenerationException(ex) {
583+
@Override
584+
public String getMessage() {
585+
return "ClassLoader mismatch for [" + contextClass.getName() +
586+
"]: JVM should be started with --add-opens=java.base/java.lang=ALL-UNNAMED " +
587+
"for ClassLoader.defineClass to be accessible on " + loader.getClass().getName();
588+
}
589+
};
590+
}
581591
catch (Throwable ex) {
582592
throw new CodeGenerationException(ex);
583593
}

0 commit comments

Comments
 (0)