DATAKV-185 - Polishing.

Fix NPE by now returning an expression that always resolves to true.
This commit is contained in:
Christoph Strobl
2017-07-04 22:02:14 +02:00
parent b99510b6e1
commit 256bb16dba
2 changed files with 11 additions and 1 deletions

View File

@@ -214,7 +214,7 @@ public class SpelQueryCreator extends AbstractQueryCreator<KeyValueQuery<SpelExp
}
}
return !StringUtils.hasText(sb) ? null : PARSER.parseRaw(sb.toString());
return StringUtils.hasText(sb) ? PARSER.parseRaw(sb.toString()) : PARSER.parseRaw("true");
}
private static boolean requiresInverseLookup(Part part) {

View File

@@ -306,6 +306,13 @@ public class SpelQueryCreatorUnitTests {
assertThat(evaluate("findByFirstnameIn", list).against(new Person(null, 10)), is(true));
}
@Test // DATAKV-185
public void noDerivedQueryArgumentsMatchesAlways() throws Exception {
assertThat(evaluate("findBy").against(JON), is(true));
assertThat(evaluate("findBy").against(null), is(true));
}
private Evaluation evaluate(String methodName, Object... args) throws Exception {
return new Evaluation((SpelExpression) createQueryForMethodWithArgs(methodName, args).getCriteria());
}
@@ -336,6 +343,9 @@ public class SpelQueryCreatorUnitTests {
static interface PersonRepository {
// No arguments
Person findBy();
// Type.SIMPLE_PROPERTY
Person findByFirstname(String firstname);