public static Throwable getCause()

in server-common/src/main/java/org/apache/cassandra/sidecar/common/server/utils/ThrowableUtils.java [188:223]


    public static Throwable getCause(Throwable throwable, Predicate<Throwable> predicate)
    {
        if (throwable == null)
        {
            return null;
        }
        Throwable cause = throwable;
        Throwable fastTracer = getCause(cause, 1);
        Throwable stop = null;
        // Keep on looking up the cause until hitting the end of the exception chain or finding the interested cause
        // It also detects whether there is a circular reference by applying fast and slow steppers.
        while (cause != null && stop != cause)
        {
            if (predicate.test(cause))
            {
                return cause;
            }

            if (stop == null)
            {
                // once stop is set; updating fast tracer is no longer required
                if (cause == fastTracer)
                {
                    // Mark the position to stop, and continue tracing the cause up until hitting stop the next time.
                    // This way we are sure that all exceptions/causes are visited at least once.
                    stop = cause;
                }
                else
                {
                    fastTracer = getCause(fastTracer, 2);
                }
            }
            cause = getCause(cause, 1);
        }
        return null;
    }