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

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Minor - P4
    • 2.5
    • Affects Version/s: 2.4
    • Component/s: API
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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 Girbal (Inactive)
              Reporter:
              Andy Jefferson
              None
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: