@@ -1562,6 +1562,41 @@ public void testTrim() throws Exception {
15621562 assertEquals (3 , record .size ());
15631563 }}
15641564
1565+ @ Test
1566+ public void testParsingPrintedEmptyFirstColumn () throws Exception {
1567+ String [][] lines = new String [][] {
1568+ {"a" , "b" },
1569+ {"" , "x" }
1570+ };
1571+ Exception firstException = null ;
1572+ for (CSVFormat .Predefined format : CSVFormat .Predefined .values ()) {
1573+ try {
1574+ StringWriter buf = new StringWriter ();
1575+ try (CSVPrinter printer = new CSVPrinter (buf , format .getFormat ())) {
1576+ for (String [] line : lines ) {
1577+ printer .printRecord ((Object []) line );
1578+ }
1579+ }
1580+ try (CSVParser csvRecords = new CSVParser (new StringReader (buf .toString ()), format .getFormat ())) {
1581+ for (String [] line : lines ) {
1582+ assertArrayEquals (line , csvRecords .nextRecord ().values ());
1583+ }
1584+ assertNull (csvRecords .nextRecord ());
1585+ }
1586+ } catch (Exception | Error e ) {
1587+ Exception detailedException = new RuntimeException ("format: " + format , e );
1588+ if (firstException == null ) {
1589+ firstException = detailedException ;
1590+ } else {
1591+ firstException .addSuppressed (detailedException );
1592+ }
1593+ }
1594+ }
1595+
1596+ if (firstException != null )
1597+ throw firstException ;
1598+ }
1599+
15651600 private void validateLineNumbers (final String lineSeparator ) throws IOException {
15661601 try (final CSVParser parser = CSVParser .parse ("a" + lineSeparator + "b" + lineSeparator + "c" , CSVFormat .DEFAULT .withRecordSeparator (lineSeparator ))) {
15671602 assertEquals (0 , parser .getCurrentLineNumber ());
0 commit comments