Skip to content

Commit 8bec3ea

Browse files
committed
Apply workaround for antlr/antlr4#4901
1 parent faa7f52 commit 8bec3ea

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

core/trino-parser/src/main/java/io/trino/sql/parser/SqlParser.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.antlr.v4.runtime.Recognizer;
3838
import org.antlr.v4.runtime.Token;
3939
import org.antlr.v4.runtime.atn.PredictionMode;
40+
import org.antlr.v4.runtime.misc.Interval;
4041
import org.antlr.v4.runtime.misc.Pair;
4142
import org.antlr.v4.runtime.tree.TerminalNode;
4243

@@ -46,6 +47,7 @@
4647
import java.util.function.BiConsumer;
4748
import java.util.function.Function;
4849

50+
import static com.google.common.base.Verify.verify;
4951
import static java.util.Objects.requireNonNull;
5052

5153
public class SqlParser
@@ -73,6 +75,15 @@ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int
7375
.specialToken(SqlBaseLexer.INTEGER_VALUE, "<integer>")
7476
.build();
7577

78+
static {
79+
// TODO: Remove after https://github.com/antlr/antlr4/issues/4901 is fixed
80+
// This is a temporary workaround to prime the internal cache for Interval
81+
// that is not thread safe and can cause concurrency issues.
82+
for (int i = 0; i <= Interval.INTERVAL_POOL_MAX_VALUE; i++) {
83+
verify(Interval.of(i, i).length() == 1, "Expected Interval.of(%s, %s) to have length 1", i, i);
84+
}
85+
}
86+
7687
private final BiConsumer<SqlBaseLexer, SqlBaseParser> initializer;
7788

7889
public SqlParser()

0 commit comments

Comments
 (0)