Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by

Reported by davidhaub, Feb 14, 2009

When attempting to compile the following program, clojure fails with a
ClassNotFoundException. It occurs because one of the methods returns the
same class that is being generated. If the returnMe method below is
changed to return an Object, the compile succeeds.

Beware when testing! If the classpath contains a class file (say from a
prior successful build when the returnMe method was changed to return an
object), the compile will succeed. Always clear out the
clojure.compile.path prior to compiling.

(ns badgenclass

 :state state
 [[returnMe [] badgenclass]]
 :init init))

(defn -init []
[[] nil])

(defn -returnMe [this]


rm -rf classes
mkdir classes
java -cp lib/clojure.jar:classes:. -Dclojure.compile.path=classes \
clojure.lang.Compile badgenclass

Comment 1 by chouser, Mar 07, 2009

Attached is a patch that accepts strings or symbols for parameter and return class
names, and generates the appropriate bytecode without calling Class/forName. It
fixes this issue, but because 'ns' doesn't resolve :gen-class's arguments, class
names aren't checked as early anymore. :gen-class-created classes with invalid
parameter or return types can even be instantiated, and no error will be reported
until the broken method is called.

One possible alternative would be to call Class/forName on any symbols given, but
allow strings to use the method given by this patch. To return your own type, you'd
need a method defined like:

[returnMe [] "badgenclass"]

Any thoughts?


7 Answers

0 votes
0 votes

Comment made by: importer

oranenj said: (link: [file:cWS6Aww30r3RbzeJe5afGb)]: on comment 1

0 votes

Comment made by: importer

richhickey said: Updating tickets (#8, #19, #30, #31, #126, #17, #42, #47, #50, #61, #64, #69, #71, #77, #79, #84, #87, #89, #96, #99, #103, #107, #112, #113, #114, #115, #118, #119, #121, #122, #124)

0 votes

Comment made by: stu

The approach take in the initial patch (delaying resolution of symbols into classes) is fine: gen-class makes no promise about when this happens, and the dynamic approach feels more consistent with Clojure. I think the proposed (but not implemented) use of string/symbol to control when class names are resolved is a bad idea: magical and not implied by the types.


  • update the patch to apply cleanly
  • consider whether totype could live in clojure.reflect.java. (Beware load order dependencies.)
0 votes

Comment made by: chouser@n01se.net

Wow, 18-month-old patch, back to haunt me for Halloway'een

So what does it mean that the assignee is Rich, but it's waiting on me?

0 votes

Comment made by: stu

I am using Approval = Incomplete plus Waiting On = Someone to let submitters know that there is feedback waiting, and that they can move the ticket forward by acting on it. The distinction is opportunity to contribute (something has been provided to let you move forward) vs. expectation of contribution.

0 votes
Reference: https://clojure.atlassian.net/browse/CLJ-84 (reported by richhickey)