DATAMONGO-1342 - Fixed potential NullPointerException in MongoQueryCreator.

MongoQueryCreator.nextAsArray(…) now returns a single element object array in case null is handed to the method. It previously failed with a NullPointerException.
This commit is contained in:
Oliver Gierke
2015-11-25 17:23:15 +01:00
parent 18bf0daee7
commit eeb37e9104
2 changed files with 15 additions and 1 deletions

View File

@@ -382,7 +382,7 @@ class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> {
if (next instanceof Collection) {
return ((Collection<?>) next).toArray();
} else if (next.getClass().isArray()) {
} else if (next != null && next.getClass().isArray()) {
return (Object[]) next;
}

View File

@@ -661,6 +661,20 @@ public class MongoQueryCreatorUnitTests {
assertThat(query, is(query(where("username").regex(".*"))));
}
/**
* @see DATAMONGO-1342
*/
@Test
public void bindsNullValueToContainsClause() {
PartTree partTree = new PartTree("emailAddressesContains", User.class);
ConvertingParameterAccessor accessor = getAccessor(converter, new Object[] { null });
Query query = new MongoQueryCreator(partTree, accessor, context).createQuery();
assertThat(query, is(query(where("emailAddresses").in((Object) null))));
}
interface PersonRepository extends Repository<Person, Long> {
List<Person> findByLocationNearAndFirstname(Point location, Distance maxDistance, String firstname);