groovyexpandojsonbuilder

Why do I get a StackoverflowError on when Groovy JsonBuilder tries to serialize an Expando?


I am getting a StackoverflowError (not traced back to my code) when I try to serialize an Expando. Reproduced with groovy shell:

... groovy-2.0.6/bin/groovysh new groovy.json.JsonBuilder(new Expando(name:'hello')).toString()
FATAL: java.lang.StackOverflowError
java.lang.StackOverflowError
        at java.lang.Exception.<init>(Exception.java:77)
        at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:54)
        at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
...

This should work right?


Solution

  • Wow..It's a bug. Looks like it was introduced at 1.8.8

    works at 1.8.6:

    groovy-1.8.6/bin/groovysh new groovy.json.JsonBuilder(new Expando(name:'hello')).toString();
    
    ===> {"name":"hello"}
    

    StackoverflowError at 1.8.8:

    groovy-1.8.8/bin/groovysh new groovy.json.JsonBuilder(new Expando(name:'hello')).toString();
    FATAL: java.lang.StackOverflowError
    java.lang.StackOverflowError
    

    Looks like there is a bug filed on 2.1.0rc1: https://issues.apache.org/jira/browse/GROOVY-5918