You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Jeanette Winzenburg (JIRA)" <ji...@apache.org> on 2013/09/18 15:07:51 UTC

[jira] [Updated] (CSV-100) CSVParser: getHeaderMap throws NPE

     [ https://issues.apache.org/jira/browse/CSV-100?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jeanette Winzenburg updated CSV-100:
------------------------------------

    Description: 
title nearly says it all :-) 

Given a CSVParser parser, the following line throws an NPE:

{code}
Map<String, Integer> header = parser.getHeaderMap();
{code}

Stacktrace: 

{noformat}
Caused by: java.lang.NullPointerException
at java.util.HashMap.<init>(HashMap.java:318)
at java.util.LinkedHashMap.<init>(LinkedHashMap.java:212)
at org.apache.commons.csv.CSVParser.getHeaderMap(CSVParser.java:288)
{noformat}

happens if the format doesn't have a headerMap.

to fix, check if the parser's headerMap is null before trying to create the returned map:

{code}
public Map<String, Integer> getHeaderMap() {
    return this.headerMap != null ?
       new LinkedHashMap<String, Integer>(this.headerMap)
       : null;
}

{code}


  was:
title nearly says it all :-) 

Given a CSVParser parser, the following line throws an NPE:

{code}
Map<String, Integer> header = parser.getHeaderMap();
{code}

Stacktrace: 

{noformat}
Caused by: java.lang.NullPointerException
at java.util.HashMap.<init>(HashMap.java:318)
at java.util.LinkedHashMap.<init>(LinkedHashMap.java:212)
at org.apache.commons.csv.CSVParser.getHeaderMap(CSVParser.java:288)
{noformat}

happens if the format doesn't have a headerMap.




    
> CSVParser: getHeaderMap throws NPE 
> -----------------------------------
>
>                 Key: CSV-100
>                 URL: https://issues.apache.org/jira/browse/CSV-100
>             Project: Commons CSV
>          Issue Type: Bug
>          Components: Parser
>         Environment: commons-cvs version is the git-clone of current trunk
>            Reporter: Jeanette Winzenburg
>              Labels: csvparser
>
> title nearly says it all :-) 
> Given a CSVParser parser, the following line throws an NPE:
> {code}
> Map<String, Integer> header = parser.getHeaderMap();
> {code}
> Stacktrace: 
> {noformat}
> Caused by: java.lang.NullPointerException
> at java.util.HashMap.<init>(HashMap.java:318)
> at java.util.LinkedHashMap.<init>(LinkedHashMap.java:212)
> at org.apache.commons.csv.CSVParser.getHeaderMap(CSVParser.java:288)
> {noformat}
> happens if the format doesn't have a headerMap.
> to fix, check if the parser's headerMap is null before trying to create the returned map:
> {code}
> public Map<String, Integer> getHeaderMap() {
>     return this.headerMap != null ?
>        new LinkedHashMap<String, Integer>(this.headerMap)
>        : null;
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira