From 0e4e0094a5c894f5927ad72a388eb263bbd496b3 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 24 Oct 2011 14:21:12 -0500 Subject: [PATCH] DATAMONGO-302, DATACMNS-91 - Added null-checks for CRUD methods where necessary. CRUD methods in SimpleMongoRepository now consistently throw IllegalArgumentExceptions for null parameters handed to them. --- .../mongodb/repository/support/SimpleMongoRepository.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java index 0f2e3f899..9a837155e 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java @@ -97,6 +97,7 @@ public class SimpleMongoRepository implements Paging * ) */ public T findOne(ID id) { + Assert.notNull(id, "The given id must not be null!"); return template.findById(id, entityInformation.getJavaType()); } @@ -115,8 +116,9 @@ public class SimpleMongoRepository implements Paging * org.springframework.data.repository.Repository#exists(java.io.Serializable * ) */ - public boolean exists(final ID id) { + public boolean exists(ID id) { + Assert.notNull(id, "The given id must not be null!"); return template.findOne(new Query(Criteria.where("_id").is(id)), Object.class, entityInformation.getCollectionName()) != null; } @@ -136,6 +138,7 @@ public class SimpleMongoRepository implements Paging * @see org.springframework.data.repository.Repository#delete(java.io.Serializable) */ public void delete(ID id) { + Assert.notNull(id, "The given id must not be null!"); template.remove(getIdQuery(id), entityInformation.getJavaType()); } @@ -146,6 +149,7 @@ public class SimpleMongoRepository implements Paging * org.springframework.data.repository.Repository#delete(java.lang.Object) */ public void delete(T entity) { + Assert.notNull(entity, "The given entity must not be null!"); delete(entityInformation.getId(entity)); }