diff --git a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java index c98b5ed36..d1460b81f 100644 --- a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java +++ b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java @@ -641,7 +641,7 @@ public class ExceptionUtils { * @since 3.13.0 */ public static boolean isUnchecked(final Throwable throwable) { - return !isChecked(throwable); + return throwable != null && (throwable instanceof Error || throwable instanceof RuntimeException); } /** diff --git a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java index 956a72390..c103345ff 100644 --- a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java @@ -635,6 +635,11 @@ public class ExceptionUtilsTest extends AbstractLangTest { assertTrue(ExceptionUtils.isChecked(new TestThrowable())); } + @Test + public void testIsUnchecked_null() { + assertFalse(ExceptionUtils.isUnchecked(null)); + } + @Test public void testIsUnchecked_checked() { assertFalse(ExceptionUtils.isUnchecked(new IOException()));