Uploaded image for project: 'Clojure'
  1. CLJ-1457

once the compiler pops the dynamic classloader from the stack, attempts to read record reader literals will fail

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects versions: None
    • Fix versions: None
    • Labels:
    • Approval:
      Triaged
    • Patch:
      Code

      Description

      reproduction case

      java -jar target/clojure-1.7.0-master-SNAPSHOT.jar -e "(do (ns foo.bar) (defrecord Foo []) (defn -main [] (prn (->Foo)) (read-string \"#foo.bar.Foo[]\")))" -m foo.bar
      

      result

      #'foo.bar/-main
      #foo.bar.Foo{}
      Exception in thread "main" java.lang.ClassNotFoundException: foo.bar.Foo
      	at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
      	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      	at java.lang.Class.forName0(Native Method)
      	at java.lang.Class.forName(Class.java:340)
      	at clojure.lang.RT.classForNameNonLoading(RT.java:2076)
      	at clojure.lang.LispReader$CtorReader.readRecord(LispReader.java:1195)
      	at clojure.lang.LispReader$CtorReader.invoke(LispReader.java:1164)
      	at clojure.lang.LispReader$DispatchReader.invoke(LispReader.java:609)
      	at clojure.lang.LispReader.read(LispReader.java:183)
      	at clojure.lang.RT.readString(RT.java:1737)
      	at clojure.core$read_string.invoke(core.clj:3497)
      	at foo.bar$_main.invoke(NO_SOURCE_FILE:1)
      	at clojure.lang.Var.invoke(Var.java:375)
      	at clojure.lang.AFn.applyToHelper(AFn.java:152)
      	at clojure.lang.Var.applyTo(Var.java:700)
      	at clojure.core$apply.invoke(core.clj:624)
      	at clojure.main$main_opt.invoke(main.clj:315)
      	at clojure.main$main.doInvoke(main.clj:420)
      	at clojure.lang.RestFn.invoke(RestFn.java:457)
      	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.main.main(main.java:37)
      

      what happens is the evaluator pushes a dynamicclassloader, evaluates some code, then -m foo.bar causes foo.bar/-main to be called, which tries to read in a literal for the just defined record, but it fails because when foo.bar/-main is called clojure.lang.Compiler/LOADER is unbound so RT uses the sun.misc classloader to try and find the class, which it knows nothing about

      Approaches: If the patch 0001-CLJ-979-make-clojure-resolve-to-the-correct-Class-in-v2.patch for CLJ-979 Closed were to be committed, this issue would be automatically fixed aswell and the patch attached to this ticket would be unnecessary.
      Alternatively, the attached patch (0001-CLJ-1457-ensure-Compiler.LOADER-is-bound-while-readi.patch) simply forces a DynamicClassLoader to be bound to clojure.lang.Compiler/LOADER during reading.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              hiredman Kevin Downey
            • Votes:
              4 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: