You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2014/03/13 01:16:58 UTC
svn commit: r1577011 - in /commons/proper/csv/trunk/src:
main/java/org/apache/commons/csv/CSVPrinter.java
test/java/org/apache/commons/csv/CSVFormatTest.java
Author: ggregory
Date: Thu Mar 13 00:16:57 2014
New Revision: 1577011
URL: http://svn.apache.org/r1577011
Log:
[CSV-106] CSVFormat.format always append null.
Modified:
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java
commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java?rev=1577011&r1=1577010&r2=1577011&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVPrinter.java Thu Mar 13 00:16:57 2014
@@ -321,7 +321,10 @@ public final class CSVPrinter implements
* If an I/O error occurs
*/
public void println() throws IOException {
- out.append(format.getRecordSeparator());
+ final String recordSeparator = format.getRecordSeparator();
+ if (recordSeparator != null) {
+ out.append(recordSeparator);
+ }
newRecord = true;
}
Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java?rev=1577011&r1=1577010&r2=1577011&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java Thu Mar 13 00:16:57 2014
@@ -55,7 +55,7 @@ public class CSVFormatTest {
public void testDelimiterSameAsCommentStartThrowsException() {
CSVFormat.DEFAULT.withDelimiter('!').withCommentStart('!').validate();
}
-
+
@Test(expected = IllegalStateException.class)
public void testDelimiterSameAsEscapeThrowsException() {
CSVFormat.DEFAULT.withDelimiter('!').withEscape('!').validate();
@@ -229,6 +229,14 @@ public class CSVFormatTest {
assertNotSame(formatWithHeader.getHeader(), headerCopy);
}
+ @Test
+ public void testNullRecordSeparatorCsv106() {
+ final CSVFormat format = CSVFormat.newFormat(';').withSkipHeaderRecord(true).withHeader("H1", "H2");
+ final String formatStr = format.format("A", "B");
+ assertNotNull(formatStr);
+ assertFalse(formatStr.endsWith("null"));
+ }
+
@Test(expected = IllegalStateException.class)
public void testQuoteCharSameAsCommentStartThrowsException() {
CSVFormat.DEFAULT.withQuoteChar('!').withCommentStart('!').validate();