Skip to content

Commit eeb37e9

Browse files
committed
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.
1 parent 18bf0da commit eeb37e9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ private Object[] nextAsArray(PotentiallyConvertingIterator iterator, MongoPersis
382382

383383
if (next instanceof Collection) {
384384
return ((Collection<?>) next).toArray();
385-
} else if (next.getClass().isArray()) {
385+
} else if (next != null && next.getClass().isArray()) {
386386
return (Object[]) next;
387387
}
388388

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryCreatorUnitTests.java

+14
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,20 @@ public void likeShouldBeTreatedCorrectlyWhenUsedWithWildcardOnly() {
661661
assertThat(query, is(query(where("username").regex(".*"))));
662662
}
663663

664+
/**
665+
* @see DATAMONGO-1342
666+
*/
667+
@Test
668+
public void bindsNullValueToContainsClause() {
669+
670+
PartTree partTree = new PartTree("emailAddressesContains", User.class);
671+
672+
ConvertingParameterAccessor accessor = getAccessor(converter, new Object[] { null });
673+
Query query = new MongoQueryCreator(partTree, accessor, context).createQuery();
674+
675+
assertThat(query, is(query(where("emailAddresses").in((Object) null))));
676+
}
677+
664678
interface PersonRepository extends Repository<Person, Long> {
665679

666680
List<Person> findByLocationNearAndFirstname(Point location, Distance maxDistance, String firstname);

0 commit comments

Comments
 (0)