Check setDelimiter() for empty string

Signed-off-by: Mykola Faryma <m.faryma@partner.samsung.com>
This commit is contained in:
Mykola Faryma 2022-09-27 13:10:43 +03:00
parent 048d507de9
commit 1da75703a4
2 changed files with 8 additions and 0 deletions

View File

@ -346,6 +346,9 @@ public final class CSVFormat implements Serializable {
if (containsLineBreak(delimiter)) {
throw new IllegalArgumentException("The delimiter cannot be a line break");
}
if (delimiter.isEmpty()) {
throw new IllegalArgumentException("The delimiter cannot be empty");
}
this.delimiter = delimiter;
return this;
}

View File

@ -1569,4 +1569,9 @@ public class CSVFormatTest {
final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withSystemRecordSeparator();
assertEquals(System.lineSeparator(), formatWithRecordSeparator.getRecordSeparator());
}
@Test
public void testDelimiterEmptyStringThrowsException1() {
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter("").build());
}
}