Issue Details (XML | Word | Printable)

Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Marcin Jurkowski
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.
DataNucleus Store MongoDB

Calling hasNext() on empty query result iterator returns true

Created: 01/Jan/14 06:09 PM   Updated: 01/Mar/14 07:44 PM   Resolved: 10/Jan/14 05:14 PM
Component/s: None
Affects Version/s: 3.2.7
Fix Version/s: 3.2.8

Datastore: MongoDB

 Description  « Hide
When an empty result list is returned by a query, calling hasNext method on its iterator returns true. The problem will not manifest if DN is forced to evaluate result list eg. by calling makeTransient pm method.

A complete testcase demonstrating this behavior is available on GitHub:

The bug can be fixed in several places. As a quickfix for my current project, I've chosen a solution that requires the minimal amount of code changes ( It involves calling MongoDB cursor's hasNext before adding CandidateClassResult, which may not be "lazy" enough. Therefore, it's probably desirable to implement a more sophisticated logic in QueryResultIterator, deferring database cursor's hasNext call until it's actually needed.

Andy Jefferson added a comment - 10/Jan/14 05:14 PM
GitHub master has a check on DBCursor emptiness

Andy Jefferson made changes - 10/Jan/14 05:14 PM
Field Original Value New Value
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 3.2.8 [ 12071 ]
Resolution Fixed [ 1 ]
Andy Jefferson made changes - 01/Mar/14 07:44 PM
Status Resolved [ 5 ] Closed [ 6 ]