Grails
  1. Grails
  2. GRAILS-8672

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 Scott 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 Scott 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.
        Hide
        James Kleeh added a comment -

        I just ran into this issue - Grails 2.1

        Show
        James Kleeh added a comment - I just ran into this issue - Grails 2.1

          People

          • Assignee:
            Jeff Scott Brown
            Reporter:
            Jaroslav Kostal
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development