为什么在Groovy JsonBuilder尝试序列化Expando时会出现StackoverflowError?

时间:2013-01-18 20:19:01

标签: groovy expando jsonbuilder

当我尝试序列化Expando时,我收到了StackoverflowError(没有追溯到我的代码)。用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)
...

这应该可行吗?

1 个答案:

答案 0 :(得分:3)

哇..这是一个错误。看起来它是在1.8.8

引入的

适用于1.8.6:

groovy-1.8.6/bin/groovysh new groovy.json.JsonBuilder(new Expando(name:'hello')).toString();

===> {"name":"hello"}

StackoverflowError 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

看起来2.1.0rc1上存在一个错误:http://jira.codehaus.org/browse/GROOVY-5918