Fix JDK 25 LinkageError in JavaUnrestrictedClassLoader#6736
Merged
Conversation
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: Claude Haiku 4.5 <noreply@anthropic.com>
Member
Author
|
Verified downstream in rewrite-maven-plugin; as reported we still need to add |
1 task
Member
Author
|
Pinging @shanman190 and @knutwannheden for async review, but I don't see any immediate concerns here. |
shanman190
approved these changes
Feb 13, 2026
Contributor
shanman190
left a comment
There was a problem hiding this comment.
I think this looks fine to me.
I wonder if we couldn't check the parent classloader has the entry loaded first prior to loading an entry ourselves. It would avoid the case like this one earlier if we did.
mcebanupgrade
added a commit
to mcebanupgrade/rewrite
that referenced
this pull request
Feb 26, 2026
…assLoader When running via Maven plugin on JDK 25, the ClassRealm classloader establishes loader constraints that prevent defineClass for certain jdk.compiler classes. The existing LinkageError fallback (from openrewrite#6736) delegates to the parent, but this creates a module split: some classes end up in the unnamed module while others land in jdk.compiler. Since jdk.compiler does not export its internal packages to unnamed modules, cross-references between split classes fail with IllegalAccessError. Fix by dynamically adding a module export from the named module to the classloader's unnamed module when falling back to parent delegation. Uses sun.misc.Unsafe to obtain a trusted MethodHandles.Lookup that can invoke Module.implAddExports, bypassing the module system's caller check. All Module API access is done via reflection for Java 8 source compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
sambsnyd
pushed a commit
that referenced
this pull request
Feb 28, 2026
…assLoader (#6836) * Fix JDK 25 IllegalAccessError from module split in JavaUnrestrictedClassLoader When running via Maven plugin on JDK 25, the ClassRealm classloader establishes loader constraints that prevent defineClass for certain jdk.compiler classes. The existing LinkageError fallback (from #6736) delegates to the parent, but this creates a module split: some classes end up in the unnamed module while others land in jdk.compiler. Since jdk.compiler does not export its internal packages to unnamed modules, cross-references between split classes fail with IllegalAccessError. Fix by dynamically adding a module export from the named module to the classloader's unnamed module when falling back to parent delegation. Uses sun.misc.Unsafe to obtain a trusted MethodHandles.Lookup that can invoke Module.implAddExports, bypassing the module system's caller check. All Module API access is done via reflection for Java 8 source compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Run the rewrite-java tests on Java 25 to test fix * Revert "Run the rewrite-java tests on Java 25 to test fix" This reverts commit 8393f8d. --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Tim te Beek <tim@moderne.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a
LinkageErrorthat occurs on JDK 25 when parsing projects with Lombok annotations on comment-free main sources followed by test sources containing comments. JDK 25 changedDocCommentTableto reference public API types across module boundaries, causing the app classloader to eagerly load internal compiler classes. This change wraps thedefineClass()call in a try-catch forLinkageErrorand falls back to parent delegation when the class was already loaded.Test Plan
./gradlew :rewrite-java:testpasses🤖 Generated with Claude Code