`
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.
;badgenclass.clj
(ns badgenclass
(:gen-class
:state state
:methods
[[returnMe [] badgenclass]]
:init init))
(defn -init []
[[] nil])
(defn -returnMe [this]
this)
!/bin/sh
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?
`