[JAVA-451] About closing of cursors Created: 18/Oct/11  Updated: 11/Sep/19  Resolved: 22/Sep/16

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

Type: Task Priority: Minor - P4
Reporter: Guy Boertje Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: cursor
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

jruby 1.6.4



 Description   

Given: a new cursor via a find on a collection
If: the cursor is closed before any documents are fetched
And: the sort order is changed
Then: No exception is thrown

Is this a bug? I expect that an exception should be thrown if one changes the sort or limit etc on a closed cursor.



 Comments   
Comment by Jeffrey Yemin [ 22/Sep/16 ]

As DBCursor is effectively deprecated now, we don't plan to make any further changes in its behavior. The new CRUD API defined in MongoCollection does not suffer from this design issue.

Comment by Guy Boertje [ 18/Oct/11 ]

Sorry I need to be less assuming. This is my understanding.

When the cursor is created the private var _it is null.
If the cursor is never used - only setOptions called, then
the cursor is closed - as _it is null and not an instance of Result nothing is done (no state change).
Then if sort, skip, or limit is called, as _it is still null an IllegalStateException would not be thrown.

AFAIK the java tests dont cover this. In trying to make JMongo API compatible with the ruby driver which does have a test for this, the test failed. Now I know that this may be being over zealous of the ruby driver and I have to make a judgement call on whether to stick hard an fast to the API or skip the test.

It seems weird, in the case described above, to be able to use the cursor after it been closed, or maybe I am missing something.

Comment by Antoine Girbal [ 18/Oct/11 ]

In any case no documents can be fetched anymore.
Changing limit / sort is done client side since no document was ever fetched.
driver could throw an exception but it doesnt seem important to any app?

Generated at Thu Feb 08 08:52:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.