Skip to content

Commit c284e4e

Browse files
committed
Polishing.
Refine assertions. See #4132 Original pull request: #4147.
1 parent 4387cd2 commit c284e4e

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.commons.logging.LogFactory;
3030
import org.bson.Document;
3131
import org.bson.conversions.Bson;
32+
3233
import org.springframework.beans.BeansException;
3334
import org.springframework.context.ApplicationContext;
3435
import org.springframework.context.ApplicationContextAware;
@@ -2070,6 +2071,8 @@ public <T> GroupByResults<T> group(@Nullable Criteria criteria, String inputColl
20702071
*/
20712072
@Override
20722073
public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, Class<O> outputType) {
2074+
2075+
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
20732076
return aggregate(aggregation, getCollectionName(aggregation.getInputType()), outputType);
20742077
}
20752078

@@ -2079,9 +2082,6 @@ public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, Clas
20792082
@Override
20802083
public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, String inputCollectionName,
20812084
Class<O> outputType) {
2082-
2083-
Assert.notNull(aggregation, "Aggregation pipeline must not be null!");
2084-
20852085
return aggregate(aggregation, inputCollectionName, outputType, null);
20862086
}
20872087

@@ -2091,6 +2091,7 @@ public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, Stri
20912091
@Override
20922092
public <O> AggregationResults<O> aggregate(Aggregation aggregation, Class<?> inputType, Class<O> outputType) {
20932093

2094+
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
20942095
return aggregate(aggregation, getCollectionName(inputType), outputType,
20952096
queryOperations.createAggregation(aggregation, inputType).getAggregationOperationContext());
20962097
}
@@ -2109,8 +2110,6 @@ public <O> AggregationResults<O> aggregate(Aggregation aggregation, String colle
21092110
@Override
21102111
public <O> CloseableIterator<O> aggregateStream(TypedAggregation<?> aggregation, String inputCollectionName,
21112112
Class<O> outputType) {
2112-
2113-
Assert.notNull(aggregation, "Aggregation pipeline must not be null!");
21142113
return aggregateStream(aggregation, inputCollectionName, outputType, null);
21152114
}
21162115

@@ -2119,6 +2118,8 @@ public <O> CloseableIterator<O> aggregateStream(TypedAggregation<?> aggregation,
21192118
*/
21202119
@Override
21212120
public <O> CloseableIterator<O> aggregateStream(TypedAggregation<?> aggregation, Class<O> outputType) {
2121+
2122+
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
21222123
return aggregateStream(aggregation, getCollectionName(aggregation.getInputType()), outputType);
21232124
}
21242125

@@ -2128,6 +2129,7 @@ public <O> CloseableIterator<O> aggregateStream(TypedAggregation<?> aggregation,
21282129
@Override
21292130
public <O> CloseableIterator<O> aggregateStream(Aggregation aggregation, Class<?> inputType, Class<O> outputType) {
21302131

2132+
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
21312133
return aggregateStream(aggregation, getCollectionName(inputType), outputType,
21322134
queryOperations.createAggregation(aggregation, inputType).getAggregationOperationContext());
21332135
}
@@ -2286,8 +2288,8 @@ protected <O> AggregationResults<O> doAggregate(Aggregation aggregation, String
22862288
protected <O> CloseableIterator<O> aggregateStream(Aggregation aggregation, String collectionName,
22872289
Class<O> outputType, @Nullable AggregationOperationContext context) {
22882290

2289-
Assert.hasText(collectionName, "Collection name must not be null or empty!");
22902291
Assert.notNull(aggregation, "Aggregation pipeline must not be null!");
2292+
Assert.hasText(collectionName, "Collection name must not be null or empty!");
22912293
Assert.notNull(outputType, "Output type must not be null!");
22922294
Assert.isTrue(!aggregation.getOptions().isExplain(), "Can't use explain option with streaming!");
22932295

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,6 @@ public <T> Flux<T> findDistinct(Query query, String field, String collectionName
10181018
public <O> Flux<O> aggregate(TypedAggregation<?> aggregation, String inputCollectionName, Class<O> outputType) {
10191019

10201020
Assert.notNull(aggregation, "Aggregation pipeline must not be null!");
1021-
10221021
return doAggregate(aggregation, inputCollectionName, aggregation.getInputType(), outputType);
10231022
}
10241023

@@ -1028,6 +1027,8 @@ public <O> Flux<O> aggregate(TypedAggregation<?> aggregation, String inputCollec
10281027
*/
10291028
@Override
10301029
public <O> Flux<O> aggregate(TypedAggregation<?> aggregation, Class<O> outputType) {
1030+
1031+
Assert.notNull(aggregation, "Aggregation pipeline must not be null");
10311032
return aggregate(aggregation, getCollectionName(aggregation.getInputType()), outputType);
10321033
}
10331034

0 commit comments

Comments
 (0)