Java 9 jshell OSX bug workaround
Java 9 jshell
You’ve downloaded the current build of Java 9, and perhaps Kulla. You try to run jshell and blammo. Stack dump.
Introduction
So, you’ve installed Java 9 on your Mac. Maybe one of the Early Access builds. I’m playing around with modules, so I’m using the Jigsaw version.
Let’s check.
1 2 3 4 5 6 7 |
$ java -version java version "9-ea" Java(TM) SE Runtime Environment (build 9-ea+96-jigsaw-nightly-h4094-20151216) Java HotSpot(TM) 64-Bit Server VM (build 9-ea+96-jigsaw-nightly-h4094-20151216, mixed mode) $ javac -fullversion javac full version "9-ea+96-jigsaw-nightly-h4094-20151216" |
Let’s run jshell.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
$ $JAVA_HOME/bin/jshell Exception in thread "main" java.lang.InternalError: Failed remote launch: com.sun.jdi.CommandLineLaunch (defaults: home=/Library/Java/JavaVirtualMachines/jdk-9j.jdk/Contents/Home, options=, main=, suspend=true, quote=", vmexec=java) -- {home=home=/Library/Java/JavaVirtualMachines/jdk-9j.jdk/Contents/Home, options=options=-classpath kulla.jar , main=main=jdk.internal.jshell.remote.RemoteAgent 58849, suspend=suspend=true, quote=quote=", vmexec=vmexec=java} at jdk.jshell.JDIConnection.reportLaunchFail(jdk.jshell@9-ea/JDIConnection.java:543) at jdk.jshell.JDIConnection.launchTarget(jdk.jshell@9-ea/JDIConnection.java:509) at jdk.jshell.JDIConnection.open(jdk.jshell@9-ea/JDIConnection.java:324) at jdk.jshell.JDIEnv.init(jdk.jshell@9-ea/JDIEnv.java:47) at jdk.jshell.ExecutionControl.jdiGo(jdk.jshell@9-ea/ExecutionControl.java:259) at jdk.jshell.ExecutionControl.launch(jdk.jshell@9-ea/ExecutionControl.java:67) at jdk.jshell.JShell.executionControl(jdk.jshell@9-ea/JShell.java:613) at jdk.jshell.ClassTracker$ClassInfo.getReferenceTypeOrNull(jdk.jshell@9-ea/ClassTracker.java:81) at jdk.jshell.Unit.lambda$classesToLoad$3(jdk.jshell@9-ea/Unit.java:265) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(java.base@9-ea/ArrayList.java:1387) 8 ##¬ at java.util.stream.ReferencePipeline$Head.forEach(java.base@9-ea/ReferencePipeline.java:591) at jdk.jshell.Unit.classesToLoad(jdk.jshell@9-ea/Unit.java:263) at jdk.jshell.Eval.lambda$compileAndLoad$13(jdk.jshell@9-ea/Eval.java:554) at java.util.stream.ReferencePipeline$7$1.accept(java.base@9-ea/ReferencePipeline.java:269) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(java.base@9-ea/ArrayList.java:1387) at java.util.stream.AbstractPipeline.copyInto(java.base@9-ea/AbstractPipeline.java:482) at java.util.stream.AbstractPipeline.wrapAndCopyInto(java.base@9-ea/AbstractPipeline.java:472) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(java.base@9-ea/ReduceOps.java:913) at java.util.stream.AbstractPipeline.evaluate(java.base@9-ea/AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(java.base@9-ea/ReferencePipeline.java:511) at jdk.jshell.Eval.compileAndLoad(jdk.jshell@9-ea/Eval.java:555) at jdk.jshell.Eval.declare(jdk.jshell@9-ea/Eval.java:461) at jdk.jshell.Eval.processMethod(jdk.jshell@9-ea/Eval.java:385) at jdk.jshell.Eval.eval(jdk.jshell@9-ea/Eval.java:127) at jdk.jshell.JShell.eval(jdk.jshell@9-ea/JShell.java:350) at jdk.internal.jshell.tool.JShellTool.processCompleteSource(jdk.jshell@9-ea/JShellTool.java:1399) at jdk.internal.jshell.tool.JShellTool.processSource(jdk.jshell@9-ea/JShellTool.java:1388) at jdk.internal.jshell.tool.JShellTool.processSourceCatchingReset(jdk.jshell@9-ea/JShellTool.java:485) at jdk.internal.jshell.tool.JShellTool.run(jdk.jshell@9-ea/JShellTool.java:471) at jdk.internal.jshell.tool.JShellTool.resetState(jdk.jshell@9-ea/JShellTool.java:406) at jdk.internal.jshell.tool.JShellTool.start(jdk.jshell@9-ea/JShellTool.java:252) at jdk.internal.jshell.tool.JShellTool.start(jdk.jshell@9-ea/JShellTool.java:247) at jdk.internal.jshell.tool.JShellTool.main(jdk.jshell@9-ea/JShellTool.java:237) Caused by: com.sun.jdi.connect.VMStartException: VM initialization failed for: /Library/Java/JavaVirtualMachines/jdk-9j.jdk/Contents/Home/bin/java -classpath kulla.jar -Xdebug -Xrunjdwp:transport=dt_socket,address=rockhopper:58850,suspend=y jdk.internal.jshell.remote.RemoteAgent 58849 at com.sun.tools.jdi.AbstractLauncher$Helper.launchAndAccept(jdk.jdi@9-ea/AbstractLauncher.java:193) at com.sun.tools.jdi.AbstractLauncher.launch(jdk.jdi@9-ea/AbstractLauncher.java:132) at com.sun.tools.jdi.SunCommandLineLauncher.launch(jdk.jdi@9-ea/SunCommandLineLauncher.java:223) at jdk.jshell.JDIConnection.launchTarget(jdk.jshell@9-ea/JDIConnection.java:502) ... 31 more |
D’oh!
Ok, let’s try it with a pre-built kulla.jar from the AdoptOpenJDK Cloudbees instance
1 |
$ java -jar kulla.jar |
Same nonsense.
I even downloaded the kulla sources and built them. No difference.
The Workaround
Add your hostname to /etc/hosts.
1 2 3 |
127.0.0.1 rockhopper and the rest... |
(My hostname is rockhopper – the penguin of course, not the bike).
Summary
A simple /etc/hosts one liner fixes the problem.
Yay! Now I can use Java as I’ve used LISP since the 80s!
1 2 3 4 5 6 7 8 9 |
$ $JAVA_HOME/bin/jshell | Welcome to JShell -- Version 9-ea | Type /help for help -> 2 + 2 | Expression value is: 4 | assigned to temporary variable $1 of type int -> |
How do you find out about this? It works after I add that line with my hostname. I have been trying to find a workaround for 2 days already. Almost the same path you do. Tried openjdk preview, AdoptOpenJDK Cloudbees instance, build on my computer and even http://zulu.org/zulu-9-pre-release-downloads/. Same things.
There is a ticket in here:https://bugs.openjdk.java.net/browse/JDK-8131029. Should be fixed anytime soon.
Thanks for sharing this.
I found it through much cursing
Still does not work for me. I typed exactly the word ‘rockhopper’ into my /etc/hosts file but alas this was to no avail. I think perhaps you are mistaked about this technique is good approach to fix the bug.
Perhaps you mistaked[sic] understanding the line “Add your hostname to /etc/hosts.”
This is the right solution.
Try running the hostname command. the use the hostname from output of that command in /etc/hosts.