Skip to content

Commit 6ab3133

Browse files
committed
Fix improper null/emptiness check.
See #3170
1 parent f493a88 commit 6ab3133

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/main/java/org/springframework/data/repository/query/ValueExpressionQueryRewriter.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,35 @@ public boolean isQuoted(int index) {
303303
return quotations.isQuoted(index);
304304
}
305305

306+
/**
307+
* @param name
308+
* @return
309+
* @since 4.0
310+
*/
311+
public boolean hasExpression(String name) {
312+
return expressions.get(name) != null;
313+
}
314+
315+
@Nullable
306316
public ValueExpression getParameter(String name) {
317+
return expressions.get(name);
318+
}
319+
320+
/**
321+
* Returns the required {@link ValueExpression} for the given name or throws an {@link IllegalArgumentException} if
322+
* the parameter is not present.
323+
*
324+
* @param name
325+
* @return
326+
* @throws IllegalArgumentException if the parameter is not present.
327+
* @since 4.0
328+
*/
329+
public ValueExpression getRequiredParameter(String name) {
307330

308-
ValueExpression valueExpression = expressions.get(name);
331+
ValueExpression valueExpression = getParameter(name);
309332

310333
if (valueExpression == null) {
311-
throw new IllegalArgumentException("No ValueExpression with name '%s' found in query.".formatted(name));
334+
throw new IllegalArgumentException("No ValueExpression with name '%s' found in query".formatted(name));
312335
}
313336

314337
return valueExpression;

0 commit comments

Comments
 (0)