You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Andriy Sholokh (JIRA)" <ji...@apache.org> on 2008/02/06 15:19:21 UTC

[jira] Created: (SANDBOX-209) NullPointerException

NullPointerException
--------------------

                 Key: SANDBOX-209
                 URL: https://issues.apache.org/jira/browse/SANDBOX-209
             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 NullPointerException.

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


[jira] Updated: (SANDBOX-209) NullPointerException

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SANDBOX-209?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated SANDBOX-209:
----------------------------------

    Fix Version/s:     (was: Nightly Builds)
                   CSV 1.0

Need to get this right before a 1.0. Great comments from Trejkaz and the direction sounds worthwhile.

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

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


[jira] Commented: (SANDBOX-209) NullPointerException

Posted by "Trejkaz (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SANDBOX-209?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12574319#action_12574319 ] 

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:
1,,3

(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 me.

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 OpenOffice.org do it this way.)


> NullPointerException
> --------------------
>
>                 Key: SANDBOX-209
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-209
>             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 NullPointerException.

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


[jira] Updated: (SANDBOX-209) NullPointerException in CSVPrinter.print()/println()

Posted by "Dennis Lundberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SANDBOX-209?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dennis Lundberg updated SANDBOX-209:
------------------------------------

    Summary: NullPointerException in CSVPrinter.print()/println()  (was: NullPointerException)

> NullPointerException in CSVPrinter.print()/println()
> ----------------------------------------------------
>
>                 Key: SANDBOX-209
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-209
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: CSV
>    Affects Versions: Nightly Builds
>            Reporter: Andriy Sholokh
>             Fix For: CSV 1.0
>
>
> If
> public void print(String value) method of CSVPrinter class gets null parameter it throws NullPointerException.

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


[jira] Commented: (SANDBOX-209) NullPointerException

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SANDBOX-209?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12574081#action_12574081 ] 

Henri Yandell commented on SANDBOX-209:
---------------------------------------

So the API has:

  public void println(String value) {
  public void println() {
  public void println(String[] values) {
  public void println(String[][] values) {
  public void printlnComment(String comment) {
  public void print(String value) {

Question being; what should the null functionality be in each case. If you look at either System.out.println or StringWriter, it is to turn 'null' into "null". In the array cases, I guess it would be { "null" } and {{ "null" }}. Very lame.

So the other obvious solution would be to implement empty functionality. That still leaves an open question of whether that means nothing happens, or it's akin to an empty string. ie) in the println(null) case, would you expect a newline to be printed.

I'm thinking that can be up to the CSVStrategy.ignoreEmptyLines - if it's true, then null means nothing. If false then null means an empty string. Or is that bad because it's reusing a configuration option for something that is not necessarily symmetrical with the usage in the parser :)

> NullPointerException
> --------------------
>
>                 Key: SANDBOX-209
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-209
>             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 NullPointerException.

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