Re: [clojure-mongodb] when using {$exists true} I get "java.lang.Boolean cannot be cast to java.lang.String"

159 views
Skip to first unread message

Michael Klishin

unread,
Jun 23, 2012, 10:58:38 AM6/23/12
to clojure...@googlegroups.com
Daniel Higginbotham:

> However, when it runs, I get the error java.lang.Boolean cannot be cast to java.lang.String .

Please post the entire stack trace.

MK

mic...@defprotocol.org

signature.asc

Michael Klishin

unread,
Jun 23, 2012, 11:15:21 AM6/23/12
to clojure...@googlegroups.com
Daniel Higginbotham:

> However, when it runs, I get the error java.lang.Boolean cannot be cast to java.lang.String .

I cannot reproduce with this small example:

https://github.com/michaelklishin/monger/blob/master/test/monger/test/updating_test.clj#L111-119

>
> Is there some way around this? Am I doing something wrong? Looking at the monger source, I can't understand why a Boolean is being handled by the String to-db-object method.

DBObject conversion protocol has a catch-all case for Object. The thing about protocols is that you are not guaranteed
to have "top to bottom" matching. So maybe we need to add a clause for booleans, however, typically problems
like that were very easy to reproduce before.

MK

mic...@defprotocol.org

signature.asc

Michael Klishin

unread,
Jun 23, 2012, 11:22:19 AM6/23/12
to clojure...@googlegroups.com
Daniel Higginbotham:

> Looking at the monger source, I can't understand why a Boolean is being handled by the String to-db-object method.

You can try a new SNAPSHOT with

https://github.com/michaelklishin/monger/commit/76efdc7e7b3b0dea063bae6322a8644fddc2e5eb

A similar edge is actually pretty well known and we may even be hitting precisely that. Imagine two Java methods
that take a single argument, overloaded like so:

mymethod(Object arg)

mymethod(int arg)

that is invoked via mymethod(1L)

which overloaded version should be used? Technically we are passing a long and only have overload for int primitives
but longs as small as 1 can be safely coerced to ints. Or casted to Object.

I am not familiar enough with the way protocols are compiled but this looks like a reasonable hypothesis. Let me know if
SNAPSHOT works for you better.

MK

mic...@defprotocol.org

signature.asc

Daniel Higginbotham

unread,
Jun 25, 2012, 8:25:28 AM6/25/12
to clojure...@googlegroups.com
It looks like the mistake was something stupid on my part. It turns out the map was {true true} whereas I thought it was {"some string" true} . Sorry about that :(
Reply all
Reply to author
Forward
0 new messages