diff --git a/src/main/java/com/google/devtools/common/options/Converters.java b/src/main/java/com/google/devtools/common/options/Converters.java index 56bc63c2a4b272..15e8b479db0b29 100644 --- a/src/main/java/com/google/devtools/common/options/Converters.java +++ b/src/main/java/com/google/devtools/common/options/Converters.java @@ -250,8 +250,8 @@ static String joinEnglishList(Iterable choices) { return buf.length() == 0 ? "nothing" : buf.toString(); } - public static class SeparatedOptionListConverter implements Converter> { - + /** Converter for a list of options, separated by some separator character. */ + public static class SeparatedOptionListConverter implements Converter> { private final String separatorDescription; private final Splitter splitter; private final boolean allowEmptyValues; @@ -264,8 +264,8 @@ protected SeparatedOptionListConverter( } @Override - public List convert(String input) throws OptionsParsingException { - List result = + public ImmutableList convert(String input) throws OptionsParsingException { + ImmutableList result = input.isEmpty() ? ImmutableList.of() : ImmutableList.copyOf(splitter.split(input)); if (!allowEmptyValues && result.contains("")) { // If the list contains exactly the empty string, it means an empty value was passed and we diff --git a/src/test/java/com/google/devtools/common/options/CommaSeparatedOptionListConverterTest.java b/src/test/java/com/google/devtools/common/options/CommaSeparatedOptionListConverterTest.java index 25651ecbfc0ed4..78fe9c0089cc8d 100644 --- a/src/test/java/com/google/devtools/common/options/CommaSeparatedOptionListConverterTest.java +++ b/src/test/java/com/google/devtools/common/options/CommaSeparatedOptionListConverterTest.java @@ -14,9 +14,8 @@ package com.google.devtools.common.options; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; -import java.util.List; +import com.google.common.collect.ImmutableList; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -24,8 +23,7 @@ /** A test for {@link Converters.CommaSeparatedOptionListConverter}. */ @RunWith(JUnit4.class) public class CommaSeparatedOptionListConverterTest { - - private Converter> converter = + private final Converter> converter = new Converters.CommaSeparatedOptionListConverter(); @Test @@ -65,13 +63,4 @@ public void multiWords() throws Exception { public void spaceIsIgnored() throws Exception { assertThat(converter.convert("one two three")).containsExactly("one two three"); } - - @Test - public void valueisUnmodifiable() throws Exception { - assertThrows( - "could modify value", - UnsupportedOperationException.class, - () -> converter.convert("value").add("other")); - } - }