groovy

How do I print a Groovy stack trace?


How do I print a Groovy stack trace? The Java method, Thread.currentThread().getStackTrace() produces a huge stack trace, including a lot of the Groovy internals. I'm seeing a function called twice from a StreamingMarkupBuilder that looks like it should only be called once and I would like to see why Groovy thinks it should be calling it twice.


Solution

  • Solution:

    org.codehaus.groovy.runtime.StackTraceUtils.sanitize(new Exception()).printStackTrace()
    

    Original answer:

    A Google search returns the following information:

    Apparently, there is a method in org.codehaus.groovy.runtime.StackTraceUtils called printSanitizedStackTrace. There isn't much documentation for the method, though there is a method called sanitize which is described as

    remove all apparently groovy-internal trace entries from the exception instance This modifies the original instance and returns it, it does not clone

    So I would try org.codehaus.groovy.runtime.StackTraceUtils.printSanitizedStackTrace(Throwable t) (it is static) and see if that works for you.