Browse Source

DATAMONGO-853 - Update does not allow null keys anymore.

Added check for blank / null keys when adding key to Update.

Original pull request: #129.
pull/129/merge
Christoph Strobl 12 years ago committed by Oliver Gierke
parent
commit
5be66a3fee
  1. 3
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java
  2. 24
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/UpdateTests.java

3
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java

@ -26,6 +26,7 @@ import java.util.Map; @@ -26,6 +26,7 @@ import java.util.Map;
import java.util.Set;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import com.mongodb.BasicDBObject;
@ -263,12 +264,14 @@ public class Update { @@ -263,12 +264,14 @@ public class Update {
protected void addFieldOperation(String operator, String key, Object value) {
Assert.hasText(key, "Key/Path for update must not be null or blank.");
modifierOps.put(operator, new BasicDBObject(key, value));
this.keysToUpdate.add(key);
}
protected void addMultiFieldOperation(String operator, String key, Object value) {
Assert.hasText(key, "Key/Path for update must not be null or blank.");
Object existingValue = this.modifierOps.get(operator);
DBObject keyValueMap;

24
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/UpdateTests.java

@ -260,4 +260,28 @@ public class UpdateTests { @@ -260,4 +260,28 @@ public class UpdateTests {
assertThat(clone.modifies("oof"), is(false));
}
/**
* @see DATAMONGO-853
*/
@Test(expected = IllegalArgumentException.class)
public void testAddingMultiFieldOperationThrowsExceptionWhenCalledWithNullKey() {
new Update().addMultiFieldOperation("$op", null, "exprected to throw IllegalArgumentException.");
}
/**
* @see DATAMONGO-853
*/
@Test(expected = IllegalArgumentException.class)
public void testAddingSingleFieldOperationThrowsExceptionWhenCalledWithNullKey() {
new Update().addFieldOperation("$op", null, "exprected to throw IllegalArgumentException.");
}
/**
* @see DATAMONGO-853
*/
@Test(expected = IllegalArgumentException.class)
public void testCreatingUpdateWithNullKeyThrowsException() {
Update.update(null, "value");
}
}

Loading…
Cancel
Save