You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Kenneth Gendron (JIRA)" <ji...@apache.org> on 2016/02/26 21:33:18 UTC

[jira] [Created] (GROOVY-7770) StackTraceUtils.deepSanitize will spin indefinitely on circular exceptions

Kenneth Gendron created GROOVY-7770:
---------------------------------------

             Summary: StackTraceUtils.deepSanitize will spin indefinitely on circular exceptions
                 Key: GROOVY-7770
                 URL: https://issues.apache.org/jira/browse/GROOVY-7770
             Project: Groovy
          Issue Type: Bug
          Components: groovy-runtime
    Affects Versions: 2.4.6
            Reporter: Kenneth Gendron


If a circular exception is given to StackTraceUtils.deepSanitize, Groovy will spin indefinitely trying to sanitize each exception recursively.
{code}
        Exception e1 = new Exception();
        Exception e2 = new Exception(e1);
        e1.initCause(e2);
        StackTraceUtils.deepSanitize(e1);
{code}
I have circumvented this in my code by writing my own sanitize routine:
{code}
    public static <T extends Throwable> T deepSanitize(T throwable) {
        StackTraceUtils.sanitize(throwable);
        Throwable cause = throwable.getCause();
        Throwable[] suppressed = throwable.getSuppressed();
        if (cause!=null || suppressed.length!=0) {
            IdentityHashMap<Throwable, Boolean> map = new IdentityHashMap<>();
            map.put(throwable, Boolean.TRUE);
            sanitizeThrowable(cause, suppressed, map);
        }
        return throwable;
    }
    private static void sanitizeThrowable(Throwable cause, Throwable[] suppressed, IdentityHashMap<Throwable, Boolean> map) {
        for (Throwable t : suppressed) {
            if (map.put(t, Boolean.TRUE)==null) {
                StackTraceUtils.sanitize(t);
                sanitizeThrowable(t.getCause(), t.getSuppressed(), map);
            }
        }
        if (cause!=null && map.put(cause, Boolean.TRUE)==null) {
            StackTraceUtils.sanitize(cause);
            sanitizeThrowable(cause.getCause(), cause.getSuppressed(), map);
        }
    }
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)