{"record":{"id":"95069c0e6a176ad2","repo":"prestodb/presto","slug":"lexererrormessage","errorCode":null,"errorMessage":"${lexerErrorMessage}","messagePattern":"\\$\\{lexerErrorMessage\\}","errorType":"exception","errorClass":"ParsingException","httpStatus":null,"severity":"error","filePath":"presto-parser/src/main/java/com/facebook/presto/sql/parser/SqlParser.java","lineNumber":55,"sourceCode":"import java.util.Arrays;\nimport java.util.EnumSet;\nimport java.util.List;\nimport java.util.function.BiConsumer;\nimport java.util.function.Consumer;\nimport java.util.function.Function;\n\nimport static com.facebook.presto.sql.parser.SqlParserOptions.RESERVED_WORDS_WARNING;\nimport static java.lang.String.format;\nimport static java.util.Objects.requireNonNull;\n\npublic class SqlParser\n{\n    private static final BaseErrorListener LEXER_ERROR_LISTENER = new BaseErrorListener()\n    {\n        @Override\n        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String message, RecognitionException e)\n        {\n            throw new ParsingException(message, e, line, charPositionInLine);\n        }\n    };\n    private static final BiConsumer<SqlBaseLexer, SqlBaseParser> DEFAULT_PARSER_INITIALIZER = (SqlBaseLexer lexer, SqlBaseParser parser) -> {};\n\n    private static final ErrorHandler PARSER_ERROR_HANDLER = ErrorHandler.builder()\n            .specialRule(SqlBaseParser.RULE_expression, \"<expression>\")\n            .specialRule(SqlBaseParser.RULE_booleanExpression, \"<expression>\")\n            .specialRule(SqlBaseParser.RULE_valueExpression, \"<expression>\")\n            .specialRule(SqlBaseParser.RULE_primaryExpression, \"<expression>\")\n            .specialRule(SqlBaseParser.RULE_identifier, \"<identifier>\")\n            .specialRule(SqlBaseParser.RULE_string, \"<string>\")\n            .specialRule(SqlBaseParser.RULE_query, \"<query>\")\n            .specialRule(SqlBaseParser.RULE_type, \"<type>\")\n            .specialToken(SqlBaseLexer.INTEGER_VALUE, \"<integer>\")\n            .ignoredRule(SqlBaseParser.RULE_nonReserved)\n            .build();\n\n    private final BiConsumer<SqlBaseLexer, SqlBaseParser> initializer;","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-parser/src/main/java/com/facebook/presto/sql/parser/SqlParser.java#L37-L73","documentation":"This is the lexer-level error path: when the SQL tokenizer (SqlBaseLexer) cannot produce any token for the input, its BaseErrorListener immediately throws a ParsingException with the ANTLR lexer message, line, and column. Unlike parser errors, this fires on characters that cannot start any known token.","triggerScenarios":"Passing SQL containing invalid characters to SqlParser — e.g. stray '!', '@', '$', a single quote opening an unterminated string literal, or an unencodable character.","commonSituations":"Template placeholders (${}, ?, :) left unsubstituted in SQL strings, smart quotes from rich-text editors, broken string escaping producing a dangling quote.","solutions":["Inspect the character at the reported line/column and remove or fix it","Terminate any unterminated string literal with a closing quote","Replace non-ASCII smart quotes with plain quotes","Substitute templating placeholders before parsing"],"exampleFix":"// before\nString sql = \"SELECT 'abc FROM t\"; // unterminated string literal\n// after\nString sql = \"SELECT 'abc' FROM t\";","handlingStrategy":"try-catch","validationCode":"// Reject obvious lexer hazards: unbalanced quotes and stray control chars\nint quotes = 0;\nfor (char c : sql.toCharArray()) if (c == '\\'') quotes++;\nif (quotes % 2 != 0) throw new IllegalArgumentException(\"Unterminated string literal\");","typeGuard":"boolean isLexerSafe(String sql) {\n    return sql != null && sql.chars().noneMatch(c -> c < 0x20 && c != '\\n' && c != '\\t')\n        && sql.replace(\"\\\\'\", \"\").chars().filter(c -> c == '\\'').count() % 2 == 0;\n}","tryCatchPattern":"try {\n    Statement stmt = sqlParser.createStatement(sql);\n} catch (ParsingException e) {\n    log.error(\"Lexer failure at line %d col %d: %s\", e.getLineNumber(), e.getColumnNumber(), e.getErrorMessage());\n    throw new QueryValidationError(sql, e);\n}","preventionTips":["Substitute templating placeholders (?, ${}, :name) before parsing","Strip non-ASCII smart quotes from pasted text","Escape single quotes inside string literals","Validate SQL from untrusted sources before parsing"],"tags":["sql","lexer","tokenizer"],"backgroundTag":"sql-lexical-error","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}