[JAVA-1909] Cannot read BSON symbol from MongoCollection<BasicDBObject> document Created: 31/Jul/15  Updated: 14/Sep/15  Resolved: 27/Aug/15

Status: Closed
Project: Java Driver
Component/s: BSON
Affects Version/s: 3.0.3
Fix Version/s: 3.0.4, 3.1.0

Type: Bug Priority: Minor - P4
Reporter: Alexander Azarov Assignee: Ross Lawley
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MongoDB server 3.0.4


Attachments: Text File fix_symbol.patch    

 Description   

What I tried to do is to run a code from the documentation to use BasicDBObject in the new CRUD API. My test document contained a BSON symbol and I got an exception where I didn't expect to have one.

scala> import com.mongodb._
import com.mongodb._
 
scala> val db = new MongoClient("localhost").getDatabase("test")
июл 31, 2015 7:59:31 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
db: com.mongodb.client.MongoDatabase = com.mongodb.MongoDatabaseImpl@2ff5be19
 
scala> июл 31, 2015 7:59:31 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:1, serverValue:6}] to localhost:27017
июл 31, 2015 7:59:31 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 0, 4]}, minWireVersion=0, maxWireVersion=3, electionId=null, maxDocumentSize=16777216, roundTripTimeNanos=560000}
 
 
scala> 
 
scala> db.getCollection("test").find.first
июл 31, 2015 7:59:52 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:2, serverValue:7}] to localhost:27017
res0: org.bson.Document = Document{{_id=55bb50acb5b97f6d98b6186c, i32=1, s=str, sym=symbol}}
 
scala> db.getCollection("test", classOf[BasicDBObject]).find.first
org.bson.BsonInvalidOperationException: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is SYMBOL.
  at org.bson.AbstractBsonReader.verifyBSONType(AbstractBsonReader.java:655)
  at org.bson.AbstractBsonReader.checkPreconditions(AbstractBsonReader.java:687)
  at org.bson.AbstractBsonReader.readString(AbstractBsonReader.java:428)
  at org.bson.codecs.StringCodec.decode(StringCodec.java:35)
  at org.bson.codecs.StringCodec.decode(StringCodec.java:27)
  at com.mongodb.DBObjectCodec.readValue(DBObjectCodec.java:306)
  at com.mongodb.DBObjectCodec.readDocument(DBObjectCodec.java:345)
  at com.mongodb.DBObjectCodec.decode(DBObjectCodec.java:136)
  at com.mongodb.DBObjectCodec.decode(DBObjectCodec.java:61)
  at com.mongodb.connection.ReplyMessage.<init>(ReplyMessage.java:57)
  at com.mongodb.connection.QueryProtocol.receiveMessage(QueryProtocol.java:290)
  at com.mongodb.connection.QueryProtocol.execute(QueryProtocol.java:229)
  at com.mongodb.connection.QueryProtocol.execute(QueryProtocol.java:38)
  at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:155)
  at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:219)
  at com.mongodb.connection.DefaultServerConnection.query(DefaultServerConnection.java:166)
  at com.mongodb.operation.FindOperation$1.call(FindOperation.java:397)
  at com.mongodb.operation.FindOperation$1.call(FindOperation.java:394)
  at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:195)
  at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:168)
  at com.mongodb.operation.FindOperation.execute(FindOperation.java:394)
  at com.mongodb.operation.FindOperation.execute(FindOperation.java:57)
  at com.mongodb.Mongo.execute(Mongo.java:738)
  at com.mongodb.Mongo$2.execute(Mongo.java:725)
  at com.mongodb.FindIterableImpl$FindOperationIterable.first(FindIterableImpl.java:197)
  at com.mongodb.FindIterableImpl.first(FindIterableImpl.java:140)
  ... 43 elided



 Comments   
Comment by Jeffrey Yemin [ 14/Sep/15 ]

Fix release today in 3.0.4.

Comment by Githook User [ 27/Aug/15 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Fix Symbol decoding in DBObjectCodec

JAVA-1909
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/ac6fa70da866aa2c34ce8b2d1f567cccffb32c42

Comment by Githook User [ 27/Aug/15 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Fix Symbol decoding in DBObjectCodec

JAVA-1909
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/6f1e7a26527ce95f60b1e106004167820344c46f

Comment by Ross Lawley [ 27/Aug/15 ]

Thanks for the initial report Alexander and then the patch Amir.

I used the patch as a basis for a fix, which will be released in the next release of the 3.0.x driver and in the forthcoming 3.1 driver.

Comment by Githook User [ 27/Aug/15 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Fix Symbol decoding in DBObjectCodec

JAVA-1909
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/4a383c9f9ced582c1c591debe768195d80abfe58

Comment by Githook User [ 27/Aug/15 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Fix Symbol decoding in DBObjectCodec

JAVA-1909
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/9f2532820041e80db567216d3ce6abaaeb694798

Comment by Ross Lawley [ 24/Aug/15 ]

Thanks Amir for the patch, this is scheduled to be fixed in the next release.

Comment by Amir Lanesman [ 24/Aug/15 ]

Attached a possible solution for issue.

Comment by Jeffrey Yemin [ 31/Jul/15 ]

Thanks for the report Alexander. We'll take a look and get back to you with any questions we may have.

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