Sep 14, 2010

Unlimited unbinding loop when using ObjectId

Just got the following error in my play templates:

RuntimeException occured : java.lang.StackOverflowError

play.exceptions.JavaExecutionException: java.lang.StackOverflowError
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:285)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.RuntimeException: java.lang.StackOverflowError
at play.templates.BaseTemplate.throwException(BaseTemplate.java:91)
at play.templates.GroovyTemplate.render(GroovyTemplate.java:226)
at play.mvc.results.RenderTemplate.(RenderTemplate.java:23)
at play.mvc.Controller.renderTemplate(Controller.java:568)
at play.mvc.Controller.renderTemplate(Controller.java:553)
at play.mvc.Controller.render(Controller.java:597)
at controllers.CKBoxes.index(CKBoxes.java:31)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:408)

at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:403)

at play.mvc.ActionInvoker.invoke(ActionInvoker.java:176)
... 1 more
Caused by: java.lang.StackOverflowError
at java.lang.Class.privateGetDeclaredFields(Class.java:2278)
at java.lang.Class.getDeclaredFields(Class.java:1743)
at play.data.binding.Unbinder.unBind(Unbinder.java:51)
at play.data.binding.Unbinder.unBind(Unbinder.java:57)
at play.data.binding.Unbinder.unBind(Unbinder.java:57)
...

The problem happens when Unbinder tries to unbind a static field called _nextInc of type org.bson.types.ObjectId:

private static AtomicInteger _nextInc

In AtomicInteger there is a reference to sun.misc.Unsafe which in turn refer to a field with the same type: sun.misc.Unsafe

So what should be the solution? Here are what comes in my mind at the moment:
1. Unbinder do not try to unbind a static field ?
2. Some mechanism should be implemented in Unbinder to prevent endless unbinding loop like this case

As a temporary workaround I add ".toString()" to explicitly get String represent of ObjectId object:

original: #{a @{edit(_.id)}edit{/#}
workaround: #{a @{edit(_.id.toString())}edit{/#}

No comments: