fix: improve vmoption command compatibility with JDK 21#3162
Open
daguimu wants to merge 2 commits intoalibaba:masterfrom
Open
fix: improve vmoption command compatibility with JDK 21#3162daguimu wants to merge 2 commits intoalibaba:masterfrom
daguimu wants to merge 2 commits intoalibaba:masterfrom
Conversation
f67a305 to
bdfca5a
Compare
On JDK 21, vmoption command fails with 'Error during setting vm option: sun.management.Flag' due to JDK module system restrictions on internal management APIs introduced in JDK 9+. Changes: - Extract getHotSpotDiagnosticMXBean() helper that tries the direct ManagementFactory.getPlatformMXBean() path first, then falls back to JMX.newMXBeanProxy() via MBeanServer, which has better module compatibility on JDK 9+ - Improve error message to include actionable hint when sun.management access fails, suggesting --add-opens java.management/sun.management=ALL-UNNAMED - Wrap complete() method in try/catch to handle errors gracefully Fixes alibaba#3081
bdfca5a to
63b2fcd
Compare
…ommand Log the reason when ManagementFactory.getPlatformMXBean() fails before falling back to MBeanServer proxy, to aid debugging on JDK 9+ environments. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
|
实际测试 jdk 21/25 都能正常执行 具体执行什么命令出错? |
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.
Problem
On JDK 21, the
vmoptioncommand fails with:This is caused by JDK module system restrictions in JDK 9+ where internal
sun.managementAPIs are no longer freely accessible to unnamed modules. Users reported that adding--add-opens java.management/sun.management=ALL-UNNAMEDdoesn't always resolve it.Fix
JMX proxy fallback: Extract
getHotSpotDiagnosticMXBean()helper that first triesManagementFactory.getPlatformMXBean(), then falls back toJMX.newMXBeanProxy()viaMBeanServer. The proxy approach uses standard JMX serialization which avoids the internalsun.managementclass loading issue.Better error message: When
sun.managementaccess fails, the error now includes an actionable hint suggesting--add-opens java.management/sun.management=ALL-UNNAMED.Robust
complete(): Wrap tab-completion in try/catch to prevent errors when diagnostic options are inaccessible.Fixes #3081