Detecting "More than one matching method"

27 views
Skip to first unread message

Maks Romih

unread,
Oct 26, 2010, 10:44:21 AM10/26/10
to Clojure
Hi!

I stumbled on a difference of behavior in using a variable vs. let
binding. It may even be a bug in Clojure.

Using Java 1.6 and Clojure 1.1 or 1.2, if you execute the following
code

<code>
(import
'javax.xml.crypto.dsig.XMLSignatureFactory
'javax.xml.crypto.dsig.Transform)

(def fac (XMLSignatureFactory/getInstance "DOM"))

(let [tf (. fac newTransform Transform/ENVELOPED nil)]
tf)

(let [fac (XMLSignatureFactory/getInstance "DOM")
tf (. fac newTransform Transform/ENVELOPED nil)]
tf)
</code>

the first let works OK while the second one breaks with stack trace
and the error "More than one matching method found: newTransform".
There are really two methods with this name and the second parameter
nil does not differentiate them enough, but I'd like to know why the
first call, with the fac as a variable, succeeds. Which method of the
two does it call?

Maks.

ataggart

unread,
Oct 27, 2010, 2:35:42 PM10/27/10
to Clojure
If you (set! *warn-on-reflection* true) you'll see that the first uses
reflection while the second doesn't. This is (imo) a bug in the
method resolution behavior, namely that the code path for looking up
compiled calls is different from reflected calls.

I submitted a patch to fix both this divergence and to allow for more
correct lookup behavior when it comes to primitive args:
https://www.assembla.com/spaces/clojure/tickets/445

Note that with the patch applied both scenarios result in a "More than
one matching method found" exception, which is (imo) the correct
behavior.

Feel free to bug Stu, et al., to get the patch applied. ;)
Reply all
Reply to author
Forward
0 new messages