Skip to content

Commit

Permalink
Improve diagnostics for LinkageError in case of ClassLoader mismatch
Browse files Browse the repository at this point in the history
Closes gh-25940
  • Loading branch information
jhoeller committed Jul 11, 2023
1 parent 9e7ee0c commit c1bf099
Showing 1 changed file with 7 additions and 5 deletions.
Expand Up @@ -576,15 +576,17 @@ public static Class defineClass(String className, byte[] b, ClassLoader loader,
c = (Class) lookupDefineClassMethod.invoke(lookup, b);
}
catch (InvocationTargetException ex) {
throw new CodeGenerationException(ex.getTargetException());
}
catch (IllegalAccessException ex) {
throw new CodeGenerationException(ex) {
Throwable target = ex.getTargetException();
if (target.getClass() != LinkageError.class && target.getClass() != IllegalAccessException.class) {
throw new CodeGenerationException(target);
}
throw new CodeGenerationException(target) {
@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();
"for ClassLoader.defineClass to be accessible on " + loader.getClass().getName() +
"; consider co-locating the affected class in that target ClassLoader instead.";
}
};
}
Expand Down

0 comments on commit c1bf099

Please sign in to comment.