Skip to content

Fix ArrayIndexOutOfBoundsException in NamedParameterUtils for SQL ending with '-' or '/' - #37330

Open
benelog wants to merge 1 commit into
spring-projects:mainfrom
benelog:named-parameter-trailing-comment-start
Open

benelog wants to merge 1 commit into
spring-projects:mainfrom
benelog:named-parameter-trailing-comment-start

Conversation

@benelog

@benelog benelog commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

NamedParameterUtils.parseSqlStatement throws an ArrayIndexOutOfBoundsException when the SQL statement ends with - or /, for example select * from t where a = :a -. skipCommentsAndQuotes matches the first character of the -- and /* comment starts and then reads the next character without checking the statement length.

This PR treats such a trailing character as not starting a comment, so the statement is left as is and any syntax error is reported by the driver instead.

NamedParameterUtils.parseSqlStatement threw an
ArrayIndexOutOfBoundsException for an SQL statement ending with '-' or
'/', since skipCommentsAndQuotes compared the second character of the
"--" and "/*" comment starts without checking the statement length.

This commit treats such a trailing character as not starting a
comment, leaving the statement as is.

Signed-off-by: Sanghyuk Jung <[email protected]>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 24, 2026
@sbrannen sbrannen added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Sep 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: data Issues in data modules (jdbc, orm, oxm, tx) status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants