Try loadClass on LinkageError in case of ClassLoader mismatch

See gh-34677
This commit is contained in:
Juergen Hoeller 2025-04-10 18:30:45 +02:00
parent 26869b0e4c
commit 7f2c1f447f
1 changed files with 19 additions and 8 deletions

View File

@ -527,6 +527,16 @@ public class ReflectUtils {
c = lookup.defineClass(b);
}
catch (LinkageError | IllegalAccessException ex) {
if (ex instanceof LinkageError) {
// Could be a ClassLoader mismatch with the class pre-existing in a
// parent ClassLoader -> try loadClass before giving up completely.
try {
c = contextClass.getClassLoader().loadClass(className);
}
catch (ClassNotFoundException cnfe) {
}
}
if (c == null) {
throw new CodeGenerationException(ex) {
@Override
public String getMessage() {
@ -537,6 +547,7 @@ public class ReflectUtils {
}
};
}
}
catch (Throwable ex) {
throw new CodeGenerationException(ex);
}