Skip to content

Commit 301dd51

Browse files
christophstroblmp911de
authored andcommitted
DATAMONGO-1774 - Enforce null constraint checks.
And remove code paths returning null where a reactive wrapper type would be expected. Original pull request: spring-projects#498.
1 parent d3d6242 commit 301dd51

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -898,15 +898,15 @@ <T> Mono<T> findAndModify(Query query, Update update, FindAndModifyOptions optio
898898
/**
899899
* Remove the given object from the collection by id.
900900
*
901-
* @param object
901+
* @param object must not be {@literal null}.
902902
* @return
903903
*/
904904
Mono<DeleteResult> remove(Object object);
905905

906906
/**
907907
* Removes the given object from the given collection.
908908
*
909-
* @param object
909+
* @param object must not be {@literal null}.
910910
* @param collection must not be {@literal null} or empty.
911911
*/
912912
Mono<DeleteResult> remove(Object object, String collection);

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -1455,9 +1455,7 @@ public Mono<DeleteResult> remove(Mono<? extends Object> objectToRemove, String c
14551455
*/
14561456
public Mono<DeleteResult> remove(Object object) {
14571457

1458-
if (object == null) {
1459-
return null;
1460-
}
1458+
Assert.notNull(object, "Object must not be null!");
14611459

14621460
return remove(getIdQueryFor(object), object.getClass());
14631461
}
@@ -1468,12 +1466,9 @@ public Mono<DeleteResult> remove(Object object) {
14681466
*/
14691467
public Mono<DeleteResult> remove(Object object, String collection) {
14701468

1469+
Assert.notNull(object, "Object must not be null!");
14711470
Assert.hasText(collection, "Collection name must not be null or empty!");
14721471

1473-
if (object == null) {
1474-
return null;
1475-
}
1476-
14771472
return doRemove(collection, getIdQueryFor(object), object.getClass());
14781473
}
14791474

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveMongoTemplateTests.java

+5
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ public void testFindAllAndRemoveFullyReturnsAndRemovesDocuments() {
461461
StepVerifier.create(template.findOne(new Query(), Sample.class)).expectNext(data).verifyComplete();
462462
}
463463

464+
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1774
465+
public void removeWithNullShouldThrowError() {
466+
template.remove((Object)null).subscribe();
467+
}
468+
464469
@Test // DATAMONGO-1774
465470
public void removeWithEmptyMonoShouldDoNothing() {
466471

0 commit comments

Comments
 (0)