From 98f74379c7da9ccbb44762888067d8f5a9474786 Mon Sep 17 00:00:00 2001 From: Berk Koprucu Date: Sun, 8 Dec 2024 17:36:03 +0100 Subject: [PATCH] Fail on WrappedCheckedException constructor validation before calling super --- .../cowwoc/pouch/core/WrappedCheckedException.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/github/cowwoc/pouch/core/WrappedCheckedException.java b/core/src/main/java/com/github/cowwoc/pouch/core/WrappedCheckedException.java index ff0bfb8..f42e582 100644 --- a/core/src/main/java/com/github/cowwoc/pouch/core/WrappedCheckedException.java +++ b/core/src/main/java/com/github/cowwoc/pouch/core/WrappedCheckedException.java @@ -4,6 +4,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; +import static java.util.Objects.requireNonNull; /** * A runtime exception dedicated to wrapping checked exceptions. @@ -21,11 +22,8 @@ public final class WrappedCheckedException extends RuntimeException */ private WrappedCheckedException(String message, Throwable cause) { - super(message, cause); - if (message == null) - throw new NullPointerException("message may not be null"); - if (cause == null) - throw new NullPointerException("cause may not be null"); + super(requireNonNull(message, "message cannot be null"), + requireNonNull(cause, "cause cannot be null")); } /** @@ -36,9 +34,7 @@ private WrappedCheckedException(String message, Throwable cause) */ private WrappedCheckedException(Throwable cause) { - super(cause); - if (cause == null) - throw new NullPointerException("cause may not be null"); + super(requireNonNull(cause, "cause cannot be null")); } /**