DATAMONGO-2478 - Fix NPE in Query.of when given a proxied source.
Original pull request: #836.
This commit is contained in:
committed by
Mark Paluch
parent
5d7e9199de
commit
5d0ab340e3
@@ -547,13 +547,11 @@ public class Query {
|
||||
}
|
||||
};
|
||||
|
||||
target.criteria.putAll(source.criteria);
|
||||
target.skip = source.skip;
|
||||
target.limit = source.limit;
|
||||
target.sort = Sort.unsorted().and(source.sort);
|
||||
target.hint = source.hint;
|
||||
target.collation = source.collation;
|
||||
target.restrictedTypes.addAll(source.restrictedTypes);
|
||||
target.skip = source.getSkip();
|
||||
target.limit = source.getLimit();
|
||||
target.hint = source.getHint();
|
||||
target.collation = source.getCollation();
|
||||
target.restrictedTypes.addAll(source.getRestrictedTypes());
|
||||
|
||||
if (source.getMeta().hasValues()) {
|
||||
target.setMeta(new Meta(source.getMeta()));
|
||||
|
||||
@@ -21,7 +21,7 @@ import static org.springframework.data.mongodb.core.query.Query.*;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
@@ -337,6 +337,19 @@ public class QueryTests {
|
||||
.isNotEqualTo(source.getQueryObject());
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2478
|
||||
public void queryOfShouldWorkOnProxiedObjects() {
|
||||
|
||||
BasicQuery source = new BasicQuery("{ 'foo' : 'bar'}", "{ '_id' : -1, 'foo' : 1 }");
|
||||
source.withHint("the hint");
|
||||
source.limit(10);
|
||||
source.setSortObject(new Document("_id", 1));
|
||||
|
||||
Query target = Query.of((Query) new ProxyFactory(source).getProxy());
|
||||
|
||||
compareQueries(target, source);
|
||||
}
|
||||
|
||||
private void compareQueries(Query actual, Query expected) {
|
||||
|
||||
assertThat(actual.getCollation()).isEqualTo(expected.getCollation());
|
||||
|
||||
Reference in New Issue
Block a user