Skip to content

fix: lex // as a line comment only for H2 and Snowflake - #2957

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:double-slash-line-comments
Nov 24, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:double-slash-line-comments

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor
  1. LINE_COMMENT matches // under every dialect and without one, but only H2 and Snowflake have // comments. Everywhere else //* is a division followed by a block comment, so SELECT 6 //*x*/ 2, (SELECT max(pw) FROM secrets) parses as SELECT 6 and TablesNamesFinder finds no table, while MySQL 9.7, MariaDB, PostgreSQL 16, SQL Server and SQLite all return the subquery (H2 2.3 returns 6, like the current parse). SELECT 1 //**/ 1; DROP TABLE users parses as a single SELECT 1 with mayModifyData() == false, and PostgreSQL drops the table.
  2. // comments are now a lexer switch like # comments: Feature.allowDoubleSlashLineComments / withDoubleSlashLineComments(), turned on by the H2 and SNOWFLAKE presets and implemented with the same token-start rewrite in SimpleCharStream that # uses. With the switch off, //* lexes as / and a block comment; no per-dialect rule goes into the lexer.
  3. Without a dialect or the switch, // comment is now a syntax error, as it is on the servers without // comments. testParseStatementIssue1250 (where // support came from) and LeadingCommentsTest opt in for that reason.

The default-path assertions of the new testDoubleSlashLineCommentsFeature fail on master and the whole test passes after; ./gradlew check (16645 tests, grammar ambiguity, Spotless, Checkstyle, PMD, SpotBugs) and mvn verify pass locally.

LINE_COMMENT matched // in every dialect, but only H2 and Snowflake have
// comments. Everywhere else //* is a division followed by a block
comment, so SELECT 6 //*x*/ 2, (SELECT max(pw) FROM secrets) parsed as
SELECT 6 while MySQL, MariaDB, PostgreSQL, SQL Server and SQLite run the
subquery.

// comments are now a lexer switch like # comments
(Feature.allowDoubleSlashLineComments, withDoubleSlashLineComments),
turned on by the H2 and SNOWFLAKE presets.
@manticore-projects
manticore-projects merged commit 2119fea into JSQLParser:master Nov 24, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

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.

2 participants