Wednesday, October 24, 2012

NullPointerException when saving Grails object

Recently I got very strange NPE while saving updated entity in Grails application:

 at com.test.MyController$_closure5.doCall(MyController.groovy:69)
 at com.test.MyController$_closure5.doCall(MyController.groovy)
 at net.bull.javamelody.JspWrapper.invoke(
 at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(
 at $Proxy49.forward(Unknown Source)
 at net.bull.javamelody.MonitoringFilter.doFilter(
 at net.bull.javamelody.MonitoringFilter.doFilter(

All I was doing on line 69 was just calling save() method, object obviously was not null, all fields and dependencies too. Even more - saving another object from same method was perfectly fine, but not one particular.
Finally, I got the reason - object had null in it's version field. Obviously migration was not done properly or it was manually created object in bad schema, but setting version solved my problem easily, but bad error reporting - didn't helped.


  1. I have this exception in a similar situation

  2. thank you for sharing this information.