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

0 votes
in Java Interop by
Two users have reported regressions from the protocol meta added to clojure.reflect returns in Clojure 1.10.

The shortest repro is something like this:


(require 'clojure.reflect)
(eval `~(clojure.reflect/reflect String))

;; Execution error (IllegalArgumentException) at user$eval9/<clinit> (REPL:1).
;; No matching ctor found for class clojure.reflect$typesym$fn__11946

ExceptionInInitializerError
    sun.reflect.NativeConstructorAccessorImpl.newInstance0 (NativeConstructorAccessorImpl.java:-2)
    sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
    java.lang.reflect.Constructor.newInstance (Constructor.java:423)
    java.lang.Class.newInstance (Class.java:442)
    clojure.lang.Compiler$ObjExpr.eval (Compiler.java:4996)
    clojure.lang.Compiler.eval (Compiler.java:7175)
    clojure.lang.Compiler.eval (Compiler.java:7131)
    clojure.core/eval (core.clj:3214)
    clojure.core/eval (core.clj:3210)
    user/eval7 (NO_SOURCE_FILE:1)
    user/eval7 (NO_SOURCE_FILE:1)
Caused by:
IllegalArgumentException No matching ctor found for class clojure.reflect$typesym$fn__11946
    clojure.lang.Reflector.invokeConstructor (Reflector.java:288)
    clojure.lang.LispReader$EvalReader.invoke (LispReader.java:1317)
    clojure.lang.LispReader$DispatchReader.invoke (LispReader.java:853)
    clojure.lang.LispReader.read (LispReader.java:285)
    clojure.lang.LispReader.read (LispReader.java:216)
    clojure.lang.LispReader.read (LispReader.java:205)
    clojure.lang.RT.readString (RT.java:1878)
    clojure.lang.RT.readString (RT.java:1873)
    user/eval9 (NO_SOURCE_FILE:1)
    sun.reflect.NativeConstructorAccessorImpl.newInstance0 (NativeConstructorAccessorImpl.java:-2)
    sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62)


The actual cases where this is happening are uses of clojure.reflect in values returned by macro (see https://groups.google.com/forum/#!msg/clojure/pxLN9tYti4c/zbhLCOrTBgAJ for one example).

*Cause:* Class symbols returned from clojure.reflect are now adorned with meta like:


#:clojure.core.protocols{datafy #object[clojure.reflect$typesym$fn__11946 0x49fc609f "clojure.reflect$typesym$fn__11946@49fc609f"]}


which has an embedded datafy function. The compiler emits this into the compiled class pool (MetaExpr wrapping the object).

*Workaround:* A workaround is to strip the meta from the symbols inside the macro and return the stripped symbol.

1 Answer

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