[JAVA-1760] Query failure with nested BasicDBObject created from Map Created: 13/Apr/15  Updated: 11/May/15  Resolved: 20/Apr/15

Status: Closed
Project: Java Driver
Component/s: Codecs
Affects Version/s: 3.0.0
Fix Version/s: 3.0.1, 3.1.0

Type: Bug Priority: Minor - P4
Reporter: Jochen Kemnade Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: regression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File regexbug.groovy    
Issue Links:
Related
is related to JAVA-1809 DocumentCodec and DBObjectCodec treat... Closed

 Description   

The attached groovy script works with 2.13.0 but fails with 3.0.0.
The problem is probably related to the PersistentArrayMap class that I create the BasicDBObject from.
Wild guess: Maybe PersistentArrayMap implements an interface that the driver interprets as a marker for a list rather than for a map.



 Comments   
Comment by Jeffrey Yemin [ 05/May/15 ]

Closed for 3.0.1 release.

Comment by Githook User [ 20/Apr/15 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: When encoding a DBObject, if a value implements both Iterable and Map, encode it as a document rather than array. This preserves compatibility with 2.x encoding behavior.

JAVA-1760
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/180ada26acddeb821f96a0804707657ad965a4f0

Comment by Githook User [ 20/Apr/15 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: When encoding a DBObject, if a value implements both Iterable and Map, encode it as a document rather than array. This preserves compatibility with 2.x encoding behavior.

JAVA-1760
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/ea179cdf3f7e4422c2170994eddfa01ad619b2ec

Comment by Jeffrey Yemin [ 13/Apr/15 ]

That's an option, but in this case I think we should prefer backwards compatibility to a breaking change.

Comment by Jochen Kemnade [ 13/Apr/15 ]

Yes, that would probably solve my issue and make 3.x behave like 2.x did, but I still think that an exception should be thrown rather than guessing which interface is more significant.

Comment by Jeffrey Yemin [ 13/Apr/15 ]

You want to try switching the the check for Map and Iterable and see if that resolves it for you? Or I can get you a patch if that would be easier.

Comment by Jochen Kemnade [ 13/Apr/15 ]

It could be com.mongodb.DBObjectCodec.writeValue(BsonWriter, EncoderContext, Object). If the object implements Iterable (which PersistentArrayMap does), it is silently treated as an array, regardless of whether it also implements Map. I think that ambiguities like that should lead to an error.

Generated at Thu Feb 08 08:55:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.