Class CauseUnwrapper

java.lang.Object
io.opentelemetry.instrumentation.api.internal.CauseUnwrapper

public class CauseUnwrapper extends Object
A helper for safely walking a chain of Throwable causes.

Instrumentation frequently needs to unwrap wrapper exceptions (e.g. ExecutionException, framework-specific wrapper types) to find the underlying error. A naive loop or recursive method that follows Throwable.getCause() (or a similar library-specific accessor) until some stop condition is met can loop forever, or overflow the stack if written recursively, when a cause chain contains a cycle - which can happen with adversarial or buggy exceptions since nothing prevents Throwable.initCause(Throwable) from being used to create one. The helpers in this class detect such cycles using identity comparisons and stop unwrapping instead of looping.

This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.