!983 不使用Apache-Commons-Lang3的获取最尾端异常,采用递归方式

Merge pull request !983 from 墨石/v6-dev
This commit is contained in:
Looly 2023-05-03 12:55:03 +00:00 committed by Gitee
commit 867ae94b74
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -416,16 +416,17 @@ public class ExceptionUtil {
* 此方法通过调用{@link Throwable#getCause()} 直到没有cause为止如果异常本身没有cause返回异常本身<br>
* 传入null返回也为null
*
* <p>
* 此方法来自Apache-Commons-Lang3
* </p>
*
* @param throwable 异常对象可能为null
* @return 最尾端异常传入null参数返回也为null
*/
public static Throwable getRootCause(final Throwable throwable) {
final List<Throwable> list = getThrowableList(throwable);
return list.size() < 1 ? null : list.get(list.size() - 1);
Throwable cause = throwable.getCause();
if (cause != null) {
return getRootCause(cause);
}else{
return throwable;
}
}
/**