Skip to content

Commit 73cc524

Browse files
committed
[CSV-106] CSVFormat.format always append null.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1577011 13f79535-47bb-0310-9956-ffa450edef68
1 parent bf8f23c commit 73cc524

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/main/java/org/apache/commons/csv/CSVPrinter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,10 @@ public void printComment(final String comment) throws IOException {
321321
* If an I/O error occurs
322322
*/
323323
public void println() throws IOException {
324-
out.append(format.getRecordSeparator());
324+
final String recordSeparator = format.getRecordSeparator();
325+
if (recordSeparator != null) {
326+
out.append(recordSeparator);
327+
}
325328
newRecord = true;
326329
}
327330

src/test/java/org/apache/commons/csv/CSVFormatTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static CSVFormat copy(final CSVFormat format) {
5555
public void testDelimiterSameAsCommentStartThrowsException() {
5656
CSVFormat.DEFAULT.withDelimiter('!').withCommentStart('!').validate();
5757
}
58-
58+
5959
@Test(expected = IllegalStateException.class)
6060
public void testDelimiterSameAsEscapeThrowsException() {
6161
CSVFormat.DEFAULT.withDelimiter('!').withEscape('!').validate();
@@ -229,6 +229,14 @@ public void testGetHeader() throws Exception {
229229
assertNotSame(formatWithHeader.getHeader(), headerCopy);
230230
}
231231

232+
@Test
233+
public void testNullRecordSeparatorCsv106() {
234+
final CSVFormat format = CSVFormat.newFormat(';').withSkipHeaderRecord(true).withHeader("H1", "H2");
235+
final String formatStr = format.format("A", "B");
236+
assertNotNull(formatStr);
237+
assertFalse(formatStr.endsWith("null"));
238+
}
239+
232240
@Test(expected = IllegalStateException.class)
233241
public void testQuoteCharSameAsCommentStartThrowsException() {
234242
CSVFormat.DEFAULT.withQuoteChar('!').withCommentStart('!').validate();

0 commit comments

Comments
 (0)