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

Reconsider MongoIterable extending Iterable, MongoCursor/BatchCursor extending Iterator

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • 6.0.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Java Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      com.mongodb.client.MongoIterable extends java.lang.Iterable. The MongoIterable.iterator methods returns MongoCursor, which is Closeable. Since users don't expect iterators returned by Iterable.iterator to require being closed, the method MongoCursor.cursor was added, which is equivalent to MongoIterable.iterator. But this, of course, does not solve the problem, because the MongoIterable.iterator is still there and is usable both explicitly and implicitly by the enhanced for statement, a.k.a. the for-each loop.

      Some of our implementations of MongoCursor/BatchCursor (maybe all, I am not sure) auto-close themselves once exhausted, but this does not mean that applications do not have to close them. And there is a non-negligible chance that applications do not close cursors, especially if they are used in enhanced for statements.

            Assignee:
            Unassigned Unassigned
            Reporter:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: