Skip to content

Commit be80704

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

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
@@ -75,8 +75,13 @@ private static OrderingParser.OrderByFragmentContext buildParseTree(TranslationC
7575
return parser.orderByFragment();
7676
}
7777
catch (ParseCancellationException e) {
78+
// When resetting the parser, its CommonTokenStream will seek(0) i.e. restart emitting buffered tokens.
79+
// This is enough when reusing the lexer and parser, and it would be wrong to also reset the lexer.
80+
// Resetting the lexer causes it to hand out tokens again from the start, which will then append to the
81+
// CommonTokenStream and cause a wrong parse
82+
// lexer.reset();
83+
7884
// reset the input token stream and parser state
79-
lexer.reset();
8085
parser.reset();
8186

8287
// 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
@@ -132,9 +132,14 @@ public void reportContextSensitivity(Parser recognizer, DFA dfa, int startIndex,
132132
try {
133133
return hqlParser.statement();
134134
}
135-
catch ( ParseCancellationException e) {
135+
catch (ParseCancellationException e) {
136+
// When resetting the parser, its CommonTokenStream will seek(0) i.e. restart emitting buffered tokens.
137+
// This is enough when reusing the lexer and parser, and it would be wrong to also reset the lexer.
138+
// Resetting the lexer causes it to hand out tokens again from the start, which will then append to the
139+
// CommonTokenStream and cause a wrong parse
140+
// hqlLexer.reset();
141+
136142
// reset the input token stream and parser state
137-
hqlLexer.reset();
138143
hqlParser.reset();
139144

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

0 commit comments

Comments
 (0)