HHH-11942 - ANTLR parser should fail when providing an extra parenthesis
This commit is contained in:
parent
e9cc8867af
commit
5feff3b2c6
|
@ -274,22 +274,27 @@ public class QueryTranslatorImpl implements FilterTranslator {
|
|||
return w;
|
||||
}
|
||||
|
||||
private HqlParser parse(boolean filter) throws TokenStreamException, RecognitionException {
|
||||
private HqlParser parse(boolean filter) throws TokenStreamException {
|
||||
// Parse the query string into an HQL AST.
|
||||
final HqlParser parser = HqlParser.getInstance( hql );
|
||||
parser.setFilter( filter );
|
||||
|
||||
LOG.debugf( "parse() - HQL: %s", hql );
|
||||
parser.statement();
|
||||
try {
|
||||
parser.statement();
|
||||
}
|
||||
catch (RecognitionException e) {
|
||||
throw new HibernateException( "Unexpected error parsing HQL", e );
|
||||
}
|
||||
|
||||
final AST hqlAst = parser.getAST();
|
||||
parser.getParseErrorHandler().throwQueryException();
|
||||
|
||||
final NodeTraverser walker = new NodeTraverser( new JavaConstantConverter( factory ) );
|
||||
walker.traverseDepthFirst( hqlAst );
|
||||
|
||||
showHqlAst( hqlAst );
|
||||
|
||||
parser.getParseErrorHandler().throwQueryException();
|
||||
return parser;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.hibernate.dialect.SybaseAnywhereDialect;
|
|||
import org.hibernate.dialect.SybaseDialect;
|
||||
import org.hibernate.dialect.TeradataDialect;
|
||||
import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory;
|
||||
import org.hibernate.hql.internal.ast.QuerySyntaxException;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.loader.MultipleBagFetchException;
|
||||
import org.hibernate.persister.entity.DiscriminatorType;
|
||||
|
@ -77,6 +78,7 @@ import org.junit.Test;
|
|||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
@ -85,6 +87,7 @@ import static org.junit.Assert.assertFalse;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
@ -3797,11 +3800,13 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
"order by a.description ", Product.class)
|
||||
.setParameter( "description", "desc" )
|
||||
.getResultList();
|
||||
fail("Should have thrown exception");
|
||||
} );
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
QueryException rootCause = (QueryException) e.getCause();
|
||||
assertTrue( rootCause.getMessage().startsWith( "node to traverse cannot be null!" ) );
|
||||
final Throwable cause = e.getCause();
|
||||
assertThat( cause, instanceOf( QuerySyntaxException.class ) );
|
||||
assertTrue( cause.getMessage().contains( "expecting EOF, found ')'" ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ 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;
|
||||
|
@ -81,7 +80,7 @@ public class JpaFunctionTest extends BaseEntityManagerFunctionalTestCase {
|
|||
} );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
assertEquals( QueryException.class, e.getCause().getClass() );
|
||||
assertEquals( QuerySyntaxException.class, e.getCause().getClass() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue