[JAVA-1618] BasicBSONList doesn't support zero-length "" key Created: 12/Jan/15  Updated: 31/Mar/15  Resolved: 03/Feb/15

Status: Closed
Project: Java Driver
Component/s: BSON
Affects Version/s: 2.12.3
Fix Version/s: 3.0.0

Type: Bug Priority: Minor - P4
Reporter: Kiyofumi Kondoh Assignee: Unassigned
Resolution: Done Votes: 0
Labels: bson, driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows mongodb 2.6.6 and java-driver 2.12.4
not checked other platform


Issue Links:
Related
is related to CDRIVER-504 Convenient API to create BSON arrays Closed
is related to SERVER-16814 Validate array keys in BSON documents Backlog

 Description   

make data by c-driver

bson_append_array_begin( &bson, "array", -1, &bson_array );
bson_append_int32( &bson_array, "", -1, 1 );
bson_append_int32( &bson_array, "", -1, 2 );
bson_append_array_end( &bson, &bson_array );

view

mongo cli work
csharp-driver work

but java-driver got exception

java.lang.IllegalArgumentException: BasicBSONList can only work with numeric keys, not: []
at org.bson.types.BasicBSONList._getInt(BasicBSONList.java:165)
at org.bson.types.BasicBSONList._getInt(BasicBSONList.java:156)
at org.bson.types.BasicBSONList.put(BasicBSONList.java:70)
at org.bson.BasicBSONCallback._put(BasicBSONCallback.java:184)
at org.bson.BasicBSONCallback.gotLong(BasicBSONCallback.java:132)
at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:222)
at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:271)
at org.bson.BasicBSONDecoder._decode(BasicBSONDecoder.java:154)
at org.bson.BasicBSONDecoder.decode(BasicBSONDecoder.java:132)
at com.mongodb.DefaultDBDecoder.decode(DefaultDBDecoder.java:62)
at com.mongodb.Response.<init>(Response.java:85)
at com.mongodb.DBPort$1.execute(DBPort.java:141)
at com.mongodb.DBPort$1.execute(DBPort.java:135)
at com.mongodb.DBPort.doOperation(DBPort.java:164)
at com.mongodb.DBPort.call(DBPort.java:135)
at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:292)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:271)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:84)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:66)
at com.mongodb.DBCursor._check(DBCursor.java:458)
at com.mongodb.DBCursor._hasNext(DBCursor.java:546)
at com.mongodb.DBCursor.hasNext(DBCursor.java:571)
at com.edgytech.umongo.CollectionPanel$1.doRun(CollectionPanel.java:259)
at com.edgytech.umongo.DbJob$1.doInBackground(DbJob.java:86)
at javax.swing.SwingWorker$1.call(SwingWorker.java:277)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at javax.swing.SwingWorker.run(SwingWorker.java:316)
at com.edgytech.swingfast.ScalableThreadPool$ScalableThreadpoolWorker.run(ScalableThreadPool.java:48)
at java.lang.Thread.run(Thread.java:662)



 Comments   
Comment by Jeffrey Yemin [ 31/Mar/15 ]

Closing all resolved 3.0.0 issues, as 3.0.0 has been tagged and released.

Comment by Jeffrey Yemin [ 03/Feb/15 ]

Fixed due to the new BsonBinaryReader class, which ignores the key name for BSON arrays. See

https://github.com/mongodb/mongo-java-driver/blob/fdf9da18a49d6bb2a8ac3be6fa8092201e0c0051/src/main/org/bson/BSONBinaryReader.java#L75

Comment by Kiyofumi Kondoh [ 13/Jan/15 ]

Hi Jeff.

OK. I tested 3.0.0-SNAPSHOT, wrote simple code.
worked 3.0.0-SNAPSHOT.

driver 3.0.0-20141205.180820
bson 3.0.0-20141226.230022

Comment by Jeffrey Yemin [ 12/Jan/15 ]

Hi Kiyofumi,

Can you test this against the 3.0.0-SNAPSHOT build, as I believe this is addressed there:

 
    <repositories>
        <repository>
            <id>sonatype-snapshot</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        </repository>
    </repositories>
 
   <dependencies>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>driver</artifactId>
            <version>3.0.0-SNAPSHOT</version>
        </dependency>
   </dependencies>

Comment by Kiyofumi Kondoh [ 12/Jan/15 ]

I made pull request
GitHub pull/289

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