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

GC Issue 81: compile gen-class fail when class returns self


    • Type: Bug
    • Status: In Progress
    • Priority: Minor
    • Resolution: Unresolved
    • Affects versions: Backlog
    • Fix versions: Backlog
    • Labels:
    • Approval:


       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?




            • Assignee:
              richhickey Rich Hickey
              richhickey Rich Hickey
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: