ANTLR parser should fail when providing an extra parenthesis

Description

Assuming we have a query like this one where the end parenthesis does not have a matching start parenthesis:

The end parenthesis is discarded instead of throwing an exception:

Now, this can lead to very weird situations where any clause following the extra round bracket is simply discarded.

So, if you have an ORDER BY clause after the extra parenthesis:

The ORDER BY vanishes from the SQL statement:

You can find a replicating test case in hibernate-core:

ASTParserLoadingTest#testOrderByExtraParenthesis

Environment

None

Status

Assignee

Vlad Mihalcea

Reporter

Vlad Mihalcea

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure