Skip to content

Commit b345f51

Browse files
committed
Add null check for the ServerCursor, as the server might not have created a cursor even if there are results.
JAVA-1855
1 parent 1cb4b30 commit b345f51

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

driver/src/main/com/mongodb/DBCursor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ public DBCursor skip(final int numberOfElements) {
576576

577577
@Override
578578
public long getCursorId() {
579-
if (cursor != null) {
579+
if (cursor != null && cursor.getServerCursor() != null) {
580580
return cursor.getServerCursor().getId();
581581
} else {
582582
return 0;

driver/src/test/functional/com/mongodb/DBCursorTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ public void testGetCursorId() {
210210
assertEquals(0, cursor.getCursorId());
211211
cursor.hasNext();
212212
assertThat(cursor.getCursorId(), is(not(0L)));
213+
214+
cursor = collection.find();
215+
assertEquals(0, cursor.getCursorId());
216+
cursor.hasNext();
217+
assertThat(cursor.getCursorId(), is(0L));
213218
}
214219

215220
@Test

0 commit comments

Comments
 (0)