Skip to content

Commit c1bf099

Browse files
committed
Improve diagnostics for LinkageError in case of ClassLoader mismatch
Closes gh-25940
1 parent 9e7ee0c commit c1bf099

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,15 +576,17 @@ public static Class defineClass(String className, byte[] b, ClassLoader loader,
576576
c = (Class) lookupDefineClassMethod.invoke(lookup, b);
577577
}
578578
catch (InvocationTargetException ex) {
579-
throw new CodeGenerationException(ex.getTargetException());
580-
}
581-
catch (IllegalAccessException ex) {
582-
throw new CodeGenerationException(ex) {
579+
Throwable target = ex.getTargetException();
580+
if (target.getClass() != LinkageError.class && target.getClass() != IllegalAccessException.class) {
581+
throw new CodeGenerationException(target);
582+
}
583+
throw new CodeGenerationException(target) {
583584
@Override
584585
public String getMessage() {
585586
return "ClassLoader mismatch for [" + contextClass.getName() +
586587
"]: 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+
"for ClassLoader.defineClass to be accessible on " + loader.getClass().getName() +
589+
"; consider co-locating the affected class in that target ClassLoader instead.";
588590
}
589591
};
590592
}

0 commit comments

Comments
 (0)