Grails

NullPointerException with named query with null parameter

Details

  • Testcase included:
    yes

Description

Assume domain class with parametrized named query, e.g.:

class Book {
	Integer year
	static namedQueries = {
		ofYear { Integer year ->
			if (year) eq 'year', year
		}
	}
}

The following call:

Book.ofYear(2012).ofYear(null).list()

throws the NPE:

java.lang.NullPointerException
	at org.grails.datastore.gorm.query.NamedCriteriaProxy.getPreparedCriteriaClosure(NamedQueriesBuilder.groovy:212)
	at org.grails.datastore.gorm.query.NamedCriteriaProxy.invokeCriteriaClosure(NamedQueriesBuilder.groovy:77)
	at org.grails.datastore.gorm.query.NamedCriteriaProxy$_listInternal_closure1.doCall(NamedQueriesBuilder.groovy:85)
	at grails.gorm.CriteriaBuilder.invokeClosureNode(CriteriaBuilder.java:976)
	at grails.gorm.CriteriaBuilder.invokeMethod(CriteriaBuilder.java:301)
	at org.grails.datastore.gorm.GormStaticApi.withCriteria(GormStaticApi.groovy:261)
	at org.grails.datastore.gorm.query.NamedCriteriaProxy.listInternal(NamedQueriesBuilder.groovy:100)
	at org.grails.datastore.gorm.query.NamedCriteriaProxy.list(NamedQueriesBuilder.groovy:104)
	...

Check unit test for cases when null parameter works.

Activity

Hide
Jeff Brown added a comment -

This should be resolved as soon as we upgrade to Groovy 1.8.6. When we do that we should uncomment NamedCriteriaTests.testPassingNullToAChainedNamedQuery.

Show
Jeff Brown added a comment - This should be resolved as soon as we upgrade to Groovy 1.8.6. When we do that we should uncomment NamedCriteriaTests.testPassingNullToAChainedNamedQuery.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: