Skip to content

Commit 4172581

Browse files
committed
Try loadClass on LinkageError in case of same ClassLoader as well
Closes gh-34824
1 parent c88ba6c commit 4172581

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,21 @@ public static Class defineClass(String className, byte[] b, ClassLoader loader,
463463
c = lookup.defineClass(b);
464464
}
465465
catch (LinkageError | IllegalArgumentException ex) {
466-
// in case of plain LinkageError (class already defined)
467-
// or IllegalArgumentException (class in different package):
468-
// fall through to traditional ClassLoader.defineClass below
469-
t = ex;
466+
if (ex instanceof LinkageError) {
467+
// Could be a ClassLoader mismatch with the class pre-existing in a
468+
// parent ClassLoader -> try loadClass before giving up completely.
469+
try {
470+
c = contextClass.getClassLoader().loadClass(className);
471+
}
472+
catch (ClassNotFoundException cnfe) {
473+
}
474+
}
475+
if (c == null) {
476+
// in case of plain LinkageError (class already defined)
477+
// or IllegalArgumentException (class in different package):
478+
// fall through to traditional ClassLoader.defineClass below
479+
t = ex;
480+
}
470481
}
471482
catch (Throwable ex) {
472483
throw new CodeGenerationException(ex);

0 commit comments

Comments
 (0)