[JAVA-5085] Override default implementation of Iterater#forEachRemaining in MongoCursor Created: 26/Jul/23  Updated: 28/Oct/23  Resolved: 27/Jul/23

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

Type: Improvement Priority: Unknown
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

To ensure that the cursor is closed in all cases for any applications using Iterator#forEachRemaining:

    @Override
    default void forEachRemaining(final Consumer<? super TResult> action) {
        try {
            Iterator.super.forEachRemaining(action);
        } finally {
            close();
        }
    }



 Comments   
Comment by Githook User [ 27/Jul/23 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Override Iterator#forEachRemaining in MongoCursor (#1161)

The override of the default implementation ensures that the cursor is closed
even if an exception is thrown.

JAVA-5085
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/df1264b9987fd7ed0928518fd9eb61a42b695cfe

Generated at Thu Feb 08 09:03:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.