commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Bourg (Commented) (JIRA)" <>
Subject [jira] [Commented] (CSV-82) CSVRecord inconsistent behaviour when header mapping is not found
Date Mon, 26 Mar 2012 12:56:27 GMT


Emmanuel Bourg commented on CSV-82:

I don't find this inconsistent. There are two cases to handle:

# The header is missing and a field is accessed by name
# The header is present but the column name requested doesn't exist

In case 1 an IllegalStateException is thrown, because the expectation of the user is severely
broken. He attempts to access the fields by name which is completely impossible.

In case 2 a null value is returned, because some column may be optional. It's not reasonable
to throw an exception in this case, otherwise reading optional columns in a try catch block
will become very cumbersome.

If you want to differentiate between missing columns and null values this can be done with
a CSVRecord#has(String) method. But is it actually useful?

> CSVRecord inconsistent behaviour when header mapping is not found
> -----------------------------------------------------------------
>                 Key: CSV-82
>                 URL:
>             Project: Commons CSV
>          Issue Type: Bug
>            Reporter: Sebb
> The CSVRecord#get(String) method has inconsistent behaviour.
> If no header mapping was provided, then it throws IllegalStateException.
> If the header name is not found, null is returned.
> Apart from being inconsistent, it might be useful in the future to be able to return
null as a column value (as distinct from the empty string).
> It should throw IllegalArgumentException for a missing header name, instead of returning

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message