Throwable (@NotNull Throwable throwable, @NotNull Class<? extends Throwable> classToUnwrap) { while (classToUnwrap.isInstance(throwable) && throwable.getCause() != null && throwable.getCause() != throwable) { throwable = throwable.getCause(); } return throwable; }