Skip to content

Commit 2894ab4

Browse files
author
Brendan W. McAdams
committed
Fixes JAVA-411, findOne fails when fields are specified but no document is found ( NullPointerException )
* Test for nullness on DBObject prior to setting PartialObject when fields are set
1 parent f25ef2b commit 2894ab4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/main/com/mongodb/DBCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ public final DBObject findOne( DBObject o )
564564
public final DBObject findOne( DBObject o, DBObject fields ) {
565565
Iterator<DBObject> i = __find( o , fields , 0 , -1 , 0, getOptions() );
566566
DBObject obj = (i == null ? null : i.next());
567-
if ( fields != null && fields.keySet().size() > 0 ){
567+
if ( obj != null && ( fields != null && fields.keySet().size() > 0 ) ){
568568
obj.markAsPartialObject();
569569
}
570570
return obj;

0 commit comments

Comments
 (0)