Clojure

A problem involving user.clj and defrecord

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.6
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Environment:
    Java 1.7.0_51 OpenJDK 64-Bit Server VM

Description

On-the-fly generation of defrecord classes fails under certain circumstances.

This github documents the issue: https://github.com/methylene/class-not-found

This was created after a leiningen ticket was closed: https://github.com/technomancy/leiningen/issues/1517

  1. CLJ-1413.tar.bz2
    30/Apr/14 1:49 PM
    2 kB
    Lars Bohl
  2. CLJ-1413-simple.tgz
    13/Nov/14 2:23 AM
    0.7 kB
    Lars Bohl
  3. new-src-folder.tar.bz2
    11/May/14 4:48 PM
    1 kB
    Lars Bohl

Activity

Hide
Alex Miller added a comment -

This ticket needs some work to have a better more concise description of the problem and how to reproduce on the ticket.

Show
Alex Miller added a comment - This ticket needs some work to have a better more concise description of the problem and how to reproduce on the ticket.
Hide
Lars Bohl added a comment -

Prerequisites:

  • a leiningen installation for the first step (install.sh, creates a library jar).
  • The scripts compile.sh and run.sh expect clojure-1.6.0.jar to be in $HOME/Downloads

Reproduce:

by running ./install.sh && ./compile.sh && ./run.sh

This should print something like "#record_holder.def.ParallelAggregator{}". See the main method in src/class_not_found/core.clj.

Instead it fails with a stacktrace, in the last step (./run.sh)

Notice how ./run.sh doesn't fail, after enabling aot in lib/record-holder/project.clj, and then running ./install.sh again.

Also, notice how ./run.sh doesn't fail, after commenting out this line from test/user.clj: (require '[record-holder.def]), and then running ./compile.sh again.

Show
Lars Bohl added a comment - Prerequisites:
  • a leiningen installation for the first step (install.sh, creates a library jar).
  • The scripts compile.sh and run.sh expect clojure-1.6.0.jar to be in $HOME/Downloads
Reproduce: by running ./install.sh && ./compile.sh && ./run.sh This should print something like "#record_holder.def.ParallelAggregator{}". See the main method in src/class_not_found/core.clj. Instead it fails with a stacktrace, in the last step (./run.sh) Notice how ./run.sh doesn't fail, after enabling aot in lib/record-holder/project.clj, and then running ./install.sh again. Also, notice how ./run.sh doesn't fail, after commenting out this line from test/user.clj: (require '[record-holder.def]), and then running ./compile.sh again.
Hide
Lars Bohl added a comment - - edited

Update:

Attaching new src folder..
The shell scripts mentioned above are not needed.
Also, leiningen is not needed.
Reproduce the error by running error.sh, with these contents:

[CLJ-1413(master)]$ cat error.sh
#!/bin/sh
CLOJURE_JAR=$HOME/Downloads/clojure-1.6.0.jar
rm -rf target && mkdir target
echo -e "(set! *compile-path* \"target\")\n(compile 'class-not-found.core)\n" | java -cp src:$CLOJURE_JAR clojure.main -
java -cp target:$CLOJURE_JAR class_not_found.core

There must be a src folder containing user.clj, core.clj and def.clj as follows:

[CLJ-1413]$ find src/ -type f
src/user.clj
src/class_not_found/core.clj
src/record_holder/def.clj

[CLJ-1413(master)]$ find src/ -type f -exec cat "{}" ";"
;; user.clj
(ns user)
(require '[record-holder.def]) ;; remove this line to get rid of error
;; core.clj
(ns class-not-found.core
  (:gen-class)
  (:require record-holder.def)
  (:import record_holder.def.ParallelAggregator))
(defn -main [& _] (println (ParallelAggregator.)))
;; def.clj
(ns record-holder.def)
(defrecord ParallelAggregator [])
Show
Lars Bohl added a comment - - edited Update: Attaching new src folder.. The shell scripts mentioned above are not needed. Also, leiningen is not needed. Reproduce the error by running error.sh, with these contents:
[CLJ-1413(master)]$ cat error.sh
#!/bin/sh
CLOJURE_JAR=$HOME/Downloads/clojure-1.6.0.jar
rm -rf target && mkdir target
echo -e "(set! *compile-path* \"target\")\n(compile 'class-not-found.core)\n" | java -cp src:$CLOJURE_JAR clojure.main -
java -cp target:$CLOJURE_JAR class_not_found.core
There must be a src folder containing user.clj, core.clj and def.clj as follows:
[CLJ-1413]$ find src/ -type f
src/user.clj
src/class_not_found/core.clj
src/record_holder/def.clj

[CLJ-1413(master)]$ find src/ -type f -exec cat "{}" ";"
;; user.clj
(ns user)
(require '[record-holder.def]) ;; remove this line to get rid of error
;; core.clj
(ns class-not-found.core
  (:gen-class)
  (:require record-holder.def)
  (:import record_holder.def.ParallelAggregator))
(defn -main [& _] (println (ParallelAggregator.)))
;; def.clj
(ns record-holder.def)
(defrecord ParallelAggregator [])
Hide
Nicola Mometto added a comment -

This ticket and http://dev.clojure.org/jira/browse/CLJ-1457 might be related

Show
Nicola Mometto added a comment - This ticket and http://dev.clojure.org/jira/browse/CLJ-1457 might be related
Hide
Lars Bohl added a comment -

Nicola, yes it seems that CLJ-1457 produces the same stack trace. Good observation. Uploading an updated reproduce tarball (CLJ-1413-simple.tgz) and pasting the stacktrace that ./error.sh (in the tarball) produces below.

 
[CLJ-1413-simple]$ ./error.sh 
Exception in thread "main" java.lang.ExceptionInInitializerError
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:274)
	at clojure.lang.RT.loadClassForName(RT.java:2093)
	at clojure.lang.RT.load(RT.java:430)
	at clojure.lang.RT.load(RT.java:411)
	at clojure.core$load$fn__5066.invoke(core.clj:5641)
	at clojure.core$load.doInvoke(core.clj:5640)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.lang.Var.invoke(Var.java:379)
	at core.<clinit>(Unknown Source)
Caused by: java.io.FileNotFoundException: Could not locate myrecord__init.class or myrecord.clj on classpath: 
	at clojure.lang.RT.load(RT.java:443)
	at clojure.lang.RT.load(RT.java:411)
	at clojure.core$load$fn__5066.invoke(core.clj:5641)
	at clojure.core$load.doInvoke(core.clj:5640)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invoke(core.clj:5446)
	at clojure.core$load_lib$fn__5015.invoke(core.clj:5486)
	at clojure.core$load_lib.doInvoke(core.clj:5485)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invoke(core.clj:626)
	at clojure.core$load_libs.doInvoke(core.clj:5524)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invoke(core.clj:626)
	at clojure.core$require.doInvoke(core.clj:5607)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at core__init.load(Unknown Source)
	at core__init.<clinit>(Unknown Source)
	... 10 more
Show
Lars Bohl added a comment - Nicola, yes it seems that CLJ-1457 produces the same stack trace. Good observation. Uploading an updated reproduce tarball (CLJ-1413-simple.tgz) and pasting the stacktrace that ./error.sh (in the tarball) produces below.
 
[CLJ-1413-simple]$ ./error.sh 
Exception in thread "main" java.lang.ExceptionInInitializerError
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:274)
	at clojure.lang.RT.loadClassForName(RT.java:2093)
	at clojure.lang.RT.load(RT.java:430)
	at clojure.lang.RT.load(RT.java:411)
	at clojure.core$load$fn__5066.invoke(core.clj:5641)
	at clojure.core$load.doInvoke(core.clj:5640)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.lang.Var.invoke(Var.java:379)
	at core.<clinit>(Unknown Source)
Caused by: java.io.FileNotFoundException: Could not locate myrecord__init.class or myrecord.clj on classpath: 
	at clojure.lang.RT.load(RT.java:443)
	at clojure.lang.RT.load(RT.java:411)
	at clojure.core$load$fn__5066.invoke(core.clj:5641)
	at clojure.core$load.doInvoke(core.clj:5640)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invoke(core.clj:5446)
	at clojure.core$load_lib$fn__5015.invoke(core.clj:5486)
	at clojure.core$load_lib.doInvoke(core.clj:5485)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invoke(core.clj:626)
	at clojure.core$load_libs.doInvoke(core.clj:5524)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invoke(core.clj:626)
	at clojure.core$require.doInvoke(core.clj:5607)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at core__init.load(Unknown Source)
	at core__init.<clinit>(Unknown Source)
	... 10 more
Hide
Lars Bohl added a comment - - edited

Extract

CLJ-1413-simple.tgz
and run ./error.sh. Observe stacktrace.
Then try error.sh again, after commenting out the the (require) in src/user.clj. It should now print "It just works."
This behaviour is very weird, considering that the code in src/user.clj is neither explicitly compiled nor called.

Show
Lars Bohl added a comment - - edited Extract
CLJ-1413-simple.tgz
and run ./error.sh. Observe stacktrace. Then try error.sh again, after commenting out the the (require) in src/user.clj. It should now print "It just works." This behaviour is very weird, considering that the code in src/user.clj is neither explicitly compiled nor called.
Hide
Lars Bohl added a comment -

The sun.misc classloader does not appear in this stacktrace though. Compare stacktrace in CLJ-1457

Show
Lars Bohl added a comment - The sun.misc classloader does not appear in this stacktrace though. Compare stacktrace in CLJ-1457

People

Vote (3)
Watch (2)

Dates

  • Created:
    Updated: