title: Intermittent stack overflow errors with groovy jsonBuilder in Jenkins
body: <p>I am getting intermittent stack overflow errors using the groovy jsonBuilder with the groovy post build plugin in Jenkins.  I'd say that the code below works about 25% of the time and the other 75% fails.  Any ideas what could be causing this?  First part of the error is below. Thank you.</p>
  
  <pre><code>import groovy.json.*
  import hudson.model.*
  
  
  def projectName = manager.build.project.name
  def job = manager.hudson.instance.getItem(projectName)
  def scm = job.scm
  def rtcStream = scm.getStreamName()
  def rtcWorkspace = scm.getWorkspaceName()
  def duration = manager.build.getExecutor().getElapsedTime()
  def result = manager.build.result
  
  def json = new JsonBuilder()
  
  def root = json.build {
      build_number manager.build.number
      build_timestamp manager.build.timestamp
      build_duration duration
      build_url manager.build.url
      build_project_name projectName
      stream rtcStream
      workspace rtcWorkspace
      build_culprits manager.build.culprits
      build_result result.toString()
  }
  
  def jsonString = JsonOutput.prettyPrint(json.toString())
  manager.listener.logger.println jsonString
  
  def channel = manager.build.workspace.channel;
  
  def fp = new hudson.FilePath(channel, manager.build.workspace.toString() + "\\build.json")
  
  if(fp != null) {
      manager.listener.logger.println "Getting ready to write build.json"
      fp.write(jsonString, null); //writing to file
      manager.listener.logger.println "Done writing build.json"
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>FATAL: null
  java.lang.StackOverflowError
      at java.lang.reflect.InvocationTargetException.&lt;init&gt;(InvocationTargetException.java:72)
      at sun.reflect.GeneratedMethodAccessor5636.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:616)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:903)
      at groovy.lang.Closure.call(Closure.java:415)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.callClosureForMapEntry(DefaultGroovyMethods.java:3653)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:2379)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:2396)
      at org.codehaus.groovy.runtime.dgm$83.invoke(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at groovy.json.JsonOutput.toJson(JsonOutput.groovy:146)
      at groovy.json.JsonOutput$toJson.callStatic(Unknown Source)
      at groovy.json.JsonOutput.toJson(JsonOutput.groovy:138)
      at groovy.json.JsonOutput$toJson$3.callStatic(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:50)
      at groovy.json.JsonOutput$toJson$4.callStatic(Unknown Source)
      at groovy.json.JsonOutput$_toJson_closure2.doCall(JsonOutput.groovy:150)
      at sun.reflect.GeneratedMethodAccessor5636.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:616)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:903)
      at groovy.lang.Closure.call(Closure.java:415)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.callClosureForMapEntry(DefaultGroovyMethods.java:3653)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:2379)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:2396)
      at org.codehaus.groovy.runtime.dgm$83.invoke(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at groovy.json.JsonOutput.toJson(JsonOutput.groovy:146)
      at groovy.json.JsonOutput$toJson.callStatic(Unknown Source)
      at groovy.json.JsonOutput.toJson(JsonOutput.groovy:138)
      at groovy.json.JsonOutput$toJson$3.callStatic(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:50)
      at groovy.json.JsonOutput$toJson$4.callStatic(Unknown Source)
      at groovy.json.JsonOutput$_toJson_closure2.doCall(JsonOutput.groovy:150)
      at sun.reflect.GeneratedMethodAccessor5636.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:616)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:903)
      at groovy.lang.Closure.call(Closure.java:415)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.callClosureForMapEntry(DefaultGroovyMethods.java:3653)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:2379)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:2396)
      at org.codehaus.groovy.runtime.dgm$83.invoke(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at groovy.json.JsonOutput.toJson(JsonOutput.groovy:146)
      at groovy.json.JsonOutput$toJson.callStatic(Unknown Source)
      at groovy.json.JsonOutput.toJson(JsonOutput.groovy:138)
      at groovy.json.JsonOutput$toJson$3.callStatic(Unknown Source)
  </code></pre>
  
  <p>Output of the elements:</p>
  
  <pre><code>build num: 25
  timestamp: java.util.GregorianCalendar[time=1389797077000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="US/Eastern",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=US/Eastern,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2014,MONTH=0,WEEK_OF_YEAR=3,WEEK_OF_MONTH=3,DAY_OF_MONTH=15,DAY_OF_YEAR=15,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=9,HOUR_OF_DAY=9,MINUTE=44,SECOND=37,MILLISECOND=0,ZONE_OFFSET=-18000000,DST_OFFSET=0]
  duration: 317805
  url: job/Client_March_Report/25/
  project: Client_March_Report
  stream: Stream_Client_Development
  workspace: Jenkins_Client_Workspace
  culprits: []
  result: FAILURE
  </code></pre>