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 1 commit
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 @@ -18,6 +18,7 @@

import java.util.Arrays;
import java.util.LinkedList;
import java.util.stream.Collectors;

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

Expand All @@ -31,14 +32,17 @@ 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) {
this.args.addAll(Arrays.stream(args).filter(s -> s != null && !"".equals(s))
Copy link
Member

Choose a reason for hiding this comment

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

We could probably replace the filter with hasLength from org.springframework.util.StringUtils. A forEach might also be a bit more concise than the collector:

Arrays.stream(args).filter(StringUtils::hasLength).forEach(this.args::add);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that is a better solution,

.collect(Collectors.toList()));
}
}

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