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

Metals does not work with Java 9 #1037

Closed
olafurpg opened this issue Nov 2, 2019 · 14 comments
Closed

Metals does not work with Java 9 #1037

olafurpg opened this issue Nov 2, 2019 · 14 comments

Comments

@olafurpg
Copy link
Member

olafurpg commented Nov 2, 2019

Describe the bug

Using Java 9 with Metals results in crashes like

Exception in thread "pool-43-thread-7" java.lang.NoClassDefFoundError: javax/tools/DiagnosticListener

`Expected behavior

Metals should report a helpful message saying that Java 9 is not supported. The user can fix the problem by using either Java 8 or Java 11.

Installation:

  • Operating system: macOS/Windows/Linux
  • Editor: Visual Studio Code/Atom/Vim/Sublime/Emacs
  • Metals version: v0.7.6
  • Java: openjdk 9.0.4

Additional context

Reported on Discord https://discordapp.com/channels/632642981228314653/632841682211045396/639918405176131594
Search terms

@Kazark
Copy link

Kazark commented Jan 16, 2020

I get the same problem on Java 8:

$ java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.232-b09, mixed mode)

The error I'm getting is:

INFO  running installed 'bloop bsp --protocol local --socket /var/folders/8l/lmk_c8ps2bggqkxvmphwxhtc0000gn/T/bsp2826756088973153477/-148q2qohp726k.socket'
INFO  The server is listening for incoming connections at local:///var/folders/8l/lmk_c8ps2bggqkxvmphwxhtc0000gn/T/bsp2826756088973153477/-148q2qohp726k.socket...
INFO  tracing is disabled for protocol BSP, to enable tracing of incoming and outgoing JSON messages create an empty file at /Users/<redacted>/Library/Caches/org.scalameta.metals/bsp.trace.json
INFO  Accepted incoming BSP client connection at local:///var/folders/8l/lmk_c8ps2bggqkxvmphwxhtc0000gn/T/bsp2826756088973153477/-148q2qohp726k.socket
INFO  request received: build/initialize
INFO  time: connected to build server in 0.21s
INFO  BSP initialization handshake complete.
INFO  time: indexed workspace in 5.07s
ERROR �[0m�[32m[D]�[0m Computing sources and classpath hashes for <redacted>
ERROR �[0m�[32m[D]�[0m Scheduling compilation for <redacted>...
ERROR �[0m�[32m[D]�[0m Using successful result for <redacted> associated with /Users/<redacted>/src/<redacted>/.bloop/<redacted>/scala-2.11/bloop-internal-classes/classes-Metals-plPpQmc9R6S6qNnSt3WOng==-vjUJljA8S-STslAweP-6DA==
ERROR �[0m�[32m[D]�[0m Increasing counter for /Users/<redacted>/src/<redacted>/.bloop/<redacted>/scala-2.11/bloop-internal-classes/classes-Metals-plPpQmc9R6S6qNnSt3WOng==-vjUJljA8S-STslAweP-6DA== to 4
ERROR �[0m�[32m[D]�[0m Disabled compiler plugin classloading, unsupported in 2.11.
ERROR �[0m�[32m[D]�[0m External classes directory /Users/<redacted>/src/<redacted>/.bloop/<redacted>/bloop-bsp-clients-classes/classes-Metals-vTJZl0ylTsyyB_X19IM99Q==
ERROR �[0m�[32m[D]�[0m Read-only classes directory /Users/<redacted>/src/<redacted>/.bloop/<redacted>/scala-2.11/bloop-internal-classes/classes-Metals-plPpQmc9R6S6qNnSt3WOng==-vjUJljA8S-STslAweP-6DA==
ERROR �[0m�[32m[D]�[0m New rw classes directory /Users/<redacted>/src/<redacted>/.bloop/<redacted>/bloop-internal-classes/classes-Metals-vTJZl0ylTsyyB_X19IM99Q==-nFHxT8biRVWdk6Mwf6yylw==
Exception in thread "pool-26-thread-1" java.lang.NoClassDefFoundError: javax/tools/DiagnosticListener
	at scala.tools.util.PathResolverBase$Calculated$.javaBootClasspath(PathResolver.scala:277)
	at scala.tools.util.PathResolverBase$Calculated$.basis(PathResolver.scala:283)
	at scala.tools.util.PathResolverBase$Calculated$.containers$lzycompute(PathResolver.scala:293)
	at scala.tools.util.PathResolverBase$Calculated$.containers(PathResolver.scala:293)
	at scala.tools.util.PathResolverBase.containers(PathResolver.scala:309)
	at scala.tools.util.PathResolver.computeResult(PathResolver.scala:341)
	at scala.tools.util.PathResolver.computeResult(PathResolver.scala:332)
	at scala.tools.util.PathResolverBase.result(PathResolver.scala:314)
	at scala.tools.nsc.backend.JavaPlatform$class.classPath(JavaPlatform.scala:28)
	at scala.tools.nsc.Global$GlobalPlatform.classPath(Global.scala:115)
	at scala.tools.nsc.Global.scala$tools$nsc$Global$$recursiveClassPath(Global.scala:131)
	at scala.tools.nsc.Global$GlobalMirror.rootLoader(Global.scala:64)
	at scala.reflect.internal.Mirrors$Roots$RootClass.<init>(Mirrors.scala:307)
	at scala.reflect.internal.Mirrors$Roots.RootClass$lzycompute(Mirrors.scala:321)
	at scala.reflect.internal.Mirrors$Roots.RootClass(Mirrors.scala:321)
	at scala.reflect.internal.Mirrors$Roots$EmptyPackageClass.<init>(Mirrors.scala:330)
	at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass$lzycompute(Mirrors.scala:336)
	at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass(Mirrors.scala:336)
	at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass(Mirrors.scala:276)
	at scala.reflect.internal.Mirrors$RootsBase.init(Mirrors.scala:250)
	at scala.tools.nsc.Global.rootMirror$lzycompute(Global.scala:73)
	at scala.tools.nsc.Global.rootMirror(Global.scala:71)
	at scala.tools.nsc.Global.rootMirror(Global.scala:39)
	at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass$lzycompute(Definitions.scala:257)
	at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass(Definitions.scala:257)
	at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1390)
	at scala.tools.nsc.Global$Run.<init>(Global.scala:1242)
	at scala.tools.nsc.interactive.Global$TyperRun.<init>(Global.scala:1321)
	at scala.tools.nsc.interactive.Global.newTyperRun(Global.scala:1344)
	at scala.tools.nsc.interactive.Global.<init>(Global.scala:299)
	at scala.meta.internal.pc.MetalsGlobal.<init>(MetalsGlobal.scala:29)
	at scala.meta.internal.pc.ScalaPresentationCompiler.newCompiler(ScalaPresentationCompiler.scala:168)
	at scala.meta.internal.pc.ScalaPresentationCompiler$$anonfun$1.apply(ScalaPresentationCompiler.scala:57)
	at scala.meta.internal.pc.ScalaPresentationCompiler$$anonfun$1.apply(ScalaPresentationCompiler.scala:57)
	at scala.meta.internal.pc.CompilerAccess.loadCompiler(CompilerAccess.scala:36)
	at scala.meta.internal.pc.CompilerAccess.withSharedCompiler(CompilerAccess.scala:120)
	at scala.meta.internal.pc.CompilerAccess$$anonfun$withNonInterruptableCompiler$1.apply(CompilerAccess.scala:110)
	at scala.meta.internal.pc.CompilerAccess$$anonfun$onCompilerJobQueue$1.apply$mcV$sp(CompilerAccess.scala:198)
	at scala.meta.internal.pc.CompilerJobQueue$Job.run(CompilerJobQueue.scala:73)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.ClassNotFoundException: javax.tools.DiagnosticListener
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:436)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 42 more
ERROR �[0m�[32m[D]�[0m Full compilation, no sources in previous analysis.
ERROR �[0m�[32m[D]�[0m All sources are invalidated.
ERROR �[0m�[32m[D]�[0m Initial set of included nodes: 
ERROR �[0m�[32m[D]�[0m Recompiling all sources: number of invalidated sources > 50.0% of all sources
ERROR �[0m�[32m[D]�[0m Returning already retrieved and compiled bridge: /Users/<redacted>/Library/Caches/bloop/components/ch.epfl.scala-compiler-bridge_2.11-1.3.0-M4+32-b1accb96-bin_2.11.12__52.0/ch.epfl.scala-compiler-bridge_2.11-1.3.0-M4+32-b1accb96-bin_2.11.12__52.0.jar.
INFO  compiling <redacted> (22 scala sources)
ERROR �[0m�[32m[D]�[0m Returning already retrieved and compiled bridge: /Users/<redacted>/Library/Caches/bloop/components/ch.epfl.scala-compiler-bridge_2.11-1.3.0-M4+32-b1accb96-bin_2.11.12__52.0/ch.epfl.scala-compiler-bridge_2.11-1.3.0-M4+32-b1accb96-bin_2.11.12__52.0.jar.
ERROR �[0m�[32m[D]�[0m [zinc] Running cached compiler 914f90d for Scala compiler version 2.11.12
ERROR �[0m�[32m[D]�[0m [zinc] The Scala compiler is invoked with:
ERROR 	-deprecation
ERROR 	-feature
ERROR 	-language:postfixOps
ERROR 	-Xlint
ERROR 	-Xlog-free-terms
ERROR 	-Xlog-free-types
ERROR 	-language:implicitConversions
ERROR 	-language:higherKinds
ERROR 	-language:existentials
ERROR 	-language:postfixOps
ERROR 	-Ywarn-dead-code
ERROR 	-Ywarn-numeric-widen
ERROR 	-Ywarn-inaccessible
ERROR 	-unchecked
ERROR 	-nowarn
ERROR 	-Xplugin-require:macroparadise
ERROR 	-P:semanticdb:synthetics:on
ERROR 	-P:semanticdb:failures:warning
ERROR 	-P:semanticdb:sourceroot:/Users/<redacted>/src/<redacted>
ERROR 	-Yrangepos
ERROR 	-Xplugin-require:semanticdb
ERROR 	-Xplugin:/Users/<redacted>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/wartremover/wartremover_2.11/2.2.1/wartremover_2.11-2.2.1.jar
ERROR 	-Xplugin:/Users/<redacted>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalameta/semanticdb-scalac_2.11.12/4.2.3/semanticdb-scalac_2.11.12-4.2.3.jar
ERROR 	-Xplugin:/Users/<redacted>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalamacros/paradise_2.11.12/2.1.1/paradise_2.11.12-2.1.1.jar
ERROR 	-bootclasspath
ERROR 	/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/classes:/Users/<redacted>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.11.12/scala-library-2.11.12.jar
ERROR 	-classpath
ERROR 	<redacted>

This is causing me problems in Emacs lsp-mode.

@Kazark
Copy link

Kazark commented Jan 16, 2020

Hm. Also getting it with Java 11.

@olafurpg
Copy link
Member Author

@Kazark thank you for reporting! What scala version are you using? This error happens when using 2.11 on jdk 11.

@olafurpg
Copy link
Member Author

These stack traces “java.base/java.lang.ClassLoader” only appear in jdk 11

@Kazark
Copy link

Kazark commented Jan 16, 2020

The repo were I am having the problem is on 2.11. I think there was some hangup making it hard to upgrade, but I'm going to push a bit for upgrading. However, AFAIK I did not even have JDK 11 when I was first having this problem. I had JDK 13 and JDK 8, with my JAVA_HOME set to 8.

@billiams
Copy link

I'm on Scala 2.11 and Java 8, hitting the same issue as @Kazark

Exception in thread "pool-6-thread-1" java.lang.NoClassDefFoundError: javax/tools/DiagnosticListener
	at scala.tools.util.PathResolverBase$Calculated$.javaBootClasspath(PathResolver.scala:277)
	at scala.tools.util.PathResolverBase$Calculated$.basis(PathResolver.scala:283)
	at scala.tools.util.PathResolverBase$Calculated$.containers$lzycompute(PathResolver.scala:293)
	at scala.tools.util.PathResolverBase$Calculated$.containers(PathResolver.scala:293)
	at scala.tools.util.PathResolverBase.containers(PathResolver.scala:309)
	at scala.tools.util.PathResolver.computeResult(PathResolver.scala:341)
	at scala.tools.util.PathResolver.computeResult(PathResolver.scala:332)
	at scala.tools.util.PathResolverBase.result(PathResolver.scala:314)
	at scala.tools.nsc.backend.JavaPlatform$class.classPath(JavaPlatform.scala:28)
	at scala.tools.nsc.Global$GlobalPlatform.classPath(Global.scala:115)
	at scala.tools.nsc.Global.scala$tools$nsc$Global$$recursiveClassPath(Global.scala:131)
	at scala.tools.nsc.Global$GlobalMirror.rootLoader(Global.scala:64)
	at scala.reflect.internal.Mirrors$Roots$RootClass.<init>(Mirrors.scala:307)
	at scala.reflect.internal.Mirrors$Roots.RootClass$lzycompute(Mirrors.scala:321)
	at scala.reflect.internal.Mirrors$Roots.RootClass(Mirrors.scala:321)
	at scala.reflect.internal.Mirrors$Roots$EmptyPackageClass.<init>(Mirrors.scala:330)
	at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass$lzycompute(Mirrors.scala:336)
	at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass(Mirrors.scala:336)
	at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass(Mirrors.scala:276)
	at scala.reflect.internal.Mirrors$RootsBase.init(Mirrors.scala:250)
	at scala.tools.nsc.Global.rootMirror$lzycompute(Global.scala:73)
	at scala.tools.nsc.Global.rootMirror(Global.scala:71)
	at scala.tools.nsc.Global.rootMirror(Global.scala:39)
	at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass$lzycompute(Definitions.scala:257)
	at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass(Definitions.scala:257)
	at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1390)
	at scala.tools.nsc.Global$Run.<init>(Global.scala:1242)
	at scala.tools.nsc.interactive.Global$TyperRun.<init>(Global.scala:1321)
	at scala.tools.nsc.interactive.Global.newTyperRun(Global.scala:1344)
	at scala.tools.nsc.interactive.Global.<init>(Global.scala:299)
	at scala.meta.internal.pc.MetalsGlobal.<init>(MetalsGlobal.scala:31)
	at scala.meta.internal.pc.ScalaPresentationCompiler.newCompiler(ScalaPresentationCompiler.scala:190)
	at scala.meta.internal.pc.ScalaPresentationCompiler$$anonfun$1.apply(ScalaPresentationCompiler.scala:61)
	at scala.meta.internal.pc.ScalaPresentationCompiler$$anonfun$1.apply(ScalaPresentationCompiler.scala:61)
	at scala.meta.internal.pc.CompilerAccess.loadCompiler(CompilerAccess.scala:36)
	at scala.meta.internal.pc.CompilerAccess.withSharedCompiler(CompilerAccess.scala:120)
	at scala.meta.internal.pc.CompilerAccess$$anonfun$withNonInterruptableCompiler$1.apply(CompilerAccess.scala:110)
	at scala.meta.internal.pc.CompilerAccess$$anonfun$onCompilerJobQueue$1.apply$mcV$sp(CompilerAccess.scala:198)
	at scala.meta.internal.pc.CompilerJobQueue$Job.run(CompilerJobQueue.scala:101)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.ClassNotFoundException: javax.tools.DiagnosticListener
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:436)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 42 more

@tgodzik
Copy link
Contributor

tgodzik commented Mar 28, 2020

Hey @billiams that error only happens with JDK 11 and scala 2.11. Are you sure there is no other version installed?

What happens if you specify java home by hand in the settings?

If it doesn't help, please create a new issue with all the details.

@kpbochenek
Copy link
Contributor

kpbochenek commented Mar 28, 2020

To clarify this problem, when you see in logs:

java.lang.NoClassDefFoundError: javax/tools/DiagnosticListener
	at scala.tools.util.PathResolverBase$Calculated$.javaBootClasspath(PathResolver.scala:277)

This means that there exists JDK 9+ and your project uses scala 2.11
Any other combination should not cause those problems. It means:

  • if you can update scala version (2.11 --> 2.12 or 2.13) then it should fix your problem
  • if you can revert JDK to 8 it should fix your problem
  • if you have JDK8 and JDK 9+ and you are okay with removing JDK 9+ please do that and that also should fix your problem(why is that below)

Problem with multiple JDKs was also present in bloop(scalacenter/bloop#743) it looks like even if you set JAVA_HOME properly because of how Java is managed by OSX you might actually end up using different version. To not get confused and search for ghosts it would be ideal to test with ONLY JDK8 installed and then it should work but in case still something is wrong issue should be raised.

Now tricky thing why there is a problem with 2.11 and not 2.12 or 2.13 in the first place?
Long story short there was a problem with scala-compiler and JDK9+ which was reported and fixed(scala/bug#11154) when scala 2.12 was latest, because of that 2.13 has this fix too. It was even backported to 2.10(scala/scala#6113) but what about 2.11? No idea.
But it means a problem is actually in scala-compiler_2.11, issue can be raised there or maybe a workaround can be hacked but that is a current state of things.

EDIT:
Okay I clearly missed something as metals always links to scala-2.12, scala-compiler on cp is from 2.12 but I check and check again and stacktrace matches scala-compiler 2.11 🙄

@olafurpg
Copy link
Member Author

This issue indeed seems to only affect Scala 2.11.x on JDK 9+. Scala 2.11 only supports JDK 8. The formatting of the following stack traces indicate you are running on JDK 9+ where there java.base module got added (in JDK 8 it's formatted as at java.net.URLClassLoader.findClass(URLClassLoader.java:436).

Caused by: java.lang.ClassNotFoundException: javax.tools.DiagnosticListener
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:436)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)

I think there will eventually be a 2.11.13 release which improves JDK 9+ support, see scala/scala#8079

@kpbochenek
Copy link
Contributor

Yes it must be from JDK9+, I don't have other than JDK 11 installed(although now I know I should never be 100% sure as it looks like bloop can actually install jdk8 itself if not found so you never know :P )

Metals must be loading separate scala library depending on scala used in a project because metals is started with scala-compiler_2.12 and stacktrace(e.g. scala.tools.util.PathResolverBase.containers(PathResolver.scala:309)) is from scala-compiler_2.11

Might be obvious to you but I have still not found how and where this is all taking place inside metals :)

It would be super awesome if this PR(scala/scala#8079) completely fixed scala 2.11 <-> JDK9+ issue and we could simply recommend users to update to 2.11.13 without changing anything(maybe a deprecation message) or maybe even better, if we know user uses scala 2.11.12 just fetch scala-compiler_2.11.13 (they should be compatible according to semver)

@tgodzik
Copy link
Contributor

tgodzik commented Mar 29, 2020

@kpbochenek IT's all happening in Embedded.scala, where we load the proper mtags module.

Yes it must be from JDK9+, I don't have other than JDK 11 installed(although now I know I should never be 100% sure as it looks like bloop can actually install jdk8 itself if not found so you never know :P )

Bloop will not download any JDK, but will use anything on the PATH.

@kpbochenek
Copy link
Contributor

@tgodzik Thanks! I will look up Embedded.scala 👍

you are also right bloop won't download any JDK, I misinterpreted completely wrong PR about launcher changes :(

@billiams
Copy link

Hey @billiams that error only happens with JDK 11 and scala 2.11. Are you sure there is no other version installed?

What happens if you specify java home by hand in the settings?

If it doesn't help, please create a new issue with all the details.

Hey @tgodzik - thanks for the reply. I am setting java_home manually now in my .spacemacs:

(setq lsp-metals-java-home "/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home")

and the problem seems to have gone away.

@olafurpg
Copy link
Member Author

Closing as fixed.

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

No branches or pull requests

6 participants