Fix handling of empty/null arguments

See gh-9916
pull/10338/merge
Björn 7 years ago committed by Stephane Nicoll
parent 0e46d0f586
commit 0867ac5777

@ -21,6 +21,8 @@ import java.util.LinkedList;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.springframework.util.StringUtils;
/**
* Parse and expose arguments specified in a single string.
*
@ -31,14 +33,16 @@ class RunArguments {
private static final String[] NO_ARGS = {};
private final LinkedList<String> args;
private final LinkedList<String> args = new LinkedList<>();
RunArguments(String arguments) {
this(parseArgs(arguments));
}
RunArguments(String[] args) {
this.args = new LinkedList<>(Arrays.asList(args));
if (args != null) {
Arrays.stream(args).filter(StringUtils::hasLength).forEach(this.args::add);
}
}
public LinkedList<String> getArgs() {

@ -34,6 +34,20 @@ public class RunArgumentsTests {
assertThat(args.length).isEqualTo(0);
}
@Test
public void parseNullArray() {
String[] args = new RunArguments((String[]) null).asArray();
assertThat(args).isNotNull();
assertThat(args.length).isEqualTo(0);
}
@Test
public void parseArrayContainingNullValue() {
String[] args = new RunArguments(new String[]{null}).asArray();
assertThat(args).isNotNull();
assertThat(args.length).isEqualTo(0);
}
@Test
public void parseEmpty() {
String[] args = parseArgs(" ");

Loading…
Cancel
Save