Repository navigation
fix: close a block comment at the first */ when nesting runs to end of input - #2965
Open
edeadington wants to merge 1 commit into
Open
edeadington wants to merge 1 commit into
edeadington wants to merge 1 commit into
Conversation
…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>
edeadington
force-pushed
the
feat/DPC-64447
branch
from
November 30, 2026 14:25
7d39010 to
0f7e45a
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/* ... /* ... */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:
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 closedstill throws; the existing flat, nested and deeply nested cases are unchanged../gradlew test checkstyleMain checkstyleTestpasses.