bug: bean returns the wrong kind of false

0 views
Skip to first unread message

Chouser

unread,
Jan 21, 2009, 12:14:21 AM1/21/09
to clo...@googlegroups.com
The first method of the String class does not take varargs:
user=> (.isVarArgs (first (.getMethods String)))
false

The above is the Right Kind of False, as shown here:
user=> (if (.isVarArgs (first (.getMethods String))) :true :false)
:false

However 'bean' returns the Wrong Kind of False:
user=> (if (:varArgs (bean (first (.getMethods String)))) :true :false)
:true


For those unfamiliar with this lovely feature of Java, it has to do
with ignoring the documented recommendation to use Boolean/valueOf and
instead using the constructor:

user=> (if (Boolean/valueOf "false") :true :false) ; correct
:false

user=> (Boolean. "false") ; don't do this, even though it looks ok
false

user=> (if (Boolean. "false") :true :false) ; see I told you
:true

So the only bug here is that 'bean' is somehow creating the Wrong Kind
of False.

--Chouser

Rich Hickey

unread,
Jan 21, 2009, 8:11:31 AM1/21/09
to Clojure


On Jan 21, 12:14 am, Chouser <chou...@gmail.com> wrote:
> The first method of the String class does not take varargs:
> user=> (.isVarArgs (first (.getMethods String)))
> false
>
> The above is the Right Kind of False, as shown here:
> user=> (if (.isVarArgs (first (.getMethods String))) :true :false)
> :false
>
> However 'bean' returns the Wrong Kind of False:
> user=> (if (:varArgs (bean (first (.getMethods String)))) :true :false)
> :true
>
> For those unfamiliar with this lovely feature of Java, it has to do
> with ignoring the documented recommendation to use Boolean/valueOf and
> instead using the constructor:
>

To clarify, it is Java's own reflection API that is ignoring this.

Worked-around in SVN 1221.

Thanks for the report,

Rich

p.s. for those of you calling Java's reflection API directly (as does
bean), you'll need to canonicalize Booleans, which you can do by
calling clojure.lang.Reflector/prepRet on values returned by
reflection.
Reply all
Reply to author
Forward
0 new messages