Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Metals fails to start when -XX:+PrintCommandLineFlags is defined #203

Open
sideeffffect opened this issue Nov 11, 2020 · 4 comments
Open

Comments

@sideeffffect
Copy link

Whenever a JDK_JAVA_OPTIONS or JAVA_TOOL_OPTIONS environment variable is defined, Metals fails to start. Even if the content is something as innocent as -XX:+PrintCommandLineFlags. The log looks like this.

Java home: /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64
Metals version: 0.9.5
[Error - 5:01:04 PM] Connection to server is erroring. Shutting down server.
[Error - 5:01:04 PM] Connection to server is erroring. Shutting down server.
[Error - 5:01:04 PM] Connection to server is erroring. Shutting down server.
[Error - 5:01:04 PM] Connection to server is erroring. Shutting down server.
NOTE: Picked up JDK_JAVA_OPTIONS: -XX:+PrintCommandLineFlags
Error: -classpath requires class path specification

(Exception is, if the variable is defined as an empty string or a white space, like " ", then Metals works normally as well.)

Metals should work well, even in the presence of these (officially supported 1, 2) environment variables.

On Ubuntu 20.04.

@tgodzik
Copy link
Contributor

tgodzik commented Nov 11, 2020

Thanks for reporting! We might be putting these options in a wrong place and breaking up classpath. Should be easy to fix, most likely in the VS Code extension.

@tgodzik
Copy link
Contributor

tgodzik commented Nov 12, 2020

It seems that the problem here is -XX:+PrintCommandLineFlags - JVM will print the flags, which messes with both Coursier output and Metals server output, which clients are unable to read in that case. We can fix the issue with coursier easily, but we it might be more complicated to do so with the environment. We would need to filter the flag here:

https://github.com/scalameta/metals-languageclient/blob/master/src/getServerOptions.ts#L33

and maybe in some other places. My recommendation for now is not to use -XX:+PrintCommandLineFlags for Metals. Otherwise, it should be fixable in scalameta/language-client

@tgodzik tgodzik transferred this issue from scalameta/metals Nov 12, 2020
@tgodzik tgodzik changed the title Metals fails to start when JDK_JAVA_OPTIONS or JAVA_TOOL_OPTIONS is defined Metals fails to start when -XX:+PrintCommandLineFlags is defined Nov 12, 2020
@sideeffffect
Copy link
Author

Oh, I haven't even tried it without -XX:+PrintCommandLineFlags, since I considered it the least problematic options 😂
Thanks for the explanation!

@fanf
Copy link

fanf commented Dec 2, 2020

I have a problem due to that and it was very hard to understand - thanks for @tgodzik for helping.
So, I tried to use metals but it was failing with just a notification "server failed to start 5 times in 3 minutes, not restarting it".
After some time I found the logs, which were only containing:

Java home: /home/fanf/java/jdk
Metals version: 0.9.7
Error: Could not find or load main class INIT:
Caused by: java.lang.ClassNotFoundException: INIT:
[Info  - 13:57:21] Connection to server got closed. Server will restart.
Error: Could not find or load main class INIT:
Caused by: java.lang.ClassNotFoundException: INIT:
[Info  - 13:57:22] Connection to server got closed. Server will restart.
Error: Could not find or load main class INIT:
Caused by: java.lang.ClassNotFoundException: INIT:
[Info  - 13:57:22] Connection to server got closed. Server will restart.
Error: Could not find or load main class INIT:
Caused by: java.lang.ClassNotFoundException: INIT:
[Info  - 13:57:22] Connection to server got closed. Server will restart.
Error: Could not find or load main class INIT:
Caused by: java.lang.ClassNotFoundException: INIT:
[Error - 13:57:22] Connection to server got closed. Server will not be restarted.

So the problem was that I use a proxy script to actually chose some properties of the jvm to start (parse the command line for some specific modifiers), and that scripts print a line to tell what it did ("using jdk XXX with param YYY").
That was that line which was causing the problem. As soon as I changed the jdk home to one without the proxy shell script, it worked.
I would love to at least have a message telling what's the problem, so that I would have found it quickly by myself.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants