From 90b51c826d81aa52fc56609c3fce86e62bb94f34 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 810df68..09a6656 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 @@ -2,6 +2,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. @@ -19,11 +20,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")); } /** @@ -34,9 +32,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")); } /**