commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Trejkaz (JIRA)" <>
Subject [jira] Commented: (SANDBOX-209) NullPointerException
Date Mon, 03 Mar 2008 00:13:50 GMT


Trejkaz commented on SANDBOX-209:

The following methods should throw NullPointerException or IllegalArgumentException if the
parameter itself is null, depending on your preference:
public void println(String[] values) {
public void println(String[][] values) {
public void printlnComment(String comment) {

The following two methods should behave similarly with null values:
public void println(String value) {
public void print(String value) {

(well, I guess println(String) just does print(String) followed by println()...)

I think leaving it completely empty is okay.  So for instance...
printer.println(new String[] { "1", null, "3" });

This would result in:

(I'll use 1,,3 and 1,"",3 to describe the two possible forms from here on.)

The issue comes down to how to distinguish null from "" when reading CSV back in.  Many people
have this problem with CSV in other systems and there is no good solution.  Some applications
say that 1,,3 is a null and 1,"",3 is "" but this isn't standardised at all.

You can test spreadsheet app behaviour by entering a single quote by itself to create a proper
empty string.  Excel's behaviour is to export both as 1,,3.  OpenOffice Calc appears to assume
that a single quote means a string which is the single quote (a bug, probably.)

So IMO, leaving both as empty is acceptable, and at least consistent with apps which do distinguish
between the two internally even if they don't export them in different ways.

Later, a new CSVStrategy parameter might be introduced, something like get/setQuoteEmptyStrings
-- assuming users actually need to distinguish between the two.  Personally when reading from
a CSV file I use StringUtils.isEmpty anyway, so whether it's null or "" doesn't matter to

As for ignoreEmptyLines, it's my belief that this should only apply to truly empty lines.
 If users insist on having a CSV file with a single column then yes, there is a risk of this
single column being null and thus empty, and thus generating a blank line.  On the other hand,
I don't think many users would be using a CSV library if their data is only in a single column
-- and two column data wouldn't have this issue as they should at the very least have a single
comma even if both cells are blank for a given row (both Excel and do it this

> NullPointerException
> --------------------
>                 Key: SANDBOX-209
>                 URL:
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: CSV
>    Affects Versions: Nightly Builds
>            Reporter: Andriy Sholokh
>             Fix For: Nightly Builds
> If
> public void print(String value) method of CSVPrinter class gets null parameter it throws

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message