Skip to content

Commit 07d1ffe

Browse files
timtebeekTim te Beekclaude
authored
Fix JDK 25 LinkageError in JavaUnrestrictedClassLoader (#6736)
Wrap defineClass() in try-catch for LinkageError to handle JDK 25+ class loader constraint violations. When app classloader eagerly loads com.sun.* classes through cross-module type boundaries, fall back to parent delegation instead of crashing. Co-authored-by: Tim te Beek <tim@mac.home> Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent f096b9a commit 07d1ffe

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

rewrite-java/src/main/java/org/openrewrite/java/JavaUnrestrictedClassLoader.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,18 @@ public Class<?> loadClass(String name) throws ClassNotFoundException {
105105
Path classFile = path.resolve(internalName);
106106
if (Files.exists(classFile)) {
107107
byte[] bytes = Files.readAllBytes(classFile);
108-
return defineClass(name, bytes, 0, bytes.length);
108+
try {
109+
return defineClass(name, bytes, 0, bytes.length);
110+
} catch (LinkageError e) {
111+
// On JDK 25+, cross-module type references in DocCommentTable can cause the
112+
// app classloader to load jdk.compiler classes before this classloader does.
113+
// Fall back to parent delegation for the already-loaded class.
114+
try {
115+
return super.loadClass(name);
116+
} catch (ClassNotFoundException cnfe) {
117+
throw e;
118+
}
119+
}
109120
}
110121
}
111122
} catch (IOException e) {

0 commit comments

Comments
 (0)