LA(0) is undefined

Description

method weakKeywords() in org.hibernate.hql.ast.HqlParser.java has:

if (LA(0) == FROM && t != IDENT && LA(2) == DOT) {
...
}

According to a posting on the antlr mailing list [see "LT(0) Specification" posted 1 July 2006],
LA and LT are defined only for i > 0. Examining the code supports this assertion. Also these
methods are documented as "lookahead" not "lookbehind". LT(0) can return NULL and then LA(0)
will throw a NullPointerException as shown:

java.lang.NullPointerException
at antlr.TokenBuffer.LA(TokenBuffer.java:81)
at antlr.LLkParser.LA(LLkParser.java:52)
at org.hibernate.hql.ast.HqlParser.weakKeywords(HqlParser.java:296)
at org.hibernate.hql.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2366)
at org.hibernate.hql.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2331)
at org.hibernate.hql.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2296)
at org.hibernate.hql.antlr.HqlBaseParser.expression(HqlBaseParser.java:2082)
at org.hibernate.hql.antlr.HqlBaseParser.compoundExpr(HqlBaseParser.java:2991)
at org.hibernate.hql.antlr.HqlBaseParser.inList(HqlBaseParser.java:2858)
at org.hibernate.hql.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2720)
at org.hibernate.hql.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2449)
at org.hibernate.hql.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2413)
at org.hibernate.hql.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2331)
at org.hibernate.hql.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2296)
at org.hibernate.hql.antlr.HqlBaseParser.expression(HqlBaseParser.java:2082)
at org.hibernate.hql.antlr.HqlBaseParser.logicalExpression(HqlBaseParser.java:1858)
at org.hibernate.hql.antlr.HqlBaseParser.whereClause(HqlBaseParser.java:454)
at org.hibernate.hql.antlr.HqlBaseParser.updateStatement(HqlBaseParser.java:224)
at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:142)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:238)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:155)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:134)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:113)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1602)
at com.timestock.tess.util.DbUtils.saveUpdatedUsers(DbUtils.java:38)
at com.timestock.tess.services.collectors.StatsCollector$StatisticsCollector.run(StatsCollector.java:602)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)

Environment

Hibernate 3.1.2 Postgres 8.1.2

Activity

Show:
Brian Cox
July 17, 2006, 10:45 PM

Further investigation shows that one way this can happen is after the TokenQueue.expand() method has been called.
The new queue elements will be NULL; therefore, LT(0) will return NULL and LA(0) will throw a NullPtrExcp.

Brett Meyer
December 18, 2013, 8:28 PM

If this is still an issue on ORM 4.2 or 4.3, anyone have a test case to attach?

Brett Meyer
December 19, 2013, 10:31 PM

Note: In an attempt to clean up the HHH JIRA, we will be rejecting any ticket that sits in the "Awaiting Test Case" state for 2-3 months with no response. So, if this issue is critical to you, please attach a reproducing test case ASAP. Thanks!

Brett Meyer
March 3, 2014, 3:40 PM

Bulk rejecting issues lacking a test case or recent response.

Rejected

Assignee

Unassigned

Reporter

Brian Cox

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure