Skip to content

Commit

Permalink
Merge pull request #3081 from pingpingy1/master
Browse files Browse the repository at this point in the history
Add null guards for Exec.ExecutionBuilder
  • Loading branch information
k8s-ci-robot authored Feb 15, 2024
2 parents e5f5821 + 017a6d2 commit 55c479d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions util/src/main/java/io/kubernetes/client/Exec.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -359,9 +360,9 @@ public final class ExecutionBuilder {
private Consumer<Throwable> 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;
Expand Down
15 changes: 15 additions & 0 deletions util/src/test/java/io/kubernetes/client/ExecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
}
}

0 comments on commit 55c479d

Please sign in to comment.