HHH-11942 - ANTLR parser should fail when providing an extra parenthesis

Fix issue by parsing the whole statements until the EOF instead of stopping at any unexpected right closing paranthesis
This commit is contained in:
Vlad Mihalcea 2017-08-24 17:26:22 +03:00 committed by Andrea Boriero
parent e950957b89
commit e9cc8867af
3 changed files with 19 additions and 14 deletions

View File

@ -242,7 +242,7 @@ tokens
}
statement
: ( updateStatement | deleteStatement | selectStatement | insertStatement )
: ( updateStatement | deleteStatement | selectStatement | insertStatement ) (EOF!)
;
// Without the optionalVersioned if the path starts with a keyword the parser fails

View File

@ -3786,19 +3786,23 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
}
@Test
@FailureExpected( jiraKey = "HHH-11942" )
@TestForIssue( jiraKey = "HHH-11942" )
public void testOrderByExtraParenthesis() throws Exception {
doInHibernate( this::sessionFactory, session -> {
session.createQuery(
"select a from Product a " +
"where " +
"coalesce(a.description, :description) = :description ) " +
"order by a.description ", Product.class)
.setParameter( "description", "desc" )
.getResultList();
fail("Should throw parsing exception");
} );
try {
doInHibernate( this::sessionFactory, session -> {
session.createQuery(
"select a from Product a " +
"where " +
"coalesce(a.description, :description) = :description ) " +
"order by a.description ", Product.class)
.setParameter( "description", "desc" )
.getResultList();
} );
}
catch (IllegalArgumentException e) {
QueryException rootCause = (QueryException) e.getCause();
assertTrue( rootCause.getMessage().startsWith( "node to traverse cannot be null!" ) );
}
}
@RequiresDialectFeature(

View File

@ -11,6 +11,7 @@ import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.hibernate.QueryException;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.hql.internal.ast.QuerySyntaxException;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
@ -80,7 +81,7 @@ public class JpaFunctionTest extends BaseEntityManagerFunctionalTestCase {
} );
}
catch ( Exception e ) {
assertEquals( QuerySyntaxException.class, e.getCause().getClass() );
assertEquals( QueryException.class, e.getCause().getClass() );
}
}