Skip to content

Commit 148a0b1

Browse files
committed
HHH-19758 Don't reset lexer on SLL parse error
(cherry picked from commit 39ac255)
1 parent b18951e commit 148a0b1

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/OrderByFragmentTranslator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ private static OrderingParser.OrderByFragmentContext buildParseTree(String fragm
7373
return parser.orderByFragment();
7474
}
7575
catch (ParseCancellationException e) {
76+
// When resetting the parser, its CommonTokenStream will seek(0) i.e. restart emitting buffered tokens.
77+
// This is enough when reusing the lexer and parser, and it would be wrong to also reset the lexer.
78+
// Resetting the lexer causes it to hand out tokens again from the start, which will then append to the
79+
// CommonTokenStream and cause a wrong parse
80+
// lexer.reset();
81+
7682
// reset the input token stream and parser state
77-
lexer.reset();
7883
parser.reset();
7984

8085
// fall back to LL(k)-based parsing

hibernate-core/src/main/java/org/hibernate/query/hql/internal/StandardHqlTranslator.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,14 @@ private HqlParser.StatementContext parseHql(String hql) {
104104
try {
105105
return hqlParser.statement();
106106
}
107-
catch ( ParseCancellationException e) {
107+
catch (ParseCancellationException e) {
108+
// When resetting the parser, its CommonTokenStream will seek(0) i.e. restart emitting buffered tokens.
109+
// This is enough when reusing the lexer and parser, and it would be wrong to also reset the lexer.
110+
// Resetting the lexer causes it to hand out tokens again from the start, which will then append to the
111+
// CommonTokenStream and cause a wrong parse
112+
// hqlLexer.reset();
113+
108114
// reset the input token stream and parser state
109-
hqlLexer.reset();
110115
hqlParser.reset();
111116

112117
// fall back to LL(k)-based parsing

0 commit comments

Comments
 (0)