Grails sanitized stracktraces
The other day I was writing a medium complex HQL query for a Grails App and no matter what the line executing the query would crash like this:
java.lang.NullPointerException at $Proxy13.createQuery(Unknown Source) at com.acme.PerformanceService.makePerformanceSheet(PerformanceService.groovy:38) ... |
So how the hell do we figure out what the problem given so few information? Turns out that grails sanitizes the exception stacktrace, resulting in better readability by removing a lot of clutter. Sometimes though this optimization will also hide some important details from you. Luckily we can still refer to stacktrace.log which usually resides in the project root folder in development mode. In this particular case opening the file reveiled this:
java.lang.NullPointerException at org.hibernate.dialect.Dialect$3.getReturnType(Dialect.java:125) at org.hibernate.hql.ast.util.SessionFactoryHelper.findFunctionReturnType(SessionFactoryHelper.java:405) at org.hibernate.hql.ast.tree.AggregateNode.getDataType(AggregateNode.java:44) at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:165) at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:727) at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:551) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:645) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:251) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135) ... |
Which almost instantly gave me the hint that something’s wrong with the aggregate part of my query:
org.hibernate.hql.ast.tree.AggregateNode.getDataType |
And indeed the problem was that I had ported an SQL Query to HQL and forgot to rename the sum() aggregate argument from the column name to the domain class property name:
sum(some_property) instead of sum(foo.someProperty)


