Skip to content

Commit

Permalink
[bugfix] Prevent null pointer exceptions in the commandRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
fsantiag committed May 3, 2019
1 parent 71f4d2c commit 586fd02
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.sonar.api.utils.log.Loggers;

import java.util.Arrays;
import java.util.Objects;

@ScannerSide
public class CommandRunner {
Expand All @@ -30,7 +31,7 @@ public CommandRunner() {
CommandStreamConsumer run(String command, CommandStreamConsumer stdout,
CommandStreamConsumer stderr, String... arguments) {
Command cmd = Command.create(command);
Arrays.stream(arguments).forEach(cmd::addArgument);
Arrays.stream(arguments).filter(Objects::nonNull).forEach(cmd::addArgument);

commandExecutor.execute(cmd, stdout, stderr, TIMEOUT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -37,13 +36,7 @@ public void setUp() {

@Test
public void shouldTakeMultipleArgumentsForCommand() {
doReturn(0).when(commandExecutor).execute(
any(),
any(),
any(),
anyLong());

commandRunner.run("echo", "argument1", "argument2");
commandRunner.run("echo", "argument1", null, "argument2");

ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
verify(commandExecutor, times(1))
Expand Down

0 comments on commit 586fd02

Please sign in to comment.