Skip to content

Fix to allow empty argument in maven plugin. Fixes gh-9713 #9916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import org.codehaus.plexus.util.cli.CommandLineUtils;

import org.springframework.util.StringUtils;

/**
* Parse and expose arguments specified in a single string.
*
Expand All @@ -31,14 +33,16 @@ class RunArguments {

private static final String[] NO_ARGS = {};

private final LinkedList<String> args;
private final LinkedList<String> args = new LinkedList<>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to initialize instance variables inside constructors instead of at the declaration level


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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ public void parseNull() {
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(" ");
Expand Down