Try loadClass on LinkageError in case of ClassLoader mismatch
See gh-34677
This commit is contained in:
parent
26869b0e4c
commit
7f2c1f447f
|
@ -527,15 +527,26 @@ public class ReflectUtils {
|
||||||
c = lookup.defineClass(b);
|
c = lookup.defineClass(b);
|
||||||
}
|
}
|
||||||
catch (LinkageError | IllegalAccessException ex) {
|
catch (LinkageError | IllegalAccessException ex) {
|
||||||
throw new CodeGenerationException(ex) {
|
if (ex instanceof LinkageError) {
|
||||||
@Override
|
// Could be a ClassLoader mismatch with the class pre-existing in a
|
||||||
public String getMessage() {
|
// parent ClassLoader -> try loadClass before giving up completely.
|
||||||
return "ClassLoader mismatch for [" + contextClass.getName() +
|
try {
|
||||||
"]: JVM should be started with --add-opens=java.base/java.lang=ALL-UNNAMED " +
|
c = contextClass.getClassLoader().loadClass(className);
|
||||||
"for ClassLoader.defineClass to be accessible on " + loader.getClass().getName() +
|
|
||||||
"; consider co-locating the affected class in that target ClassLoader instead.";
|
|
||||||
}
|
}
|
||||||
};
|
catch (ClassNotFoundException cnfe) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (c == null) {
|
||||||
|
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() +
|
||||||
|
"; consider co-locating the affected class in that target ClassLoader instead.";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
throw new CodeGenerationException(ex);
|
throw new CodeGenerationException(ex);
|
||||||
|
|
Loading…
Reference in New Issue