Throwable (@NotNull Throwable e) { for (Throwable candidate = e; candidate != null; candidate = candidate.getCause()) { Class<? extends Throwable> clazz = candidate.getClass(); if (clazz != InvocationTargetException.class && clazz != UndeclaredThrowableException.class) { return candidate; } } return e; }