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

:javap crashes REPL with java.lang.NoClassDefFoundError (JDK 11) #11154

Closed
bmccutchon opened this issue Sep 15, 2018 · 15 comments
Closed

:javap crashes REPL with java.lang.NoClassDefFoundError (JDK 11) #11154

bmccutchon opened this issue Sep 15, 2018 · 15 comments
Assignees
Milestone

Comments

@bmccutchon
Copy link

This is completely reproducible for me and happens regardless of what Foo I pass to :javap Foo (even if it doesn't exist).

$ scala
Welcome to Scala 2.12.6 (Java HotSpot(TM) 64-Bit Server VM, Java 10.0.2).
Type in expressions for evaluation. Or try :help.

scala> :javap Nil
java.lang.NoClassDefFoundError: javax/tools/JavaFileManager
	at scala.tools.nsc.interpreter.JavapClass$JavapTool.$anonfun$TaskCtor$1(JavapClass.scala:210)
	at scala.tools.nsc.interpreter.JavapClass$JavapTool$Failer.orFailed(JavapClass.scala:137)
	at scala.tools.nsc.interpreter.JavapClass$JavapTool.<init>(JavapClass.scala:214)
	at scala.tools.nsc.interpreter.JavapClass$JavapTool$.apply(JavapClass.scala:338)
	at scala.tools.nsc.interpreter.JavapClass.tool$lzycompute(JavapClass.scala:37)
	at scala.tools.nsc.interpreter.JavapClass.tool(JavapClass.scala:37)
	at scala.tools.nsc.interpreter.JavapClass.apply(JavapClass.scala:49)
	at scala.tools.nsc.interpreter.ILoop.javapCommand(ILoop.scala:372)
	at scala.tools.nsc.interpreter.ILoop.$anonfun$standardCommands$7(ILoop.scala:187)
	at scala.tools.nsc.interpreter.LoopCommands$LineCmd.apply(LoopCommands.scala:154)
	at scala.tools.nsc.interpreter.LoopCommands.colonCommand(LoopCommands.scala:114)
	at scala.tools.nsc.interpreter.LoopCommands.colonCommand$(LoopCommands.scala:112)
	at scala.tools.nsc.interpreter.ILoop.colonCommand(ILoop.scala:43)
	at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:752)
	at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:456)
	at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:477)
	at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:1069)
	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:82)
	at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:85)
	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)


Unrecoverable error.

Failed to initialize compiler: NoClassDefFoundError.
This is most often remedied by a full clean and recompile.
Otherwise, your classpath may continue bytecode compiled by
different and incompatible versions of scala.

java.lang.NoClassDefFoundError: javax/tools/JavaFileManager
	at scala.tools.nsc.interpreter.JavapClass$JavapTool.$anonfun$TaskCtor$1(JavapClass.scala:210)
	at scala.tools.nsc.interpreter.JavapClass$JavapTool$Failer.orFailed(JavapClass.scala:137)
	at scala.tools.nsc.interpreter.JavapClass$JavapTool.<init>(JavapClass.scala:214)
	at scala.tools.nsc.interpreter.JavapClass$JavapTool$.apply(JavapClass.scala:338)
	at scala.tools.nsc.interpreter.JavapClass.tool$lzycompute(JavapClass.scala:37)
	at scala.tools.nsc.interpreter.JavapClass.tool(JavapClass.scala:37)
	at scala.tools.nsc.interpreter.JavapClass.apply(JavapClass.scala:49)
	at scala.tools.nsc.interpreter.ILoop.javapCommand(ILoop.scala:372)
	at scala.tools.nsc.interpreter.ILoop.$anonfun$standardCommands$7(ILoop.scala:187)
	at scala.tools.nsc.interpreter.LoopCommands$LineCmd.apply(LoopCommands.scala:154)
	at scala.tools.nsc.interpreter.LoopCommands.colonCommand(LoopCommands.scala:114)
	at scala.tools.nsc.interpreter.LoopCommands.colonCommand$(LoopCommands.scala:112)
	at scala.tools.nsc.interpreter.ILoop.colonCommand(ILoop.scala:43)
	at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:752)
	at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:456)
	at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:477)
	at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:1069)
	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:82)
	at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:85)
	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
@joroKr21
Copy link
Member

This happened to me too and somehow java -version and JAVA_HOME were pointing to different Java versions. I didn't have time to fix it but maybe this helps you.

@bmccutchon
Copy link
Author

Nope, that's not it. I didn't have JAVA_HOME set at all. I set it to the correct location and nothing changed.

@xuwei-k
Copy link

xuwei-k commented Sep 15, 2018

workaround: scala -nobootcp

@som-snytt
Copy link

Wow, xuwei-k is all over the place.

I also took a look. This is the REPL class not seeing the javax.tools class on the platform class loader.

The tool is loaded reflectively using the REPL class loader. I'll look for the way to eliminate the warning.

$ PATH=~/zulu10.2+3-jdk10.0.1-macosx_x64/bin:$PATH scala -J--add-modules -Jjava.compiler -nobootcp
Welcome to Scala 2.12.6 (OpenJDK 64-Bit Server VM, Java 10.0.1).
Type in expressions for evaluation. Or try :help.

scala> class C
defined class C

scala> :javap -pv C
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by scala.tools.nsc.interpreter.JavapClass$JavapTool (file:/Users/andrew/scala-2.12.6/lib/scala-compiler.jar) to method com.sun.tools.javap.JavapFileManager.create(javax.tools.DiagnosticListener,java.io.PrintWriter)
WARNING: Please consider reporting this to the maintainers of scala.tools.nsc.interpreter.JavapClass$JavapTool
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
  Size 446 bytes
  MD5 checksum 1a4e5f31d530a6c3f67162a7706e0e9d
  Compiled from "<console>"
public class $line3.$read$$iw$$iw$C

@SethTisue SethTisue added this to the 2.12.7 milestone Sep 16, 2018
@SethTisue
Copy link
Member

@retronym this looks like your dept, should we try to sneak a fix into 2.12.7, or let it go?

@retronym
Copy link
Member

retronym commented Sep 17, 2018

We could certainly do with a better error message when the scala is started without -nobootcp and java.lang.NoClassDefFoundError: javax/tools/JavaFileManager is raised.

The illegal reflective access warning would require another command line option:

$ printf ':javap -public scala.Serializable\n' | scala -nobootcp -J--add-opens -Jjdk.jdeps/com.sun.tools.javap=ALL-UNNAMED
Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 10.0.1).
Type in expressions for evaluation. Or try :help.

scala> :javap -public scala.Serializable
Compiled from "Serializable.scala"
public interface scala.Serializable extends java.io.Serializable {
}

scala> :quit

Not sure how to automate the addition of this in a low-risk manner.

It might be possible to reflectively load a new ModuleLayer with the add-opens added programatically, although at the time of this message support for this sort of thing seemed limited.

Another strategy would be to just fork and call javap.

I don't think we should hold up 2.12.7 for these given that there are workarounds and that the path forward is still somewhat murky.

@SethTisue SethTisue modified the milestones: 2.12.7, 2.13.0-RC1 Sep 17, 2018
@adriaanm adriaanm modified the milestones: 2.13.0-RC1, 2.13.1 Nov 13, 2018
@SethTisue SethTisue changed the title :javap crashes REPL with java.lang.NoClassDefFoundError (Scala 2.12.6, Java 10.0.2) :javap crashes REPL with java.lang.NoClassDefFoundError Feb 25, 2019
@SethTisue SethTisue modified the milestones: 2.13.1, 2.12.9 Feb 25, 2019
@SethTisue
Copy link
Member

still happens in Scala 2.12.8 on JDK 11

@SethTisue SethTisue changed the title :javap crashes REPL with java.lang.NoClassDefFoundError :javap crashes REPL with java.lang.NoClassDefFoundError (JDK 11) Feb 25, 2019
@er1c
Copy link

er1c commented Jun 2, 2019

I'm getting this error now with bloop tests if running Java 11, it compiles fine but tests fail. Is there some magic sbt setting for ensuring nobootcp is used for test/run/etc? Or is this a zinc issue to add the same nobootcp function? There is an interesting example here: https://github.com/eligosource/eventsourced/blob/master/project/Build.scala#L77 but it's for sbt 0.13 and looks like it would need someone with more sbt Fu than I to adapt to sbt 1.x

@som-snytt
Copy link

I refactored to use java.util.spi.ToolProvider (since Java 9) and current reflection on Java 8. The REPL is just filtering output from the tool either way. I'll PR after polish.

@lrytz lrytz modified the milestones: 2.12.9, 2.12.10 Jul 17, 2019
@SethTisue
Copy link
Member

@som-snytt interested in returning to this one?

@som-snytt
Copy link

Yes, I have a branch for this. Is summer over already? When is Labor Day? School hasn't started yet.

@SethTisue
Copy link
Member

San Francisco schools are session.

I'm moving this the to 2.12.11 milestone, but a timely fix could still make 2.12.10

@SethTisue SethTisue modified the milestones: 2.12.10, 2.12.11 Sep 3, 2019
@som-snytt som-snytt modified the milestones: 2.12.11, 2.12.10 Sep 5, 2019
@som-snytt
Copy link

som-snytt commented Sep 5, 2019

I reverted to 2.12.10 because it says it has no due date.

Edit: on the PR side, it says due Sept 6. If today is Wednesday, it must be California.

@som-snytt
Copy link

I just read the forum thread about infighting within the community; I was going to add something about the folks who push a PR to the next milestone and then the other faction that immediately push it back again. Sorry @SethTisue I just saw that you were happy at zero PRs. Probably retronym is the only user of :javap on 2.12 on JDK11 at this point.

@som-snytt som-snytt modified the milestones: 2.12.10, 2.12.11 Sep 6, 2019
@som-snytt
Copy link

som-snytt commented Dec 13, 2019

On 2.13 as scala/scala#8486 and on 2.12 as scala/scala#8400

Not only can we not have nice things, but we have to fix them twice when they break.

The merged version does not do the backflip with a twist to accommodate the classloader. Instead:

scala> :javap C
On JDK 9 or higher, use -nobootcp to enable :javap, or set -Yrepl-outdir to a file system path on the tool class path with -toolcp.

I try to start with -nobootcp always, but it's painful when I forget. That issue by itself could be a blocker.

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

No branches or pull requests

9 participants