Top Description Fields Constructors Methods
org.codehaus.groovy.runtime

public Class StackTraceUtils

extends Object
Class Inheritance
Imports
groovy.lang.Closure, org.apache.groovy.util.SystemUtil, org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation, java.io.PrintWriter, java.util.ArrayList, .Enumeration, .List, java.util.logging.Level, .LogManager, .Logger

Originally was grails.utils.GrailsUtils, removed some grails specific stuff. Utility methods removing internal lines from stack traces
Since
1.5

Field Summary

Modifier and TypeField and Description
private static final String[]
private static final Logger
public static final String
private static final List<Closure<V>>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
addClassTest(Closure<V>
the testing groovy.lang.Closure
test
)

Adds a groovy.lang.Closure to test whether the stack trace element should be added or not.

public static Throwable

Returns:

The root cause exception instances, with stack trace modified to filter out groovy runtime classes
deepSanitize
(Throwable
a throwable
t
)

Sanitize the exception and ALL nested causes

This will MODIFY the stacktrace of the exception instance and all its causes irreversibly

public static Throwable

Returns:

The deepest cause of the exception that can be found
extractRootCause
(Throwable
a Throwable
t
)

Extracts the root cause of the exception, no matter how nested it is

public static boolean
public static void
public static void
public static Throwable

Returns:

The original Throwable but with a sanitized stack trace
sanitize
(Throwable
the Throwable whose stack trace we want to sanitize
t
)

Remove all apparently groovy-internal trace entries from the exception instance

This modifies the original instance and returns it, it does not clone

public static Throwable

Returns:

The root cause exception instance, with its stace trace modified to filter out groovy runtime classes
sanitizeRootCause
(Throwable
a throwable
t
)

Get the root cause of an exception and sanitize it for display to the user

This will MODIFY the stacktrace of the root cause exception object and return it

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

GROOVY_PACKAGESback to summary
private static final String[] GROOVY_PACKAGES
STACK_LOGback to summary
private static final Logger STACK_LOG
STACK_LOG_NAMEback to summary
public static final String STACK_LOG_NAME
testsback to summary
private static final List<Closure<V>> tests

Constructor Detail

StackTraceUtilsback to summary
public StackTraceUtils()

Method Detail

addClassTestback to summary
public static void addClassTest(Closure<V> test)

Adds a groovy.lang.Closure to test whether the stack trace element should be added or not.

The groovy.lang.Closure will be given the class name as parameter. the return value decides if the element will be added or not.

  • true - trace element will be added to the trace
  • false - trace element will not be added to the trace
  • null - continue with next test
Groovy truth will be used to determine true and false, null is excluded from defaulting to false here. If all tests have been executed and all of them skipped, then the groovy standard filtering will take place.
Parameters
test:Closure<V>

the testing groovy.lang.Closure

deepSanitizeback to summary
public static Throwable deepSanitize(Throwable t)

Sanitize the exception and ALL nested causes

This will MODIFY the stacktrace of the exception instance and all its causes irreversibly

Parameters
t:Throwable

a throwable

Returns:Throwable

The root cause exception instances, with stack trace modified to filter out groovy runtime classes

extractRootCauseback to summary
public static Throwable extractRootCause(Throwable t)

Extracts the root cause of the exception, no matter how nested it is

Parameters
t:Throwable

a Throwable

Returns:Throwable

The deepest cause of the exception that can be found

isApplicationClassback to summary
public static boolean isApplicationClass(String className)
printSanitizedStackTraceback to summary
public static void printSanitizedStackTrace(Throwable t, PrintWriter p)
printSanitizedStackTraceback to summary
public static void printSanitizedStackTrace(Throwable t)
sanitizeback to summary
public static Throwable sanitize(Throwable t)

Remove all apparently groovy-internal trace entries from the exception instance

This modifies the original instance and returns it, it does not clone

Parameters
t:Throwable

the Throwable whose stack trace we want to sanitize

Returns:Throwable

The original Throwable but with a sanitized stack trace

sanitizeRootCauseback to summary
public static Throwable sanitizeRootCause(Throwable t)

Get the root cause of an exception and sanitize it for display to the user

This will MODIFY the stacktrace of the root cause exception object and return it

Parameters
t:Throwable

a throwable

Returns:Throwable

The root cause exception instance, with its stace trace modified to filter out groovy runtime classes