From f85765ba1b56cfa3f60e773d482be74c910fe8b4 Mon Sep 17 00:00:00 2001 From: Evgeniy Cheban Date: Wed, 11 Dec 2024 11:08:26 +0200 Subject: [PATCH] Polish 5b2df328 --- .../query/StringBasedReindexerRepositoryQuery.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/data/reindexer/repository/query/StringBasedReindexerRepositoryQuery.java b/src/main/java/org/springframework/data/reindexer/repository/query/StringBasedReindexerRepositoryQuery.java index 35386cc..63c8014 100644 --- a/src/main/java/org/springframework/data/reindexer/repository/query/StringBasedReindexerRepositoryQuery.java +++ b/src/main/java/org/springframework/data/reindexer/repository/query/StringBasedReindexerRepositoryQuery.java @@ -115,7 +115,10 @@ private String prepareQuery(Object[] parameters) { index += digit; digits++; } - String value = getParameterValuePart(parameters, index - 1); + if (index < 1 || index > parameters.length) { + throw new IllegalStateException("Invalid parameter reference at index: " + i); + } + String value = getParameterValuePart(parameters[index - 1]); result.replace(offset + i - 1, offset + i + digits, value); offset += value.length() - digits - 1; break; @@ -131,7 +134,7 @@ private String prepareQuery(Object[] parameters) { String parameterName = sb.toString(); Integer index = this.namedParameters.get(parameterName); Assert.notNull(index, () -> "No parameter found for name: " + parameterName); - String value = getParameterValuePart(parameters, index); + String value = getParameterValuePart(parameters[index]); result.replace(offset + i - 1, offset + i + parameterName.length(), value); offset += value.length() - parameterName.length() - 1; break; @@ -141,9 +144,7 @@ private String prepareQuery(Object[] parameters) { return result.toString(); } - private String getParameterValuePart(Object[] parameters, int index) { - Assert.state(index >= 0 && index < parameters.length, () -> "No parameter found at index: " + index); - Object value = parameters[index]; + private String getParameterValuePart(Object value) { if (value instanceof String) { return "'" + value + "'"; }