public static Throwable getRootCause(Throwable t) {
        Throwable cause = null;
        Throwable parent = t.getCause();
        while (parent != null) {
            cause = parent;
            parent = parent.getCause();
        }
        return cause;
    }