[JAVA-820] DBCollection Doesn't Check Keys Contained By Lists Created: 29/Apr/13  Updated: 25/Jun/13  Resolved: 18/Jun/13

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.11.2, 2.12.0

Type: Bug Priority: Major - P3
Reporter: Doug Jones Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by JAVA-794 Java driver fails to detect fields wi... Closed

 Description   

In DBCollection._checkKeys (pasted below), if the inner Object is an instance of List, it is not validated. It is possible, for instance, to have a List<BasicDBObject>> where the DBObjects in the list will not have their keys validated.

 private void _checkKeys( DBObject o ) {
        if ( o instanceof LazyDBObject || o instanceof LazyDBList )
            return;
 
        for ( String s : o.keySet() ){
            validateKey ( s );
            Object inner = o.get( s );
            if ( inner instanceof DBObject ) {
                _checkKeys( (DBObject)inner );
            } else if ( inner instanceof Map ) {
                _checkKeys( (Map<String, Object>)inner );
            }
        }
    }



 Comments   
Comment by auto [ 06/Jun/13 ]

Author:

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

Message: JAVA-820. Added support for checking of bad keys within documents contained in a List.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/4f17fe04b5c74ce9f6f1ba9daa8a0840f4afe16c

Comment by auto [ 05/Jun/13 ]

Author:

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

Message: JAVA-820. Added support for checking of bad keys within documents contained in a List.
Branch: 2.11.x
https://github.com/mongodb/mongo-java-driver/commit/7186dc94f405ad8a984c16ea5059b2165a14acd7

Comment by auto [ 05/Jun/13 ]

Author:

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

Message: Modernized test for bad keys. Added commented-out test for JAVA-820
Branch: 2.11.x
https://github.com/mongodb/mongo-java-driver/commit/e79c9daf6b0b90d05edf6a0681dbd95b735d9528

Comment by auto [ 01/May/13 ]

Author:

{u'date': u'2013-05-01T19:25:34Z', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: Modernized test for bad keys. Added commented-out test for JAVA-820
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/0045363d7675a926b7a6b332e5bf0447246613b8

Comment by Jeffrey Yemin [ 30/Apr/13 ]

Confirmed. If you need a quick workaround, you can use BasicDBList, as this test passes:

        try {
            final BasicDBList list = new BasicDBList();
            list.add(new BasicDBObject("$a", 1));
            c.save(new BasicDBObject("a", list));
            fail("Bad key was accepted");
        } 
        catch (IllegalArgumentException e) {
        }

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