-
Notifications
You must be signed in to change notification settings - Fork 225
JansiNativePty and JnaNativePty use illegal reflective access #575
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
Comments
We could use |
Any news on this? |
If you have any pointer / example on how to actually call this method, I'd be happy to give it another try. Or even better a PR where you can actually compile a method calling |
I'm having the same problem:
What do you mean by "If you have any pointer / example on how to actually call this method"? Which method? |
Unfortunately, I can no longer use jline because we're switching to Java 17, which doesn't allow you to override reflection errors like this. In my case, the problem stems from this code in ExecTerminalProvider:
|
|
Have you configured the VM with the necessary
|
That did fix the issue. Is there any better way to solve this? |
I'd be happy to be pointed to a better way. Internally, the JDK use Maybe using some JNI. Acoording to the JNI Programmer's Guide and Specification says this in 10.9 Violating Access Control Rules:
I just found a library that may help with that, but it does not support a lof of platforms. |
Is the purpose of this to hide any text that may be printed to stdout or stderr? If so, you can use ProcessBuilder.Redirect.PIPE instead of ProcessBuilder.Redirect.INHERIT. I also wonder why you are shelling out at all to determine whether this is a system stream? Shelling out is a bit slow. Could each provider just implement its name in code? |
This is a bit more complex. It basically executes
The point is to retrieve the real tty name, such as |
Seems like it might not be worth the illegal reflexive access for a diagnostic string, but obviously that's not for me to decide. Maybe you could gate this on a system property so it would only affect users who are actually running diagnostics? |
The value itself it not used at runtime (only in the |
Got it. This goes back to my original question though which is whether or not it is possible to identify whether it is a system stream without shelling out. Is a system stream a different class from other streams? Could it be? |
Also, it should be possible to shell out with fork/execve using the jna if you want to avoid jni. This should be relatively straightforward because execve has a simple api although I don't love the jna api itself (but jline already uses jna so at least it wouldn't be a new dependency). This would allow you to fully control the descriptors of the forked process. If you search for execve, you'll probably find c code that you can port to jna code. This would probably take the better part of a day to work through so I can understand not being motivated to do it. Alternatively, you could probably find the system function that tty calls under the hood and call that directly from the jna without needing to shell out. |
There are 3 terminal providers: one using jansi, one using jna and one using fork/exec. I do recommend the jansi one, but if people want to avoid using JNI at all, the provider is here. Both jansi and jna use direct calls to the standard library to retrieve the ttyname. The exec provider has to rely on exec'ing |
@eatkins fwiw, your original issue is not about forking |
This comment #575 (comment) suggested that the issue is coming in the getRedirect method which is only used in systemStreamName in ExecTerminalProvider. But I see your point that setAccessible is used in the jansi and jna providers to make a FileDescriptor instance, which is ultimately used as the constructor argument for a File(Input|Output)Stream. There is a way around that by using custom InputStream and OutputStream classes that delegate to the read and write syscalls using JNA instead of File(Input|Output)Stream. I understand why that might be unappealing though. That all being said, I do not see any warnings when I start sbt with java 19 which makes a system terminal without setting JNA or Jansi so I guess this is only a problem if you specify JNA, Jansi or Exec terminal. I'm going to bow out of this discussion because I no longer use any software that relies on JLine, but good luck. |
#825 provides a fix for the original problem mentioned in this issue, the fact that If needed, other methods could be added, such as using This currently does not address the |
… allow access (fixes jline#575)
… allow access (fixes jline#575)
This change gets rid of this annoying warning: WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.jline.terminal.impl.exec.ExecTerminalProvider (file:/Users/apr/git/jpos/jpos/build/install/jpos/lib/jline-3.23.0.jar) to constructor java.lang.ProcessBuilder$RedirectPipeImpl() WARNING: Please consider reporting this to the maintainers of org.jline.terminal.impl.exec.ExecTerminalProvider WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release See jline/jline3#575 for details
When I wire up sbt to use either a jna or jansi based system terminal on osx and start sbt with java 11, I get the following warning at startup:
so I'm just doing what the warning told me to.
The text was updated successfully, but these errors were encountered: