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

Java 9 incompatibility #2149

Closed
tommyettinger opened this issue May 23, 2016 · 44 comments · Fixed by #2319
Closed

Java 9 incompatibility #2149

tommyettinger opened this issue May 23, 2016 · 44 comments · Fixed by #2319

Comments

@tommyettinger
Copy link

Due to restructuring in the JDK's internal-use packages, sun.misc is very different in Java 9, and much of it is not available due to the "Project Jigsaw" modularization of the JRE actually making internal-use packages internal. This affects Lein because, at the bare minimum, sun.misc.Launcher is used even when running the command lein with no args. This class, Launcher, is likely being restructured because a new sun.launcher package is present in the root module, whichexports a small subset of sun.misc and other internal-use packages. This subset notably includes the Unsafe class, but that one may be limited to JRE builds that include the module jdk.unsupported, which is discouraged already and a likely candidate for removal in Java 10.

The information on this is scattered around the OpenJDK site, but this JEP is the most relevant: http://openjdk.java.net/jeps/260 , and this section on modularization should also be useful: http://openjdk.java.net/projects/jigsaw/ . I'm using the 4th preview release of the Zulu OpenJDK 9 builds, available here: http://zulu.org/zulu-9-pre-release-downloads/

The exact stacktrace I get when running lein is:

C:\Program Files\Zulu\compiler>lein
Exception in thread "main" java.lang.ExceptionInInitializerError
        at java.lang.Class.forName0(java.base@9-ea/Native Method)
        at java.lang.Class.forName(java.base@9-ea/Class.java:378)
        at clojure.lang.RT.classForName(RT.java:2168)
        at clojure.lang.RT.classForName(RT.java:2177)
        at clojure.lang.RT.loadClassForName(RT.java:2196)
        at clojure.lang.RT.load(RT.java:443)
        at clojure.lang.RT.load(RT.java:419)
        at clojure.core$load$fn__5677.invoke(core.clj:5893)
        at clojure.core$load.invokeStatic(core.clj:5892)
        at clojure.core$load.doInvoke(core.clj:5876)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invokeStatic(core.clj:5697)
        at clojure.core$load_one.invoke(core.clj:5692)
        at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
        at clojure.core$load_lib.invokeStatic(core.clj:5736)
        at clojure.core$load_lib.doInvoke(core.clj:5717)
        at clojure.lang.RestFn.applyTo(RestFn.java:142)
        at clojure.core$apply.invokeStatic(core.clj:648)
        at clojure.core$load_libs.invokeStatic(core.clj:5774)
        at clojure.core$load_libs.doInvoke(core.clj:5758)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invokeStatic(core.clj:648)
        at clojure.core$require.invokeStatic(core.clj:5796)
        at clojure.core$require.doInvoke(core.clj:5796)
        at clojure.lang.RestFn.invoke(RestFn.java:703)
        at leiningen.core.project$loading__5569__auto____5958.invoke(project.clj:1)
        at leiningen.core.project__init.load(Unknown Source)
        at leiningen.core.project__init.<clinit>(Unknown Source)
        at java.lang.Class.forName0(java.base@9-ea/Native Method)
        at java.lang.Class.forName(java.base@9-ea/Class.java:378)
        at clojure.lang.RT.classForName(RT.java:2168)
        at clojure.lang.RT.classForName(RT.java:2177)
        at clojure.lang.RT.loadClassForName(RT.java:2196)
        at clojure.lang.RT.load(RT.java:443)
        at clojure.lang.RT.load(RT.java:419)
        at clojure.core$load$fn__5677.invoke(core.clj:5893)
        at clojure.core$load.invokeStatic(core.clj:5892)
        at clojure.core$load.doInvoke(core.clj:5876)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invokeStatic(core.clj:5697)
        at clojure.core$load_one.invoke(core.clj:5692)
        at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
        at clojure.core$load_lib.invokeStatic(core.clj:5736)
        at clojure.core$load_lib.doInvoke(core.clj:5717)
        at clojure.lang.RestFn.applyTo(RestFn.java:142)
        at clojure.core$apply.invokeStatic(core.clj:648)
        at clojure.core$load_libs.invokeStatic(core.clj:5774)
        at clojure.core$load_libs.doInvoke(core.clj:5758)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invokeStatic(core.clj:648)
        at clojure.core$require.invokeStatic(core.clj:5796)
        at clojure.core$require.doInvoke(core.clj:5796)
        at clojure.lang.RestFn.invoke(RestFn.java:619)
        at leiningen.core.main$loading__5569__auto____5695.invoke(main.clj:1)
        at leiningen.core.main__init.load(Unknown Source)
        at leiningen.core.main__init.<clinit>(Unknown Source)
        at java.lang.Class.forName0(java.base@9-ea/Native Method)
        at java.lang.Class.forName(java.base@9-ea/Class.java:378)
        at clojure.lang.RT.classForName(RT.java:2168)
        at clojure.lang.RT.classForName(RT.java:2177)
        at clojure.lang.RT.loadClassForName(RT.java:2196)
        at clojure.lang.RT.load(RT.java:443)
        at clojure.lang.RT.load(RT.java:419)
        at clojure.core$load$fn__5677.invoke(core.clj:5893)
        at clojure.core$load.invokeStatic(core.clj:5892)
        at clojure.core$load.doInvoke(core.clj:5876)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invokeStatic(core.clj:5697)
        at clojure.core$load_one.invoke(core.clj:5692)
        at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
        at clojure.core$load_lib.invokeStatic(core.clj:5736)
        at clojure.core$load_lib.doInvoke(core.clj:5717)
        at clojure.lang.RestFn.applyTo(RestFn.java:142)
        at clojure.core$apply.invokeStatic(core.clj:648)
        at clojure.core$load_libs.invokeStatic(core.clj:5774)
        at clojure.core$load_libs.doInvoke(core.clj:5758)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invokeStatic(core.clj:648)
        at clojure.core$require.invokeStatic(core.clj:5796)
        at clojure.main$main_opt.invokeStatic(main.clj:314)
        at clojure.main$main_opt.invoke(main.clj:310)
        at clojure.main$main.invokeStatic(main.clj:421)
        at clojure.main$main.doInvoke(main.clj:384)
        at clojure.lang.RestFn.invoke(RestFn.java:421)
        at clojure.lang.Var.invoke(Var.java:383)
        at clojure.lang.AFn.applyToHelper(AFn.java:156)
        at clojure.lang.Var.applyTo(Var.java:700)
        at clojure.main.main(main.java:37)
Caused by: java.lang.ClassNotFoundException: sun.misc.Launcher, compiling:(dynapath/defaults.clj:29:3)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6875)
        at clojure.lang.Compiler.analyze(Compiler.java:6669)
        at clojure.lang.Compiler.analyze(Compiler.java:6625)
        at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6001)
        at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6319)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6868)
        at clojure.lang.Compiler.analyze(Compiler.java:6669)
        at clojure.lang.Compiler.analyze(Compiler.java:6625)
        at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6001)
        at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5380)
        at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3972)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6866)
        at clojure.lang.Compiler.analyze(Compiler.java:6669)
        at clojure.lang.Compiler.eval(Compiler.java:6924)
        at clojure.lang.Compiler.load(Compiler.java:7379)
        at clojure.lang.RT.loadResourceScript(RT.java:372)
        at clojure.lang.RT.loadResourceScript(RT.java:363)
        at clojure.lang.RT.load(RT.java:453)
        at clojure.lang.RT.load(RT.java:419)
        at clojure.core$load$fn__5677.invoke(core.clj:5893)
        at clojure.core$load.invokeStatic(core.clj:5892)
        at clojure.core$load.doInvoke(core.clj:5876)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invokeStatic(core.clj:5697)
        at clojure.core$load_one.invoke(core.clj:5692)
        at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
        at clojure.core$load_lib.invokeStatic(core.clj:5736)
        at clojure.core$load_lib.doInvoke(core.clj:5717)
        at clojure.lang.RestFn.applyTo(RestFn.java:142)
        at clojure.core$apply.invokeStatic(core.clj:648)
        at clojure.core$load_libs.invokeStatic(core.clj:5774)
        at clojure.core$load_libs.doInvoke(core.clj:5758)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invokeStatic(core.clj:648)
        at clojure.core$require.invokeStatic(core.clj:5796)
        at clojure.core$require.doInvoke(core.clj:5796)
        at clojure.lang.RestFn.invoke(RestFn.java:421)
        at dynapath.util$eval254$loading__5569__auto____255.invoke(util.clj:1)
        at dynapath.util$eval254.invokeStatic(util.clj:1)
        at dynapath.util$eval254.invoke(util.clj:1)
        at clojure.lang.Compiler.eval(Compiler.java:6927)
        at clojure.lang.Compiler.eval(Compiler.java:6916)
        at clojure.lang.Compiler.load(Compiler.java:7379)
        at clojure.lang.RT.loadResourceScript(RT.java:372)
        at clojure.lang.RT.loadResourceScript(RT.java:363)
        at clojure.lang.RT.load(RT.java:453)
        at clojure.lang.RT.load(RT.java:419)
        at clojure.core$load$fn__5677.invoke(core.clj:5893)
        at clojure.core$load.invokeStatic(core.clj:5892)
        at clojure.core$load.doInvoke(core.clj:5876)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invokeStatic(core.clj:5697)
        at clojure.core$load_one.invoke(core.clj:5692)
        at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
        at clojure.core$load_lib.invokeStatic(core.clj:5736)
        at clojure.core$load_lib.doInvoke(core.clj:5717)
        at clojure.lang.RestFn.applyTo(RestFn.java:142)
        at clojure.core$apply.invokeStatic(core.clj:648)
        at clojure.core$load_libs.invokeStatic(core.clj:5774)
        at clojure.core$load_libs.doInvoke(core.clj:5758)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invokeStatic(core.clj:648)
        at clojure.core$require.invokeStatic(core.clj:5796)
        at clojure.core$require.doInvoke(core.clj:5796)
        at clojure.lang.RestFn.invoke(RestFn.java:436)
        at cemerick.pomegranate$loading__5569__auto____12241.invoke(pomegranate.clj:1)
        at cemerick.pomegranate__init.load(Unknown Source)
        at cemerick.pomegranate__init.<clinit>(Unknown Source)
        ... 88 more
Caused by: java.lang.ClassNotFoundException: sun.misc.Launcher
        at java.net.URLClassLoader.findClass(java.base@9-ea/URLClassLoader.java:384)
        at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:69)
        at java.lang.ClassLoader.loadClass(java.base@9-ea/ClassLoader.java:486)
        at clojure.lang.DynamicClassLoader.loadClass(DynamicClassLoader.java:77)
        at java.lang.ClassLoader.loadClass(java.base@9-ea/ClassLoader.java:419)
        at java.lang.Class.forName0(java.base@9-ea/Native Method)
        at java.lang.Class.forName(java.base@9-ea/Class.java:378)
        at clojure.lang.RT.classForName(RT.java:2168)
        at clojure.lang.RT.classForName(RT.java:2177)
        at clojure.lang.Compiler.maybeResolveIn(Compiler.java:7187)
        at clojure.core$ns_resolve.invokeStatic(core.clj:4240)
        at clojure.core$ns_resolve.invokeStatic(core.clj:4229)
        at clojure.core$resolve.invokeStatic(core.clj:4242)
        at clojure.core$resolve.invoke(core.clj:4242)
        at dynapath.defaults$when_resolves.invokeStatic(defaults.clj:9)
        at dynapath.defaults$when_resolves.doInvoke(defaults.clj:7)
        at clojure.lang.RestFn.invoke(RestFn.java:467)
        at clojure.lang.Var.invoke(Var.java:394)
        at clojure.lang.AFn.applyToHelper(AFn.java:165)
        at clojure.lang.Var.applyTo(Var.java:700)
        at clojure.lang.Compiler.macroexpand1(Compiler.java:6776)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6854)
        ... 155 more

That's run with a subset of the modules in the normal JDK, but the error is identical if I run with the non-limited module set of a normal OpenJDK 9 installation.

This isn't at all urgent, but I hope there's an easy fix for using sun.* classes that can be applied sometime before Java 9 starts to become more commonly used.

@ayqazi
Copy link

ayqazi commented Aug 30, 2016

I had a similar problem just running lein. To make sure it was not a problem with my set up, I fresh-installed Oracle JDK 9 on my Ubuntu 16.04 LTS installation, and downloaded lein afresh too.

Output:

$ lein version
Exception in thread "main" java.lang.ExceptionInInitializerError
        at java.lang.Class.forName0(java.base@9-ea/Native Method)
        at java.lang.Class.forName(java.base@9-ea/Class.java:374)
        at clojure.lang.RT.classForName(RT.java:2168)
        at clojure.lang.RT.classForName(RT.java:2177)
        at clojure.lang.RT.loadClassForName(RT.java:2196)
        at clojure.lang.RT.load(RT.java:443)
        at clojure.lang.RT.load(RT.java:419)
        at clojure.core$load$fn__5677.invoke(core.clj:5893)
        at clojure.core$load.invokeStatic(core.clj:5892)
        at clojure.core$load.doInvoke(core.clj:5876)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core__init.load(Unknown Source)
        at clojure.core__init.<clinit>(Unknown Source)
        at java.lang.Class.forName0(java.base@9-ea/Native Method)
        at java.lang.Class.forName(java.base@9-ea/Class.java:374)
        at clojure.lang.RT.classForName(RT.java:2168)
        at clojure.lang.RT.classForName(RT.java:2177)
        at clojure.lang.RT.loadClassForName(RT.java:2196)
        at clojure.lang.RT.load(RT.java:443)
        at clojure.lang.RT.load(RT.java:419)
        at clojure.lang.RT.doInit(RT.java:461)
        at clojure.lang.RT.<clinit>(RT.java:331)
        at clojure.main.<clinit>(main.java:20)
Caused by: java.lang.ClassNotFoundException: java/sql/Timestamp
        at java.lang.Class.forName0(java.base@9-ea/Native Method)
        at java.lang.Class.forName(java.base@9-ea/Class.java:374)
        at clojure.lang.RT.classForName(RT.java:2168)
        at clojure.lang.RT.classForNameNonLoading(RT.java:2181)
        at clojure.instant$loading__5569__auto____6869.invoke(instant.clj:9)
        at clojure.instant__init.load(Unknown Source)
        at clojure.instant__init.<clinit>(Unknown Source)
        ... 23 more

I am not a Java person, so do not really have a clue as to what is happening, but it seems related to this issue.

Thanks

@hypirion
Copy link
Collaborator

I'd like to get to the core of this and find out how to resolve it, but I myself would like to wait for feature freeze in Java 9 first. Others are free to look into this of course, and I'll happily take patches for this.

@danielcompton
Copy link
Collaborator

danielcompton commented Nov 16, 2016

Running a REPL with JDK-9 crashes immediately

  • Downloaded today from https://jdk9.java.net/download/

    java version "9-ea"
    Java(TM) SE Runtime Environment (build 9-ea+144)
    Java HotSpot(TM) 64-Bit Server VM (build 9-ea+144, mixed mode)
    
  • No ~/.lein/profiles.clj present

  • In a directory without a project.clj

$ lein repl
Exception in thread "main" java.lang.ExceptionInInitializerError
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:374)
    at clojure.lang.RT.classForName(RT.java:2168)
    at clojure.lang.RT.classForName(RT.java:2177)
    at clojure.lang.RT.loadClassForName(RT.java:2196)
    at clojure.lang.RT.load(RT.java:443)
    at clojure.lang.RT.load(RT.java:419)
    at clojure.core$load$fn__5677.invoke(core.clj:5893)
    at clojure.core$load.invokeStatic(core.clj:5892)
    at clojure.core$load.doInvoke(core.clj:5876)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core__init.load(Unknown Source)
    at clojure.core__init.<clinit>(Unknown Source)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:374)
    at clojure.lang.RT.classForName(RT.java:2168)
    at clojure.lang.RT.classForName(RT.java:2177)
    at clojure.lang.RT.loadClassForName(RT.java:2196)
    at clojure.lang.RT.load(RT.java:443)
    at clojure.lang.RT.load(RT.java:419)
    at clojure.lang.RT.doInit(RT.java:461)
    at clojure.lang.RT.<clinit>(RT.java:331)
    at clojure.main.<clinit>(main.java:20)
Caused by: java.lang.ClassNotFoundException: java/sql/Timestamp
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:374)
    at clojure.lang.RT.classForName(RT.java:2168)
    at clojure.lang.RT.classForNameNonLoading(RT.java:2181)
    at clojure.instant$loading__5569__auto____6869.invoke(instant.clj:9)
    at clojure.instant__init.load(Unknown Source)
    at clojure.instant__init.<clinit>(Unknown Source)
    ... 23 more

@ivanpierre
Copy link

A compilation of Clojure with JDK 9 should give the problem(s). There's a lot of libraries refactoring.

@tobias
Copy link
Collaborator

tobias commented Nov 17, 2016

I can build Clojure HEAD of master and 1.8.0 with 9-ea+144, so I don't think that's the issue.

I was able to get the repl to start by editing bin/lein and removing the lein jar from the bootclasspath here. I believe this is caused by java 9's module system hiding java.sql.* from the bootstrap classloader, and exposing it via the platform classloader instead (see http://openjdk.java.net/jeps/261, and search for "java.sql" to find the relevant paragraph).

You can replicate this with just the Clojure jar with:

/p/tmp> java -Xbootclasspath/a:clojure-1.9.0-alpha14.jar clojure.main -e "(require 'clojure.instant)"
Exception in thread "main" java.lang.ExceptionInInitializerError
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:374)
    at clojure.lang.RT.classForName(RT.java:2183)
    at clojure.lang.RT.classForName(RT.java:2192)
    at clojure.lang.RT.loadClassForName(RT.java:2211)
    at clojure.lang.RT.load(RT.java:445)
    at clojure.lang.RT.load(RT.java:421)
    at clojure.core$load$fn__7846.invoke(core.clj:6008)
    at clojure.core$load.invokeStatic(core.clj:6007)
    at clojure.core$load.doInvoke(core.clj:5991)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core__init.load(Unknown Source)
    at clojure.core__init.<clinit>(Unknown Source)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:374)
    at clojure.lang.RT.classForName(RT.java:2183)
    at clojure.lang.RT.classForName(RT.java:2192)
    at clojure.lang.RT.loadClassForName(RT.java:2211)
    at clojure.lang.RT.load(RT.java:445)
    at clojure.lang.RT.load(RT.java:421)
    at clojure.lang.RT.doInit(RT.java:463)
    at clojure.lang.RT.<clinit>(RT.java:333)
    at clojure.main.<clinit>(main.java:20)
Caused by: java.lang.ClassNotFoundException: java/sql/Timestamp
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:374)
    at clojure.lang.RT.classForName(RT.java:2183)
    at clojure.lang.RT.classForNameNonLoading(RT.java:2196)
    at clojure.instant$loading__7732__auto____9257.invoke(instant.clj:9)
    at clojure.instant__init.load(Unknown Source)
    at clojure.instant__init.<clinit>(Unknown Source)
    ... 23 more
 /p/tmp [1]> java -cp clojure-1.9.0-alpha14.jar clojure.main -e "(require 'clojure.instant)"
 /p/tmp>

@arrdem
Copy link
Contributor

arrdem commented Nov 21, 2016

Was just bitten by this. Downgrading to Java 8 for now.

@hypirion
Copy link
Collaborator

Might be interesting to focus on this soon, as Java 9 is around the corner.

@ivanpierre
Copy link

Warning, it seems to me there is a '_' variable in the Java code for Clojure. It's now a keyword...https://blogs.oracle.com/sundararajan/entry/underscore_is_a_keyword_in

@ivanpierre
Copy link

ivanpierre commented Dec 12, 2016

I'm working on a solution that seems to work with the Clojure REPL concerning the Timestamp.
I'll try compiling Leiningen with the modified JAR to see if there isn't a trap behind the trap... :D
https://gist.github.com/ivanpierre/b0ea937dac97d910a7c3c1e5774028e0

@timmyjose
Copy link

Any updates on this, guys?

@theneva
Copy link

theneva commented Feb 27, 2017

I, too, wonder if anything is happening here :)

@hypirion
Copy link
Collaborator

If the only issue is that Lein is ran from the bootclasspath, then this is trivial. Not running from the bootclasspath is time consuming for users though, so I'd be slightly hesitant to fix this immediately.

I can do some measurements on startup time and see how hard we're penalised by not using the bootclasspath.

@mtexier
Copy link

mtexier commented Mar 28, 2017

I have the same problem after a fresh clojure + lein install on Ubuntu.
Any news?

@hypirion Can you explain?

@technomancy
Copy link
Owner

@mtexier The references to sun.misc in the issue description have been addressed as far as I can tell. If you are seeing problems with running the git master version of Leiningen on Java 9 please do share details; it may be that we have to wait for a stable release of Clojure 1.9.0.

If you're having problems with version 2.7.1 that is expected at this point.

@tobias
Copy link
Collaborator

tobias commented Mar 29, 2017

@hypirion I did some benchmarking of startup time with and without the bootclasspath (averaged over 100 invocations of lein deps):

  • Java 8, using bootclasspath: 1.0394s
  • Java 8, no bootclasspath: 1.1844s
  • Java 9, no bootclasspath: 1.3277s

For me, the difference between Java 8 w/BCP and Java 9 (where loading from the BCP isn't an option) is about 28%. So, it's not terrible, but I know it is a larger margin on slower hardware (I've done some benchmarking on an old linux machine and have seen a more marked difference, but don't have access to that machine atm to confirm).

@technomancy I suspect issues with loading from the bootclasspath won't be fixed in Clojure 1.9, but maybe we can chat with Alex at Clojure/West about it to see.

@mtexier
Copy link

mtexier commented Mar 29, 2017

@technomancy I'm not sure this is the right issue, my exact issue is this one:
clojure-emacs/refactor-nrepl#169
that redirects here.
I tried with git master version of leiningen but I still have the issue:

Exception in thread "main" java.lang.RuntimeException: Unable to resolve var: refactor-nrepl.middleware/wrap-refactor in this context, compiling:(/tmp/form-init6563780447993741250.clj:1:8882)

@tobias
Copy link
Collaborator

tobias commented Mar 29, 2017

@mtexier That issue isn't caused by leiningen, but does have the same root cause as this issue had originally: tobias/dynapath#5. I'll comment further on the refactor-nrepl issue.

@mtexier
Copy link

mtexier commented Mar 30, 2017

@tobias thanks ;)

@tobias
Copy link
Collaborator

tobias commented Mar 31, 2017

It was pointed out to me that I haven't actually said how to get existing leins to work with Java 9. The current workaround is to comment out:

BOOTCLASSPATH="-Xbootclasspath/a:$LEIN_JAR"

from the lein shell script (it should be at line 218 in 2.7.1).

@technomancy
Copy link
Owner

technomancy commented Mar 31, 2017 via email

@ghadishayban
Copy link
Contributor

@hypirion cool, thanks!

It still fails on Java 9 unless someone knows what is wrong, and that they need to modify bootstrap args. Broken seems more user-hostile than slower.

@caifara
Copy link

caifara commented Oct 7, 2017

same here, wanted to try some clojure on my new mac, can't start lein. Pretty much stopped me in my tracks …

fotoetienne added a commit to fotoetienne/cljstache that referenced this issue Oct 7, 2017
fotoetienne added a commit to fotoetienne/cljstache that referenced this issue Oct 7, 2017
* Update dependencies

Removed jline dev dependency. Not sure what that was for.

Not updating lein-doo yet - it has lots of annoying reflection warnings
Not updating clojure or clojurescript in cljs profile yet. Some bleeding edge
pain there still.

* Document 2.0.1 changes

* Document changes since 2.0.0

* Add Java 9 to travis test config

* Rm Java 9 from travis config

Lein isn't ready for Java 9 yet

technomancy/leiningen#2149
https://github.com/tobias/clojure-java-9/issues
@tommyettinger
Copy link
Author

Just as an aside, when I opened this issue over a year ago, the reason Java 9 broke compatibility was completely different than the current one. It's pretty shocking that no one in the OpenJDK team tested major alternative JVM languages effectively enough to find this problem as development moved forward (at times recklessly, e.g. when the sun.misc package was removed). Also, Gradle was completely devastated by the loss of sun.misc.Unsafe, and somehow they were able to make that known and incline the OpenJDK developers to restore it. It would be nice if Leiningen development could have a voice in that kind of area, though I don't know how that whole ordeal resolved itself. While the OpenJDK and especially Oracle side has me feeling disheartened about the future of the JVM, it's encouraging to see not just comments, but commits, by both Leiningen and Clojure developers to fix this issue. It looks to me like Java 9 will be unsuitable for my usage for some time (the LWJGL3 graphics library still isn't especially compatible), but I'm sure by the time most libraries have fixed compatibility issues, Clojure will already have a new stable release (maybe more than one), and Leiningen will be working out-of-the-box once more.

Thanks for all your hard work on this, Clojurers and Leiniacs.

@andrepoleza
Copy link

What I did to solve this issue (temporarily) was reverting the Java version from 9 to 8. In Homebrew is simple as (assuming Java 9 is currently installed):

brew cask zap java
brew cask install caskroom/versions/java8

🤷‍♂️

@AlanBateman
Copy link

Just on "tommyettinger" comment: "It's pretty shocking that no one in the OpenJDK team tested major alternative JVM languages effectively enough to find this problem as development moved forward". That seems a bit unfair. Early access builds of JDK 9 were published very week and Clojure was on the list of projects that were mailed regularly to test with JDK 9 (see https://wiki.openjdk.java.net/display/quality/Quality+Outreach).

On the specifics, sun.misc.Launcher was an undocumented/internal class used to support the java launcher. It was never meant to be used outside of the JDK. It's way too brittle to depend on JDK internal classes as they can change or be removed at any time. In this case, it was replaced in the main line JDK 9 builds in March 2016. The jdeps tool in JDK 8 (and JDK 9) is a useful way to quickly identity usages of internal APIs like this.

On -Xbootlcasspath/a then it works as before in that the classes will be loaded by the boot loader. However, there is ongoing defense-in-depth and security work in the JDK that has moved several non-core modules away from the boot loader. There is no reason for the classes in the java.sql module to be loaded by the boot loader with all permissions for example. This so-called de-privilging work may break code that is deployed in unusual ways as there is no guarantee that all classes in all modules are visible to the boot loader. There is an issue tracking it (tobias/clojure-java-9#1) and I hope the maintainers will find a way to move away from using -Xbootclasspath/a. The startup regression that is mentioned above is worth exploring further. Part of it may be just to move to use G1 as the default collector.

There was never a plan to remove sun.misc.Unsafe in JDK 9. There was discussion on whether to encapsulate it or not, all the details on that topic are in JEP 260 (http://openjdk.java.net/jeps/260).

@tommyettinger
Copy link
Author

@AlanBateman There was certainly an intent to remove sun.misc.Unsafe; see this from Donald Smith, senior director of product management at Oracle: http://mail.openjdk.java.net/pipermail/openjfx-dev/2015-April/017028.html . I think a quote from that post should make said intent clear -- "Let me be blunt -- sun.misc.Unsafe must die in a fire. It is -- wait
for it -- Unsafe. It must go." I worked with an early build of Java 9 that did not make any of the sun.misc package available to third-party code. I don't think it's meaningful to consider "forbidden to access and invisible to outside code" and "removed from the library" as separate...

I haven't even bothered to install the current stable version of Java 9; it was too much of a train wreck working with it in development and I don't see any features in the final release that would actually benefit my everyday development. From what I can gather from other Java developers, I'm far from alone in sticking with Java 8. If the compact profiles turn out to be good for distributing bundled JVMs, I might try it, but I haven't found any documentation or support code describing how that would work with the new module structure.

But now I'm off-topic. This issue has been closed; it may be worthwhile to post a link to the tracking issue regarding the bootloader in either the pull request that closed this issue, or a new issue if there is a chance that the bootloader solution won't stay valid.

@AlanBateman
Copy link

sun.misc.Unsafe does need to die but it will take many years and releases to get there.

The JDK 9 early access builds did not encapsulate sun.misc. Most of the work on JEP 260 to move or remove undocumented internal classes from sun.misc was done in JDK 9 long before we brought the module system into the main line.

@technomancy
Copy link
Owner

I have a hard enough time convincing the Clojure core team to listen to my concerns; honestly the idea that it would be worthwhile to try to talk to people who work at Oracle never even crossed my mind.

The startup regression that is mentioned above is worth exploring further. Part of it may be just to move to use G1 as the default collector.

Unfortunately that's not the case; forcing us off the bootclasspath affects everyone regardless of whether they're using Java 9, so we're in the unfortunate case that Leiningen 2.8.0 will be worse for everyone out of the box in that regard. You can still get back to the original speed if you set LEIN_JVM_OPTS to include the bootclasspath invocation if you know you're never going to use Java 9.

@puredanger
Copy link
Contributor

@tommyettinger as @AlanBateman mentioned, I have long been on a mailing list that notifies me of Java 9 releases to request testing of Clojure with them. I have periodically tested Clojure's build and/or runtime with these releases and have fed back information about things like the need for a sun.misc.Signal break handler to use in the repl. Clojure itself does not have an issue with Java 9 (older versions of Clojure work with it just fine too).

I do not typically test every tool in the Clojure ecosystem with one of these releases and so had not discovered some of the problems in Leiningen or Boot. When we did discover the problem with the use of an unavailable class in the bootclasspath (not something Clojure explicitly states support for by the way), we evaluated alternatives, and implemented a fix in CLJ-2077 to conditionally load those features). That fix has been applied in the Clojure 1.9.0 development builds since before Java 9 was released.

@kenrestivo-stem
Copy link
Contributor

kenrestivo-stem commented Aug 6, 2018

Also having same problem on Java 10 :(

(WARNING: user-level profile defined in project files.)
Exception in thread "main" java.lang.ClassNotFoundException: sun.misc.Launcher, compiling:(dynapath/defaults.clj:29:3)
	at clojure.lang.Compiler.analyzeSeq(Compiler.java:6926)
	at clojure.lang.Compiler.analyze(Compiler.java:6701)
	at clojure.lang.Compiler.analyze(Compiler.java:6657)
	at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6030)
	at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6348)
	at clojure.lang.Compiler.analyzeSeq(Compiler.java:6919)
	at clojure.lang.Compiler.analyze(Compiler.java:6701)
	at clojure.lang.Compiler.analyze(Compiler.java:6657)
	at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6030)
	at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5407)
	at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3973)
	at clojure.lang.Compiler.analyzeSeq(Compiler.java:6917)
	at clojure.lang.Compiler.analyze(Compiler.java:6701)
	at clojure.lang.Compiler.eval(Compiler.java:6975)
	at clojure.lang.Compiler.load(Compiler.java:7430)
	at clojure.lang.RT.loadResourceScript(RT.java:374)
	at clojure.lang.RT.loadResourceScript(RT.java:365)
	at clojure.lang.RT.load(RT.java:455)
	at clojure.lang.RT.load(RT.java:421)
	at clojure.core$load$fn__7846.invoke(core.clj:6008)
	at clojure.core$load.invokeStatic(core.clj:6007)
	at clojure.core$load.doInvoke(core.clj:5991)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5812)
	at clojure.core$load_one.invoke(core.clj:5807)
	at clojure.core$load_lib$fn__7791.invoke(core.clj:5852)
	at clojure.core$load_lib.invokeStatic(core.clj:5851)
	at clojure.core$load_lib.doInvoke(core.clj:5832)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:659)
	at clojure.core$load_libs.invokeStatic(core.clj:5889)
	at clojure.core$load_libs.doInvoke(core.clj:5873)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:659)
	at clojure.core$require.invokeStatic(core.clj:5911)
	at clojure.core$require.doInvoke(core.clj:5911)
	at clojure.lang.RestFn.invoke(RestFn.java:421)
	at dynapath.util$eval44$loading__7732__auto____45.invoke(util.clj:1)
	at dynapath.util$eval44.invokeStatic(util.clj:1)
	at dynapath.util$eval44.invoke(util.clj:1)
	at clojure.lang.Compiler.eval(Compiler.java:6978)
	at clojure.lang.Compiler.eval(Compiler.java:6967)
	at clojure.lang.Compiler.load(Compiler.java:7430)
	at clojure.lang.RT.loadResourceScript(RT.java:374)
	at clojure.lang.RT.loadResourceScript(RT.java:365)
	at clojure.lang.RT.load(RT.java:455)
	at clojure.lang.RT.load(RT.java:421)
	at clojure.core$load$fn__7846.invoke(core.clj:6008)
	at clojure.core$load.invokeStatic(core.clj:6007)
	at clojure.core$load.doInvoke(core.clj:5991)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5812)
	at clojure.core$load_one.invoke(core.clj:5807)
	at clojure.core$load_lib$fn__7791.invoke(core.clj:5852)
	at clojure.core$load_lib.invokeStatic(core.clj:5851)
	at clojure.core$load_lib.doInvoke(core.clj:5832)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:659)
	at clojure.core$load_libs.invokeStatic(core.clj:5889)
	at clojure.core$load_libs.doInvoke(core.clj:5873)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:659)
	at clojure.core$require.invokeStatic(core.clj:5911)
	at clojure.core$require.doInvoke(core.clj:5911)
	at clojure.lang.RestFn.invoke(RestFn.java:436)
	at bultitude.core$eval36$loading__7732__auto____37.invoke(core.clj:1)
	at bultitude.core$eval36.invokeStatic(core.clj:1)
	at bultitude.core$eval36.invoke(core.clj:1)
	at clojure.lang.Compiler.eval(Compiler.java:6978)
	at clojure.lang.Compiler.eval(Compiler.java:6967)
	at clojure.lang.Compiler.load(Compiler.java:7430)
	at clojure.lang.RT.loadResourceScript(RT.java:374)
	at clojure.lang.RT.loadResourceScript(RT.java:365)
	at clojure.lang.RT.load(RT.java:455)
	at clojure.lang.RT.load(RT.java:421)
	at clojure.core$load$fn__7846.invoke(core.clj:6008)
	at clojure.core$load.invokeStatic(core.clj:6007)
	at clojure.core$load.doInvoke(core.clj:5991)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5812)
	at clojure.core$load_one.invoke(core.clj:5807)
	at clojure.core$load_lib$fn__7791.invoke(core.clj:5852)
	at clojure.core$load_lib.invokeStatic(core.clj:5851)
	at clojure.core$load_lib.doInvoke(core.clj:5832)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:659)
	at clojure.core$load_libs.invokeStatic(core.clj:5889)
	at clojure.core$load_libs.doInvoke(core.clj:5873)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:659)
	at clojure.core$require.invokeStatic(core.clj:5911)
	at clojure.core$require.doInvoke(core.clj:5911)
	at clojure.lang.RestFn.invoke(RestFn.java:3204)
	at cloverage.coverage$eval30$loading__7732__auto____31.invoke(coverage.clj:1)
	at cloverage.coverage$eval30.invokeStatic(coverage.clj:1)
	at cloverage.coverage$eval30.invoke(coverage.clj:1)
	at clojure.lang.Compiler.eval(Compiler.java:6978)
	at clojure.lang.Compiler.eval(Compiler.java:6967)
	at clojure.lang.Compiler.load(Compiler.java:7430)
	at clojure.lang.RT.loadResourceScript(RT.java:374)
	at clojure.lang.RT.loadResourceScript(RT.java:365)
	at clojure.lang.RT.load(RT.java:455)
	at clojure.lang.RT.load(RT.java:421)
	at clojure.core$load$fn__7846.invoke(core.clj:6008)
	at clojure.core$load.invokeStatic(core.clj:6007)
	at clojure.core$load.doInvoke(core.clj:5991)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5812)
	at clojure.core$load_one.invoke(core.clj:5807)
	at clojure.core$load_lib$fn__7791.invoke(core.clj:5852)
	at clojure.core$load_lib.invokeStatic(core.clj:5851)
	at clojure.core$load_lib.doInvoke(core.clj:5832)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:659)
	at clojure.core$load_libs.invokeStatic(core.clj:5889)
	at clojure.core$load_libs.doInvoke(core.clj:5873)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:659)
	at clojure.core$require.invokeStatic(core.clj:5911)
	at clojure.core$require.doInvoke(core.clj:5911)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at user$eval13$fn__17.invoke(5cf26ed0978eb366caa862d4f7bc7456985c213e-init.clj:1)
	at user$eval13.invokeStatic(5cf26ed0978eb366caa862d4f7bc7456985c213e-init.clj:1)
	at user$eval13.invoke(5cf26ed0978eb366caa862d4f7bc7456985c213e-init.clj:1)
	at clojure.lang.Compiler.eval(Compiler.java:6978)
	at clojure.lang.Compiler.eval(Compiler.java:6968)
	at clojure.lang.Compiler.load(Compiler.java:7430)
	at clojure.lang.Compiler.loadFile(Compiler.java:7368)
	at clojure.main$load_script.invokeStatic(main.clj:277)
	at clojure.main$init_opt.invokeStatic(main.clj:279)
	at clojure.main$init_opt.invoke(main.clj:279)
	at clojure.main$initialize.invokeStatic(main.clj:310)
	at clojure.main$null_opt.invokeStatic(main.clj:344)
	at clojure.main$null_opt.invoke(main.clj:341)
	at clojure.main$main.invokeStatic(main.clj:423)
	at clojure.main$main.doInvoke(main.clj:386)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.lang.Var.applyTo(Var.java:700)
	at clojure.main.main(main.java:37)
Caused by: java.lang.ClassNotFoundException: sun.misc.Launcher
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
	at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:69)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:566)
	at clojure.lang.DynamicClassLoader.loadClass(DynamicClassLoader.java:77)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:374)
	at clojure.lang.RT.classForName(RT.java:2183)
	at clojure.lang.RT.classForName(RT.java:2192)
	at clojure.lang.Compiler.maybeResolveIn(Compiler.java:7238)
	at clojure.core$ns_resolve.invokeStatic(core.clj:4322)
	at clojure.core$ns_resolve.invokeStatic(core.clj:4311)
	at clojure.core$resolve.invokeStatic(core.clj:4324)
	at clojure.core$resolve.invoke(core.clj:4324)
	at dynapath.defaults$when_resolves.invokeStatic(defaults.clj:9)
	at dynapath.defaults$when_resolves.doInvoke(defaults.clj:7)
	at clojure.lang.RestFn.applyTo(RestFn.java:146)
	at clojure.lang.Var.applyTo(Var.java:700)
	at clojure.lang.Compiler.macroexpand1(Compiler.java:6828)
	at clojure.lang.Compiler.analyzeSeq(Compiler.java:6905)
	... 138 more
Error encountered performing task 'do' with profile(s): 'test'
Suppressed exit

Compilation exited abnormally with code 1 at Mon Aug  6 09:53:13
 java -version
openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Debian-1)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Debian-1, mixed mode)
lein version
Leiningen 2.8.1 on Java 10.0.2 OpenJDK 64-Bit Server VM

@peter-lyons-kehl
Copy link

Hi. I'm new to Clojure and Leiningen. I'm getting ClassNotFoundException: sun.misc.Launcher in Java 10 with Leiningen 2.8.1 and [lein-gorilla "0.4.0"] in plugins: in package.clj.

Help (other than reinstalling old Java), please.

@holyjak
Copy link

holyjak commented Sep 10, 2018

@peter-kehl you might get better help at https://clojurians.slack.com/messages/C0AB48493/

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

Successfully merging a pull request may close this issue.