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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 2.5
    • 2.4
    • API
    • None

    Description

      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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: