diff --git a/util/src/main/java/io/kubernetes/client/Exec.java b/util/src/main/java/io/kubernetes/client/Exec.java index 35d1c764aa..1a94a31593 100644 --- a/util/src/main/java/io/kubernetes/client/Exec.java +++ b/util/src/main/java/io/kubernetes/client/Exec.java @@ -39,6 +39,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; @@ -359,9 +360,9 @@ public final class ExecutionBuilder { private Consumer onUnhandledError; private ExecutionBuilder(String namespace, String name, String[] command) { - this.namespace = namespace; - this.name = name; - this.command = command; + this.namespace = Objects.requireNonNull(namespace, "namespace"); + this.name = Objects.requireNonNull(name, "name"); + this.command = Objects.requireNonNull(command, "command"); this.stdin = true; this.stdout = true; this.stderr = true; diff --git a/util/src/test/java/io/kubernetes/client/ExecTest.java b/util/src/test/java/io/kubernetes/client/ExecTest.java index 8f09534a1f..7293f88d6d 100644 --- a/util/src/test/java/io/kubernetes/client/ExecTest.java +++ b/util/src/test/java/io/kubernetes/client/ExecTest.java @@ -19,6 +19,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -281,4 +282,18 @@ public void testNonZeroBadIntExit() { int exitCode = Exec.parseExitCode(client, inputStream); assertEquals(-1, exitCode); } + + @Test + public void testExecutionBuilderNull() { + Exec exec = new Exec(null); + assertThrows(NullPointerException.class, () -> { + exec.newExecutionBuilder(null, null, null); + }); + assertThrows(NullPointerException.class, () -> { + exec.newExecutionBuilder("", null, null); + }); + assertThrows(NullPointerException.class, () -> { + exec.newExecutionBuilder("", "", null); + }); + } }