Browse files

Empty result iterator's hasNext() returning true

Calling hasNext() method on an empty lazy-loaded query result iterator
returns true while next() method returns null. Consequently, iterating
over such a list results in a single null element being processed.

The reason for this strange behavior is QueryResultIterator's hasNext()
relying on the existence of at least one candidate result, failing to
check if candidate's cursor contains at least one object.

This quick fix ensures that only candidates with a non-empty cursor are
added to query result candidate list.
  • Loading branch information...
1 parent c46c29b commit 050cca852c2bdc854b896a28f1f80c7013ae9f3d @marcin1j committed Dec 31, 2013
Showing with 4 additions and 1 deletion.
  1. +4 −1 src/java/org/datanucleus/store/mongodb/query/
5 src/java/org/datanucleus/store/mongodb/query/
@@ -113,7 +113,10 @@ public CandidateClassResult(AbstractClassMetaData cmd, DBCursor curs, int[] fpMe
public void addCandidateResult(AbstractClassMetaData cmd, DBCursor cursor, int[] fpMembers)
- candidateResults.add(new CandidateClassResult(cmd, cursor, fpMembers));
+ if (cursor.hasNext())
+ {
+ candidateResults.add(new CandidateClassResult(cmd, cursor, fpMembers));
+ }

0 comments on commit 050cca8

Please sign in to comment.