Skip to content

Commit 81a347b

Browse files
author
Steve Briskin
committed
ensure non-null query
1 parent 7c3e4a6 commit 81a347b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/com/mongodb/QueryOpBuilder.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,17 @@ public QueryOpBuilder addSnapshot(boolean snapshot){
9999
* @return DBObject representing the query command to be sent to server
100100
*/
101101
public DBObject get(){
102+
DBObject lclQuery = query;
103+
104+
//must always have a query
105+
if(lclQuery == null){
106+
lclQuery = new BasicDBObject();
107+
}
108+
102109
if(hasSpecialQueryFields()){
103110
DBObject queryop = (specialFields == null ? new BasicDBObject() : specialFields);
104111

105-
addToQueryObject(queryop, "query", query, true);
112+
addToQueryObject(queryop, "query", lclQuery, true);
106113
addToQueryObject(queryop, "orderby", orderBy, false);
107114
if (hintStr != null)
108115
addToQueryObject(queryop, "$hint", hintStr);
@@ -117,7 +124,7 @@ public DBObject get(){
117124
return queryop;
118125
}
119126

120-
return query;
127+
return lclQuery;
121128
}
122129

123130
private boolean hasSpecialQueryFields(){

0 commit comments

Comments
 (0)