Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-267

update DBCusor .next() .hasNext() javadoc to say it can throw an exception WAS: MongoInternalException from DBCursor.hasNext() is inappropriate

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.5
    • Affects Version/s: 2.4
    • Component/s: API
    • None

      If I do the following

      DBCursor curs = db.getCollection("Person").find(query);
      while (curs.hasNext())
      {
      ...
      }

      where query is "{ "firstName" : { "$eq" : "Daffy"}}

      then I get
      com.mongodb.MongoInternalException: couldn't get next element
      at com.mongodb.DBCursor.hasNext(DBCursor.java:459)

      Yes, I (now) know the query object represents invalid BSON (but then someone who is learning this API wouldn't know that, since "$eq" seems logical when you have "$ne", "$gt" etc).

      The fact remains though that there is nothing in the API for Cursor.hasNext() (or java.util.Iterator.hasNext() too which is cleaimed to be implemented here) that permits such an exception. Invalid BSON should be detected in "DBCollection.find()" IMHO, so the user doesn't get unexpected exceptions thrown

            Assignee:
            antoine Antoine Girbal
            Reporter:
            datanucleus Andy Jefferson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: