Skip to content

Commit eacfd2c

Browse files
EdwardPrenticechristophstrobl
authored andcommitted
DATAMONGO-1608 - Add guard against NPE in MongoQueryCreator when using IgnoreCase.
Original Pull Request: #439
1 parent 439616c commit eacfd2c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
* @author Oliver Gierke
5656
* @author Thomas Darimont
5757
* @author Christoph Strobl
58+
* @author Edward Prentice
5859
*/
5960
class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> {
6061

@@ -297,7 +298,9 @@ private Criteria createLikeRegexCriteriaOrThrow(Part part, MongoPersistentProper
297298
criteria = criteria.not();
298299
}
299300

300-
return addAppropriateLikeRegexTo(criteria, part, parameters.next().toString());
301+
Object next = parameters.next();
302+
303+
return addAppropriateLikeRegexTo(criteria, part, next != null ? next.toString() : "");
301304

302305
case NEVER:
303306
// intentional no-op

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
* @author Thomas Darimont
6767
* @author Christoph Strobl
6868
* @author Mark Paluch
69+
* @author Fırat KÜÇÜK
70+
* @author Edward Prentice
6971
*/
7072
@RunWith(SpringJUnit4ClassRunner.class)
7173
public abstract class AbstractPersonRepositoryIntegrationTests {
@@ -712,6 +714,17 @@ public void executesGeoPageQueryForWithPageRequestForJustOneElementEmptyPage() {
712714
assertThat(results.getAverageDistance().getMetric(), is((Metric) Metrics.KILOMETERS));
713715
}
714716

717+
/***
718+
* @see DATAMONGO-1608
719+
*/
720+
@Test
721+
public void findByFirstNameIgnoreCaseWithNull() {
722+
723+
List<Person> result = repository.findByFirstnameIgnoreCase(null);
724+
725+
assertThat(result.size(), is(0));
726+
}
727+
715728
/**
716729
* @see DATAMONGO-770
717730
*/
@@ -1010,7 +1023,7 @@ public void gettingNonFirstPageWorksWithoutLimitBeingSet() {
10101023

10111024
/**
10121025
* Ignored for now as this requires Querydsl 3.4.1 to succeed.
1013-
*
1026+
*
10141027
* @see DATAMONGO-972
10151028
*/
10161029
@Test

0 commit comments

Comments
 (0)