clj-commons / virgil

Recompile Java code without restarting the REPL
312 stars 21 forks source link

Dependency clash with org.clojure/tools.analyzer.jvm #7

Closed miikka closed 6 years ago

miikka commented 7 years ago

tools.analyzer.jvm depends on [org.ow2.asm/asm-all "4.2"] and Virgil depends on [org.ow2.asm/asm "5.1"]. ASM 4.2 does not support Java 8, so if you depend on both and manage to get the libraries in the wrong order in your classpath, you'll get this stacktrace from Virgil:

Exception in thread "main" java.lang.IllegalArgumentException, compiling:(/private/var/folders/8s/w7wls65s2vvdml8ztk54jfch0000gn/T/form-init7439712748175071086.clj:1:125)
    at clojure.lang.Compiler.load(Compiler.java:7391)
    at clojure.lang.Compiler.loadFile(Compiler.java:7317)
    at clojure.main$load_script.invokeStatic(main.clj:275)
    at clojure.main$init_opt.invokeStatic(main.clj:277)
    at clojure.main$init_opt.invoke(main.clj:277)
    at clojure.main$initialize.invokeStatic(main.clj:308)
    at clojure.main$null_opt.invokeStatic(main.clj:342)
    at clojure.main$null_opt.invoke(main.clj:339)
    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.IllegalArgumentException
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at virgil.decompile$parents.invokeStatic(decompile.clj:12)
    at virgil.decompile$parents.invoke(decompile.clj:12)
    at virgil.decompile$rank_order$parents__1212.invoke(decompile.clj:24)
    at clojure.core$map$fn__4785.invoke(core.clj:2646)
    at clojure.lang.LazySeq.sval(LazySeq.java:40)
    at clojure.lang.LazySeq.seq(LazySeq.java:49)
    at clojure.lang.RT.seq(RT.java:521)
    at clojure.core$seq__4357.invokeStatic(core.clj:137)
    at clojure.core$zipmap.invokeStatic(core.clj:2962)
    at clojure.core$zipmap.invoke(core.clj:2962)
    at virgil.decompile$rank_order.invokeStatic(decompile.clj:25)
    at virgil.decompile$rank_order.invoke(decompile.clj:18)
    at virgil.compile$compile_java.invokeStatic(compile.clj:86)
    at virgil.compile$compile_java.invoke(compile.clj:81)
    at virgil.compile$compile_all_java.invokeStatic(compile.clj:103)
    at virgil.compile$compile_all_java.invoke(compile.clj:102)
    at virgil$watch$recompile__1292.invoke(virgil.clj:15)
    at virgil$watch.invokeStatic(virgil.clj:26)
    at virgil$watch.doInvoke(virgil.clj:9)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at user$eval1309.invokeStatic(form-init7439712748175071086.clj:1)
    at user$eval1309.invoke(form-init7439712748175071086.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)
    ... 14 more

The annoying thing is that because the artefact IDs do not match, lein deps :tree or :pedantic? :abort in project.clj won't complain about the problem. A possible workaround is to exclude asm-all and hope that it won't break anything in tools.analyzer.jvm.


I'm not sure if Virgil needs to do anything about this. Mostly I opened this issue to document the problem somewhere. Since tools.analyzer.jvm is a fairly common dependency, this might bite some other people as well. Took me a while to figure out what's going on.

ztellman commented 7 years ago

Hmmm, do you happen to know if tools.analyzer needs that particular version of the ASM library? I can make sure that I remove older versions, if not.

miikka commented 7 years ago

I don't know for sure, but I doubt it. It only uses org.objectweb.asm.Type/getType and Type.java hasn't changed much after ASM 4.2. I quickly tried running the tools.analyzer.jvm tests after bumping the ASM dep and they all passed, for whatever that's worth.

miikka commented 7 years ago

For what is worth, there's now an issue on tools.jvm.analyzer JIRA to update its ASM dependency, inspired by encountering a similar problem with another library.

alexander-yakushev commented 6 years ago

FWIW, the ticket is closed, and t.j.a. has updated the dependency: https://github.com/clojure/tools.analyzer.jvm/commit/f273e18a58bcf9d34861e80c5ca278427dea48cd

@miikka, could you please confirm if this issue is obsolete now?

miikka commented 6 years ago

Yes, this is obsolete now. Of course it can still happen with other libraries that depend on org.ow2.asm/asm-all, but I'm not sure if it makes sense for Virgil to be super-defensive here. I'll close this issue.