Skip to content

fix: close a block comment at the first */ when nesting runs to end of input - #2965

Open
edeadington wants to merge 1 commit into
JSQLParser:masterfrom
edeadington:feat/DPC-64447
Open

edeadington wants to merge 1 commit into
JSQLParser:masterfrom
edeadington:feat/DPC-64447

Conversation

@edeadington

@edeadington edeadington commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

/* ... /* ... */ is read as a nested comment that needs a second */. Nesting was added in #1175 because H2 and Oracle nest block comments, but it applies to every dialect, and most do not nest: Snowflake, PostgreSQL, BigQuery and others end a block comment at the first */.

So SQL that is valid in those dialects no longer parses. The common shape is an expression that was commented out while already containing a commented-out older version:

SELECT a
/* commented out:
   AND x = /* default 42
   AND y = 0
*/
FROM t

The scan never gets back to nesting level zero, runs to the end of the input and fails with a lexical error from state IN_BLOCK_COMMENT. Because the comment swallows the rest of the statement, the reported position is at the end of the file, often thousands of characters away from the line that caused it.

Fix

consumeBlockCommentBody() now records where the first */ ended. If nesting runs past the end of the input and some */ was seen along the way, the stream is rewound to it and <MULTI_LINE_COMMENT> closes the comment there — which is what a parser without nesting would have done. If nothing closed the comment at all, nothing changes and the lexical error is raised as before.

Only input that currently throws can take the new path, so nesting keeps working and no feature flag or per-dialect configuration is needed.

Validation

New cases in NestedCommentTest: the unbalanced shape on one line and across lines fail before and pass after; a genuinely unterminated /* never closed still throws; the existing flat, nested and deeply nested cases are unchanged.

./gradlew test checkstyleMain checkstyleTest passes.

…ns to end of input

Block comment nesting (JSQLParser#1175) applies to every dialect, but most do not
nest: Snowflake, PostgreSQL and others end a comment at the first */.
SQL that commented out an expression already containing a commented-out
version therefore failed at end of input from IN_BLOCK_COMMENT.

consumeBlockCommentBody() now records where the first */ ended and, if
nesting runs past the end of the input, rewinds there and closes the
comment. Only input that currently throws takes the new path, so nesting
is unaffected and no feature flag is needed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant