Skip to content

Conversation

@xyraclius
Copy link

@xyraclius xyraclius commented Jan 14, 2026

I have implemented a state-aware parser inPreprocessedQuery to resolve GH-4090.

Currently, the ParameterBindingParser incorrectly identifies characters like ? or : as bind markers when they appear inside comments. I chose to use a BitSet to track these "comment zones" rather than stripping the comments entirely for two reasons:

  1. Preserving Optimizer Hints: Many databases rely on comments (e.g., /*+ ... */) for SQL hints. Stripping them would break this functionality.
  2. Offset Integrity: Keeping the original query string intact ensures that character offsets remain accurate for JPA provider error reporting.

The parser handles block comments (/* */), SQL-style line comments (--), and Java-style comments (//). It explicitly tracks string literal bounds first to ensure that markers inside quoted strings are not mistakenly treated as comments.

I've included unit tests with 100% branch coverage for the detection logic and attached a reproducible demo.

Checklist

  • Read the Spring Data contribution guidelines.
  • Used the provided code formatters.
  • Added unit tests covering the new logic.
  • Updated author headers in modified classes.

Fixes #4090.

Demo: demo.zip

Prevent ParameterBindingParser from treating ? and : as bind markers
when they appear inside SQL or JPQL comments.

The query preprocessor now uses a state-aware parser to track block
comments, line comments, and string literals, ensuring parameter
markers are ignored only in valid comment regions while preserving
optimizer hints and query structure.

Fixes spring-projects#4090

Signed-off-by: Nabil Fawwaz Elqayyim <master@nabilfawwaz.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parameter bind marker in query comments are not ignored by ParameterBindingParser

2 participants