-
Notifications
You must be signed in to change notification settings - Fork 155
Avoid usage of jdk.jconsole module in Java 9+ #113
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
Conversation
Copied from PR jiaqi#113 Co-Authored-By: nyg <[email protected]>
Copied from PR jiaqi#113 Co-Authored-By: nyg <[email protected]>
Copied from PR jiaqi#113 Co-Authored-By: nyg <[email protected]>
Object vm = staticVirtualMachine.attach(vmd.id()); | ||
try { | ||
Class<?> originalVirtualMachine = Class.forName(VirtualMachine.ORIGINAL_CLASS_NAME); | ||
VirtualMachine vmProxy = WeakCastUtils.cast(originalVirtualMachine, VirtualMachine.class); |
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.
Did you forget to pass vm
to cast
?
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.
Indeed I did! I created a new PR to fix that: #129.
@jiaqi @nyg, have you ever seen this exception when running with JDK 21:
|
Bumps [org.jline:jline](https://github.com/jline/jline3) from 3.29.0 to 3.30.0. - [Release notes](https://github.com/jline/jline3/releases) - [Commits](jline/jline3@jline-3.29.0...jline-3.30.0) --- updated-dependencies: - dependency-name: org.jline:jline dependency-version: 3.30.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Hello,
Since Java 9, there is a warning (illegal reflective access operation) when using the jdk.jconsole module which contains classes like
LocalVirtualMachine
that are used to list local VMs and attach to them. On later Java version (17?), accessing these classes makes jmxterm crash.I implemented a
Jdk9JavaProcessManager
which relies only on the public Attach API (which is actually whatLocalVirtualMachine
appears to use under the hood, see: https://github.com/openjdk/jdk/blob/jdk8-b120/jdk/src/share/classes/sun/tools/jconsole/LocalVirtualMachine.java#L123). So my code is voluntarily based on what goes on in LocalVirtualMachine (especially when listing VMs).I had to adapt
WeakCastUtils
to build themethodMap
using not thefrom
instance (which in Jdk9 case is an instance ofVirtualMachineImpl
which is not part of the public API) but using the "original" interface, i.e.VirtualMachine
. When this distinction is not needed, I just usefrom.getClass()
.The source and target version remain Java 8.
Also, as the mininum Java version is 8, I'm not sure it's useful to keep
Jdk5JavaProcessManager
.If
WeakCastUtils
doesn't serve any other purpose than supporting multiple Java version, probably it could be replaced with Java 9 multi-release JARs: https://nipafx.dev/multi-release-jars-multiple-java-versions/.Note 1: this PR includes my other PR (#112).
Note 2: as I answered in #48, making jmxterm work with Java 17+ can be done by allowing access to the jdk.jconsole module (with
--add-exports jdk.jconsole/...
) but this is not supported by Java 8 and cannot be used with the Java 9--release
option.Best,
nyg
Fixes #48
Fixes #87
EDIT: I tested in the following way: compiled and ran (running
jvms
andopen
) jmxterm with both JDK8 and JDK21, but always leaving the maven.compiler.source and target to 1.8.