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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user