Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
1.4
-
None
-
None
-
Any.
Description
The function CSVFormat.format() trims off the last delimiter if the delimiter is a white space character and the value in the last column is null.
public String format(Object... values) { StringWriter out = new StringWriter(); try { (new CSVPrinter(out, this)).printRecord(values); return out.toString().trim(); } catch (IOException var4) { throw new IllegalStateException(var4); } }
For example, consider the following records (\t = tab)-
ID\tName\tCountry\tAge
1\tJohn Doe\tUSA\t20
2\tJane Doe\tUSA\t
The CSVFormat.format() on both the rows returns the following -
ID\tName\tCountry\tAge
1\tJohn Doe\tUSA\t20
2\tJane Doe\tUSA
Note that there is a missing delimiter for the last column in the second record.
This usually causes schema mismatch when we try and read back the CSV file as there is one less column in all the rows which have a null at the end.
I feel the trim() is unnecessary while returning out.toString()
Attachments
Issue Links
- links to