-
Notifications
You must be signed in to change notification settings - Fork 122
jdk21 #3829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
theshadowco
wants to merge
6
commits into
develop
Choose a base branch
from
feature/jdk21
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
jdk21 #3829
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
jmockit 1.50 Java 21 compatibility issues JEP 403💡 Result:
JMockit 1.50 tends to run into Java 17+ / Java 21 problems for the same underlying reason as many legacy instrumentation/mocking tools: JEP 403 (delivered in Java 17) tightened access to JDK internals so you can’t rely on the old “relaxed” illegal reflective access behavior anymore; you must explicitly open the needed JDK packages (or the tool must be updated to stop depending on them). [1]
What it looks like on Java 21
Typical failures show up as
java.lang.reflect.InaccessibleObjectException/ “modulejava.basedoes notopens …”, commonly involving packages likejava.lang/java.lang.reflect. This is the class of failure people are explicitly fixing for JDK 21+ by propagating--add-opensinto the test JVM. [3]Why JMockit specifically is risky here
Practical workarounds (tests)
Because JEP 403 removed the “single switch” approach (
--illegal-access), the remaining escape hatch is to open specific packages with--add-opens. [1][2]Common starting point (adjust based on the exact package named in your exception):
(You may need additional
--add-openslines depending on what JMockit and/or your test stack reflectively touches; the exception message tells you the exactmodule/packageto open.) [2][3]Bottom line
If you must stay on JMockit 1.50 with Java 21, expect to maintain a growing list of
--add-opensfor your test JVM due to JEP 403’s strong encapsulation. [1][2][3] For longer-term stability on Java 21+, most teams end up migrating away from JMockit rather than fighting JPMS/agent edge-cases. [4][5]Sources:
[1] OpenJDK JEP 403 (Strongly Encapsulate JDK Internals)
[2] StackOverflow explanation of
InaccessibleObjectException+--add-opens+ note that--illegal-accessstops working from JDK 17 (JEP 403)[3] Apache Maven PR discussion: JDK 21+ test failures fixed by propagating
--add-opens(mentionsjava.lang/java.lang.reflect)[4] JMockit issue: incompatibilities on Java 17 (example of ongoing breakage/fragility)
[5] javadoc.io listing showing latest
org.jmockit:jmockitversion is 1.50🌐 Web query:
jmockit Java agent bytecode instrumentation Java 21 encapsulation💡 Result:
JMockit’s mocking works by bytecode instrumentation via a
-javaagent(it’s not a pure proxy-based mocking library). With Java 21’s strong encapsulation, this tends to break in two main ways:JMockit is effectively unmaintained for modern JDKs
The last “current release” shown in JMockit’s own history is v1.49 (Dec 29, 2019), i.e., pre–Java 21 and even pre–Java 17 LTS, so incompatibilities with newer classfiles/JDK behaviors are common and often not fixed upstream. [1]
Encapsulation / deep-reflection failures (
InaccessibleObjectException)On Java 9+, you can get
java.lang.reflect.InaccessibleObjectExceptionwhen code tries to “break in” to non-opened JDK internals (access checks can’t be suppressed). [3]Typical mitigations are JVM flags such as
--add-opens ...=ALL-UNNAMED(or targeted opens to specific modules), but this weakens encapsulation and is increasingly discouraged.Agent-loading rules tightened (especially dynamic attach)
If your setup loads the agent dynamically (Attach API) rather than at JVM startup, JDK 21 emits warnings and is explicitly moving toward disallowing dynamic agent loading by default. The official guidance is to prefer startup-time
-javaagent, and if you truly must attach dynamically you may need-XX:+EnableDynamicAgentLoading(and related attach settings). [2]Practical takeaways for Java 21
-javaagent:/path/to/jmockit.jar(not dynamic attach). [2]InaccessibleObjectException, you’ll need targeted--add-opensfor the specific JDK packages you’re trying to instrument/reflect into (but consider that this is fighting the platform direction). [3]Sources
[1] JMockit “Development history” (current release v1.49, Dec 29, 2019) https://jmockit.github.io/changes.html
[2] OpenJDK JEP 451 (JDK 21): Prepare to Disallow the Dynamic Loading of Agents https://openjdk.org/jeps/451
[3] Oracle JDK docs:
InaccessibleObjectException(thrown when access checks can’t be suppressed) https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/reflect/InaccessibleObjectException.html🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 141
🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 2185
🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 2158
🏁 Script executed:
rg -n "java\s*\{|sourceCompatibility|targetCompatibility|jvmArgs|add-opens" build.gradle.ktsRepository: 1c-syntax/bsl-language-server
Length of output: 249
🏁 Script executed:
Repository: 1c-syntax/bsl-language-server
Length of output: 1308
Add
--add-opensflags to test task for Java 21 compatibility with jmockit 1.50.The codebase targets Java 21 (lines 164–165) while using jmockit 1.50 with
-javaagent(lines 157, 232). JMockit relies on bytecode instrumentation to access JDK internals, but Java 21's strong encapsulation (JEP 403) blocks this by default, causingInaccessibleObjectExceptionfailures. To run tests on Java 21, add the following to the test task configuration:Adjust the
--add-openspackages based on the specificInaccessibleObjectExceptionerrors encountered. For longer-term stability, consider migrating to a modern mocking library or the maintained jmockit fork atcom.github.hazendaz.jmockit, as the original jmockit project (v1.50) is not actively maintained for modern JDKs.🤖 Prompt for AI Agents