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

For record type Rec, (instance? Rec (map->Rec {...})) need not return true, though (instance? Rec (Rec. ...)) does.


    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects versions: Release 1.4
    • Fix versions: None
    • Labels:
    • Environment:

      Apache Tomcat/6.0.24 JVM/1.6.0_26-b03 Linux 2.6.32-279.el6.x86_64

      Clojure 1.4.0, Ring 1.1.6, Compojure 1.1.3, Lein-Ring Plugin 0.7.5 (for lein ring uberwar)


      (defrecord Rec ...)

      (instance? Rec (Rec. ...)) ;=> true
      (instance? Rec (map->Rec

      {...})) ;=> can be false

      This occurs when the code is wrapped in a tomcat servlet by `lein ring
      uberwar`, but not when run at the REPL or under Jetty, say.

      Although produced under ring, this seems to me to be a general problem
      with the map-> constructor, as (true? (instance? Rec (map->Rec {...}

      should be an invariant, regardless of the environment or context.
      The problem seems to arise in some aspect of the class loading process:

      (.getClassLoader Rec) ;=> WebappClassLoader (delegate: false, repositories: /WEB-INF/classes/, parent: org.apache.catalina.loader.StandardClassLoader@790bc49d)
      (.getClassLoader (class (Rec. ...))) ;=> WebappClassLoader (same as the previous line)
      (.getClassLoader (class (map->Rec ...))) ;=> clojure.lang.DynamicClassLoader@2e7227a8

      The map->Rec delegates to the create method, which seems to be where the problem lies.

      The record namespace is AOT compiled, properly I think/hope, and the requisite classes
      imported as they should be.

      I have attached a minimal web app that reproduces the problem and shows
      the configuration. As a sanity check, I have also created a trivial
      workaround defrecord* that creates a clojure-native map constructor,
      for which the problem does not occur. See the README.md in the tar
      file for usage details, and the project.clj for my configuration.

      Again, I've only been able to reproduce the problem under Tomcat,
      not under Jetty or at the REPL.




            • Assignee:
            • Votes:
              1 Vote for this issue
              1 Start watching this issue


              • Created: