Skip to content

Commit

Permalink
Merge pull request fabric8io#693 from chonton/master
Browse files Browse the repository at this point in the history
fix empty link causing NullPointerException
  • Loading branch information
rhuss authored Jan 24, 2017
2 parents 2eda669 + bc75a0a commit 272736d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/io/fabric8/maven/docker/util/EnvUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.maven.shared.utils.io.FileUtils;

import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -127,7 +128,8 @@ public static List<String> splitAtCommasAndTrim(Iterable<String> input) {
if(input==null) {
return Collections.emptyList();
}
return Lists.newArrayList(Iterables.concat(Iterables.transform(input, COMMA_SPLITTER)));
Iterable<String> nonEmptyInputs = Iterables.filter(input, Predicates.notNull());
return Lists.newArrayList(Iterables.concat(Iterables.transform(nonEmptyInputs, COMMA_SPLITTER)));
}

public static String[] splitOnSpaceWithEscape(String toSplit) {
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/io/fabric8/maven/docker/util/EnvUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ public void splitAtCommas() {
assertTrue(Iterables.elementsEqual(it, expected));
}

public void assertEmptyList(Iterable<String> actual) {
assertTrue(Iterables.elementsEqual(Collections.emptyList(), actual));
}
@Test
public void splitAtCommasEmpty() {
assertEmptyList(EnvUtil.splitAtCommasAndTrim(Collections.<String>emptyList()));
}

@Test
public void splitAtCommasSingleEmpty() {
assertEmptyList(EnvUtil.splitAtCommasAndTrim(Arrays.asList("")));
}

@Test
public void splitAtCommasNullList() {
assertEmptyList(EnvUtil.splitAtCommasAndTrim(null));
}

// null occurs when <links><link></link></links>
@Test
public void splitAtCommasNullInList() {
assertEmptyList(EnvUtil.splitAtCommasAndTrim(Collections.<String>singletonList(null)));
}

@Test
@TestCaseName("{method}: input \"{0}\" splits to {1}")
@Parameters
Expand Down

0 comments on commit 272736d

Please sign in to comment.