Skip to content
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

Avoid usage of jdk.jconsole module in Java 9+ #113

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nyg
Copy link
Contributor

@nyg nyg commented Feb 4, 2024

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 what LocalVirtualMachine 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 the methodMap using not the from instance (which in Jdk9 case is an instance of VirtualMachineImpl which is not part of the public API) but using the "original" interface, i.e. VirtualMachine. When this distinction is not needed, I just use from.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 and open) jmxterm with both JDK8 and JDK21, but always leaving the maven.compiler.source and target to 1.8.

@nyg nyg mentioned this pull request Apr 3, 2024
LeMyst added a commit to LeMyst/jmxterm that referenced this pull request Jun 19, 2024
LeMyst added a commit to LeMyst/jmxterm that referenced this pull request Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WARNING: An illegal reflective access operation has occurred Does not build or run with java9
2 participants