[JAVA-1012] MongoException thrown for any document that has key named 'err' Created: 12/Oct/13  Updated: 13/Oct/13  Resolved: 13/Oct/13

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 2.11.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Carl Sayres Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I've found a bug in the mongo java driver (v.2.11.3).

Any document containing a key 'err' or 'errmsg' will throw a MongoException when retrieved using findOne().

com.mongodb.MongoException: POSTAL_CODE_NOT_FOUND
at com.mongodb.MongoException.parse(MongoException.java:82)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:292)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:273)
at com.mongodb.DBCollection.findOne(DBCollection.java:347)
at com.mongodb.DBCollection.findOne(DBCollection.java:332)

I traced the problem to com.mongodb.ServerError.

public class ServerError {

ServerError( DBObject o )

{ _err = getMsg( o , null ); if ( _err == null ) throw new IllegalArgumentException( "need to have $err" ); _code = getCode( o ); }

static String getMsg( BSONObject o , String def )

{ Object e = o.get( "$err" ); if ( e == null ) e = o.get( "err" ); if ( e == null ) e = o.get( "errmsg" ); if ( e == null ) return def; return e.toString(); }

Not sure why it would try to interpret an application level 'err' message as a reason to throw a MongoException:



 Comments   
Comment by Jeffrey Yemin [ 13/Oct/13 ]

This has been fixed already as part of JAVA-978

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