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

Unrecognized option: --add-exports #368

Open
GuillaumeDesforges opened this issue Nov 2, 2021 · 3 comments
Open

Unrecognized option: --add-exports #368

GuillaumeDesforges opened this issue Nov 2, 2021 · 3 comments

Comments

@GuillaumeDesforges
Copy link

Describe the bug

When Starting VSCode, I get

Java home: /nix/store/rjgb7sb2wrhl98gqda31h1iaa7v6nm9y-openjdk-11.0.12+7/lib/openjdk
Metals version: 0.10.8
Unrecognized option: --add-exports java.base/sun.nio.ch=ALL-UNNAMED
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Downloading Metals failed with the following:
Process exited with code 1

To Reproduce

  • Create a simple Scala project
  • Write to .jvmopts
    --add-exports java.base/sun.nio.ch=ALL-UNNAMED
    

Expected behavior

Language server should not crash. Indeed, sbt works fine from console for instance.

Installation:

  • Operating system: Linux
  • Editor: Visual Studio Code
  • Metals version: v0.10.8

Additional context

I am providing OpenJDK and sbt from Nix.
I've tried providing metals from Nix as well, but it did not fix my issue.

@tgodzik
Copy link
Contributor

tgodzik commented Nov 2, 2021

Thanks for reporting!

Metals uses .jvmopts for starting the server by default and it seems JDK doesn't recognize the --add-exports option. If you remove it the server should start. You can also specify a separate javaHome to a JDK that recognizes the option.

@GuillaumeDesforges
Copy link
Author

Thanks for your reply. After some investigation, I actually think that the extension does not support options in the .jvmopts written with a space.

With

--add-exports java.base/sun.nio.ch=ALL-UNNAMED

Looking at https://github.com/scalameta/metals-languageclient/blob/main/src/fetchMetals.ts#L26 I expect that java is called with the jvm opts, but using console.log I could see it parsed it "wrong",

console.log("javaOptions=" + JSON.stringify(javaOptions))

gave

javaOptions=["--add-exports java.base/sun.nio.ch=ALL-UNNAMED"]

however, child process spawn, unlike shell calls, wants args separated by a space to be given one by one, so it would need to be equal to

["--add-exports", "java.base/sun.nio.ch=ALL-UNNAMED"]

in the end, I solved the issue by writing in .jvmopts

--add-exports=java.base/sun.nio.ch=ALL-UNNAMED

@tgodzik tgodzik transferred this issue from scalameta/metals Nov 8, 2021
@tgodzik
Copy link
Contributor

tgodzik commented Nov 8, 2021

We should fix the issue somewhere around here:
https://github.com/scalameta/metals-languageclient/blob/main/src/getJavaOptions.ts#L32

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

2 participants