Skip to content

Commit 256bb16

Browse files
DATAKV-185 - Polishing.
Fix NPE by now returning an expression that always resolves to true.
1 parent b99510b commit 256bb16

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/main/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ protected SpelExpression toPredicateExpression(PartTree tree) {
214214
}
215215
}
216216

217-
return !StringUtils.hasText(sb) ? null : PARSER.parseRaw(sb.toString());
217+
return StringUtils.hasText(sb) ? PARSER.parseRaw(sb.toString()) : PARSER.parseRaw("true");
218218
}
219219

220220
private static boolean requiresInverseLookup(Part part) {

src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ public void inMatchesNullValuesCorrectly() throws Exception {
306306
assertThat(evaluate("findByFirstnameIn", list).against(new Person(null, 10)), is(true));
307307
}
308308

309+
@Test // DATAKV-185
310+
public void noDerivedQueryArgumentsMatchesAlways() throws Exception {
311+
312+
assertThat(evaluate("findBy").against(JON), is(true));
313+
assertThat(evaluate("findBy").against(null), is(true));
314+
}
315+
309316
private Evaluation evaluate(String methodName, Object... args) throws Exception {
310317
return new Evaluation((SpelExpression) createQueryForMethodWithArgs(methodName, args).getCriteria());
311318
}
@@ -336,6 +343,9 @@ private KeyValueQuery<SpelExpression> createQueryForMethodWithArgs(String method
336343

337344
static interface PersonRepository {
338345

346+
// No arguments
347+
Person findBy();
348+
339349
// Type.SIMPLE_PROPERTY
340350
Person findByFirstname(String firstname);
341351

0 commit comments

Comments
 (0)