compilation problem with probably core.async

113 views
Skip to first unread message

Leonid K

unread,
Oct 19, 2015, 4:39:05 PM10/19/15
to clojure-android
Hello, all,

I'm having compilation problem with recent adding core.async:

Exception in thread "main" java.lang.ClassCastException: clojure.core.memoize.PluggableMemoization cannot be cast to clojure.core.cache.CacheProtocol, compiling:(mirrored/weather.clj:34:5)
(stacktrace is below, caused by go-loop directive with async/<! operation used)

It used to work while I was developing it against running machine, but (as it happened twice to me now) stopped working during full recompilation.

Quick googling point to Sean Corfield's similar error in google groups and this jira ticket: http://dev.clojure.org/jira/browse/CLJ-1639

Unfortunately, I am not sure what can I do in this case - I have tried disabling AOT in droid, which didn't work. (Application is not starting, and I guess probably having jar files with my codebase is a necessary step to convert that java code to Dalvik instructions?)

Can you please give me an advice whether I can tweak something to still have core.async and somehow continue using all the clojure repl-first goodness.

Thank you,
Leo


Exception in thread "main" java.lang.ClassCastException: clojure.core.memoize.PluggableMemoization cannot be cast to clojure.core.cache.CacheProtocol, compiling:(mirrored/weather.clj:34:5)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6740)
at clojure.lang.Compiler.analyze(Compiler.java:6534)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6721)
at clojure.lang.Compiler.analyze(Compiler.java:6534)
at clojure.lang.Compiler.analyze(Compiler.java:6495)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5871)
at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6189)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6733)
at clojure.lang.Compiler.analyze(Compiler.java:6534)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6721)
at clojure.lang.Compiler.analyze(Compiler.java:6534)
at clojure.lang.Compiler.analyze(Compiler.java:6495)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5871)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5306)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3935)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6731)
at clojure.lang.Compiler.analyze(Compiler.java:6534)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6721)
at clojure.lang.Compiler.analyze(Compiler.java:6534)
at clojure.lang.Compiler.access$300(Compiler.java:38)
at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:577)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6733)
at clojure.lang.Compiler.analyze(Compiler.java:6534)
at clojure.lang.Compiler.analyze(Compiler.java:6495)
at clojure.lang.Compiler.compile1(Compiler.java:7328)
at clojure.lang.Compiler.compile(Compiler.java:7400)
at clojure.lang.RT.compile(RT.java:406)
at clojure.lang.RT.load(RT.java:451)
at clojure.lang.RT.load(RT.java:419)
at clojure.core$load$fn__5458.invoke(core.clj:5862)
at clojure.core$load.doInvoke(core.clj:5861)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5667)
at clojure.core$load_lib$fn__5407.invoke(core.clj:5707)
at clojure.core$load_lib.doInvoke(core.clj:5706)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:632)
at clojure.core$load_libs.doInvoke(core.clj:5745)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:632)
at clojure.core$require.doInvoke(core.clj:5828)
at clojure.lang.RestFn.invoke(RestFn.java:930)
at mirrored.view$loading__5350__auto____13477.invoke(view.clj:1)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3633)
at clojure.lang.Compiler.compile1(Compiler.java:7333)
at clojure.lang.Compiler.compile1(Compiler.java:7323)
at clojure.lang.Compiler.compile(Compiler.java:7400)
at clojure.lang.RT.compile(RT.java:406)
at clojure.lang.RT.load(RT.java:451)
at clojure.lang.RT.load(RT.java:419)
at clojure.core$load$fn__5458.invoke(core.clj:5862)
at clojure.core$load.doInvoke(core.clj:5861)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5667)
at clojure.core$compile$fn__5463.invoke(core.clj:5873)
at clojure.core$compile.invoke(core.clj:5872)
at user$eval5.invoke(form-init8139288172059162865.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6792)
at clojure.lang.Compiler.eval(Compiler.java:6782)
at clojure.lang.Compiler.load(Compiler.java:7237)
at clojure.lang.Compiler.loadFile(Compiler.java:7175)
at clojure.main$load_script.invoke(main.clj:280)
at clojure.main$init_opt.invoke(main.clj:285)
at clojure.main$initialize.invoke(main.clj:313)
at clojure.main$null_opt.invoke(main.clj:348)
at clojure.main$main.doInvoke(main.clj:426)
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.ClassCastException: clojure.core.memoize.PluggableMemoization cannot be cast to clojure.core.cache.CacheProtocol
at clojure.core.cache$fn__3170$G__3096__3173.invoke(cache.clj:20)
at clojure.core.cache$fn__3170$G__3095__3177.invoke(cache.clj:20)
at clojure.core.cache$through.invoke(cache.clj:53)
at clojure.core.memoize$through_STAR_.invoke(memoize.clj:52)
at clojure.lang.Atom.swap(Atom.java:65)
at clojure.core$swap_BANG_.invoke(core.clj:2236)
at clojure.core.memoize$build_memoizer$fn__3443.doInvoke(memoize.clj:134)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.lang.AFunction$1.doInvoke(AFunction.java:29)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.tools.analyzer.jvm$desugar_host_expr.invoke(jvm.clj:115)
at clojure.tools.analyzer.jvm$macroexpand_1.invoke(jvm.clj:170)
at clojure.tools.analyzer$fn__4995.invoke(analyzer.clj:252)
at clojure.lang.MultiFn.invoke(MultiFn.java:238)
at clojure.tools.analyzer$analyze_form.invoke(analyzer.clj:46)
at clojure.tools.analyzer$analyze_in_env$fn__4963.invoke(analyzer.clj:102)
at clojure.core$mapv$fn__6750.invoke(core.clj:6612)
at clojure.lang.PersistentVector.reduce(PersistentVector.java:333)
at clojure.core$reduce.invoke(core.clj:6514)
at clojure.core$mapv.invoke(core.clj:6612)
at clojure.tools.analyzer$fn__4998.invoke(analyzer.clj:264)
at clojure.lang.MultiFn.invoke(MultiFn.java:233)
at clojure.tools.analyzer.jvm$fn__6266.invoke(jvm.clj:65)
at clojure.lang.MultiFn.invoke(MultiFn.java:233)

Alexander Yakushev

unread,
Oct 19, 2015, 4:45:32 PM10/19/15
to clojure-android
You can't really disable AOT on Android, so that is out of question.

I don't know why you get this error, but core.async certainly worked with Clojure-Android before. You might want to try some older versions of it. If the error persists, then it must be something wrong in your code.

Leonid K

unread,
Oct 19, 2015, 4:53:16 PM10/19/15
to clojure-android
Thank you for your quick response!

I tried two versions: September 2014 and August 2014, with the same effect.

What currently (hopefully, no tests yet) worked for me is adding these two lines to :aot-exclude-ns:
"clojure.core.memoize"
"clojure.core.cache"

Code below started to work.

I should say that during repl sessions my code worked okay. I'm continuing poking around to see what happens :)

Just a quick question - can those exclusions from aot affect behavior of core.async?

(defn weather-loop []
  (let [close-chan (chan)] 
    (go-loop []
             (log/e ">>>>READING WEATHER<<<<<")
             (swap! self/world assoc :weather (get-weather))
             (<! (timeout 120000))
             (when (alt! close-chan false :default :keep-going) (recur)))
    close-chan))


Many thanks for your support,
Leo

Alexander Yakushev

unread,
Oct 19, 2015, 5:00:14 PM10/19/15
to clojure-android
The code looks simple enough to be correct. So it must be something wrong in the library then. Could you maybe try some much earlier version, like from beginning of 2015?

If you exclude something from AOT-compilation on Android, and things still work, consider that code not being called at all. Maybe that's the case, I don't know how core.async uses memoize and cache libraries.

Leonid K

unread,
Oct 19, 2015, 5:12:54 PM10/19/15
to clojure-android
Thank you. Core async has releases only for 2014 in Maven - that's what I used and what github page offers.

http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.clojure%22%20AND%20a%3A%22core.async%22

It has some mentions in master on github and on clojars, though.

I will try much older 2014 versions soon,
and I will also try 2015 versions this week when I learn how to reference github commit instead of built-and-published version in project.clj dependencies.
(I figure I need to clone core.async for that, and issue a local maven repository installation, and then refer it from there)

/Leo

Leonid K

unread,
Nov 1, 2015, 3:23:39 AM11/1/15
to clojure-android
Um. Unfortunately, no luck changing library versions (tried Aug 2014 and Oct 2015).
Solution with adding 'memoize' and 'cache' namespaces to AOT exclusions still works though, for some reason.

Leonid K

unread,
Nov 1, 2015, 3:43:15 AM11/1/15
to clojure-android
Addition: just for the record, I see clojure.core.memoize and clojure.core.cache jars in DX output during build despite adding those in aot-exclude-ns section

  :android {
            :aot-exclude-ns ["clojure.parallel" "clojure.core.reducers"
                             "cider.nrepl" "cider-nrepl.plugin"
                             "cider.nrepl.middleware.util.java.parser"
                             "cljs.core.async.macros"
                             "cljs.core.async.impl.ioc-macros"
                             "clojure.core.memoize"
                             "clojure.core.cache" 
                             #"cljs-tooling\..+"]})


DEBUG=1 lein droid doall DX fragment

/home/valt/Android/Sdk/build-tools/23.0.1/dx -JXmx6096M --dex --no-optimize --multi-dex --main-dex-list /home/valt/workspace/mirrored/target/debug/main-dex-list.txt --output /home/valt/workspace/mirrored/target/debug /home/valt/workspace/mirrored/target/debug/classes /home/valt/.m2/repository/org/tcrawley/dynapath/0.2.3/dynapath-0.2.3.jar /home/valt/.m2/repository/org/clojure/tools.reader/0.9.2/tools.reader-0.9.2.jar /home/valt/.m2/repository/prismatic/hiphip/0.2.1/hiphip-0.2.1.jar /home/valt/.m2/repository/org/clojure/tools.nrepl/0.2.10/tools.nrepl-0.2.10.jar /home/valt/.m2/repository/cider/cider-nrepl/0.10.0-SNAPSHOT/cider-nrepl-0.10.0-SNAPSHOT.jar /home/valt/.m2/repository/io/netty/netty-buffer/4.0.26.Final/netty-buffer-4.0.26.Final.jar /home/valt/.m2/repository/slingshot/slingshot/0.12.1/slingshot-0.12.1.jar /home/valt/.m2/repository/clj-http-lite/clj-http-lite/0.3.0/clj-http-lite-0.3.0.jar /home/valt/.m2/repository/quoin/quoin/0.1.0/quoin-0.1.0.jar /home/valt/.m2/repository/org/clojure/test.check/0.6.2/test.check-0.6.2.jar /home/valt/.m2/repository/io/netty/netty-common/4.0.26.Final/netty-common-4.0.26.Final.jar /home/valt/.m2/repository/hickory/hickory/0.5.4/hickory-0.5.4.jar /home/valt/.m2/repository/org/clojure-android/clojure/1.7.0-r3/clojure-1.7.0-r3.jar /home/valt/.m2/repository/clj-wallhack/clj-wallhack/1.0.1/clj-wallhack-1.0.1.jar /home/valt/.m2/repository/com/nanohttpd/nanohttpd/2.1.1/nanohttpd-2.1.1.jar /home/valt/.m2/repository/org/jsoup/jsoup/1.7.2/jsoup-1.7.2.jar /home/valt/.m2/repository/org/clojure/tools.analyzer.jvm/0.6.7/tools.analyzer.jvm-0.6.7.jar /home/valt/.m2/repository/org/clojure/core.async/0.2.371/core.async-0.2.371.jar /home/valt/.m2/repository/org/ccil/cowan/tagsoup/tagsoup/1.2.1/tagsoup-1.2.1.jar /home/valt/.m2/repository/org/clojure/core.memoize/0.5.6/core.memoize-0.5.6.jar /home/valt/.m2/repository/org/ow2/asm/asm-all/4.2/asm-all-4.2.jar /home/valt/.m2/repository/org/clojure/data.json/0.2.6/data.json-0.2.6.jar /home/valt/.m2/repository/neko/neko/4.0.0-alpha5/neko-4.0.0-alpha5.jar /home/valt/.m2/repository/org/clojure/tools.analyzer/0.6.6/tools.analyzer-0.6.6.jar /home/valt/.m2/repository/org/clojure/core.cache/0.6.4/core.cache-0.6.4.jar /home/valt/.m2/repository/clojurewerkz/buffy/1.0.2/buffy-1.0.2.jar /home/valt/.m2/repository/org/clojure/data.priority-map/0.0.4/data.priority-map-0.0.4.jar /home/valt/.m2/repository/enlive/enlive/1.1.6/enlive-1.1.6.jar /home/valt/workspace/mirrored/target/debug/aar-extracted/com.android.support_multidex_aar_1.0.0/classes.jar /home/valt/workspace/mirrored/lib/yandex-speechkit/YandexSpeechKit.jar /home/valt/workspace/mirrored/lib/pocket-sphinx/pocketsphinx-android-5prealpha-nolib.jar /home/valt/Android/Sdk/tools/support/annotations.jar
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.ccil.cowan.tagsoup.Parser$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.


Dependencies in project.clj:


  :dependencies [[org.clojure-android/clojure "1.7.0-r3"]
                 [neko/neko "4.0.0-alpha5"]
                 [clj-http-lite "0.3.0"]
                 [enlive "1.1.6"]
                 [org.clojure/data.json "0.2.6"]
                 [org.clojure/core.memoize "0.5.6"]
                 [org.clojure/core.cache "0.6.4"]
                 [com.nanohttpd/nanohttpd "2.1.1"]
                 [clojurewerkz/buffy "1.0.2"]
                 [prismatic/hiphip "0.2.1"]
                 [clj-wallhack "1.0.1"]
                 ;; [org.nanohttpd/nanohttpd "2.2.0-SNAPSHOT"]
                 [org.clojure/core.async "0.2.371"]
                 ;; [org.clojure/core.async  "0.1.346.0-17112a-alpha"]
                 ;; [org.clojure/core.async  "0.1.338.0-5c5012-alpha"]
                 [hickory "0.5.4"]]

Dependencies in profiles.clj

 :android-user {:dependencies  [[cider/cider-nrepl  "0.10.0-SNAPSHOT"]
                                #_[refactor-nrepl "2.0.0-SNAPSHOT"] ]
                :android  {:aot-exclude-ns  ["cider.nrepl.middleware.util.java.parser"
                                             "cider.nrepl"  "cider-nrepl.plugin"]}} }

Leonid K

unread,
Nov 12, 2015, 3:29:33 PM11/12/15
to clojure-android
Yay! At last I built a minimal example: https://github.com/altV/minimal2

Indeed this looks like a compilation problem, however I can't google how to debug compilation problems like mentioned in http://dev.clojure.org/jira/browse/CLJ-1639.
@Alexander, are you available for um.. beermercial support? :)

Minimal example contains empty project with lein new droid, and 1 file with core.async added there. It seems like it has to do with the order of loading of files during compilation.
I also have this thought - I do not see project.clj.lock somewhere which contains exact versions of clj libraries used by leiningen, so this looks like clojure builds with leiningen might not be 100% reproducible.

Second thought - maybe I can build a minimal example even without lein droid.

Halp! halp! :)

Leonid K

unread,
Nov 12, 2015, 3:47:16 PM11/12/15
to clojure-android
In project.clj I changed [org.clojure-android/clojure "1.7.0-r3"] to [org.clojure/clojure "1.7.0"], and still get the error.
It compiles just fine with any clojure version 1.6, android flavor or not.

Leonid K

unread,
Nov 12, 2015, 4:07:56 PM11/12/15
to clojure-android
This is definitely looks like a problem of core.async and clojure 1.7.
I will try to move to core async jira.

Sorry for offtopic!
Reply all
Reply to author
Forward
0 new messages