Skip to content

Commit 8351042

Browse files
committed
Polish "Fix handling of empty/null arguments"
Closes gh-9916
1 parent 0867ac5 commit 8351042

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunArguments.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818

1919
import java.util.Arrays;
2020
import java.util.LinkedList;
21+
import java.util.Objects;
2122

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

24-
import org.springframework.util.StringUtils;
25-
2625
/**
2726
* Parse and expose arguments specified in a single string.
2827
*
@@ -41,7 +40,7 @@ class RunArguments {
4140

4241
RunArguments(String[] args) {
4342
if (args != null) {
44-
Arrays.stream(args).filter(StringUtils::hasLength).forEach(this.args::add);
43+
Arrays.stream(args).filter(Objects::nonNull).forEach(this.args::add);
4544
}
4645
}
4746

spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/RunArgumentsTests.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,9 +43,16 @@ public void parseNullArray() {
4343

4444
@Test
4545
public void parseArrayContainingNullValue() {
46-
String[] args = new RunArguments(new String[]{null}).asArray();
46+
String[] args = new RunArguments(new String[]{"foo", null, "bar"}).asArray();
4747
assertThat(args).isNotNull();
48-
assertThat(args.length).isEqualTo(0);
48+
assertThat(args).containsOnly("foo", "bar");
49+
}
50+
51+
@Test
52+
public void parseArrayContainingEmptyValue() {
53+
String[] args = new RunArguments(new String[]{"foo", "", "bar"}).asArray();
54+
assertThat(args).isNotNull();
55+
assertThat(args).containsOnly("foo", "", "bar");
4956
}
5057

5158
@Test

0 commit comments

Comments
 (0)