Uploaded image for project: 'Commons CSV'
  1. Commons CSV
  2. CSV-100

CSVParser: getHeaderMap throws NPE

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0
    • Component/s: Parser
    • Labels:
    • Environment:

      commons-cvs version is the git-clone of current trunk

      Description

      title nearly says it all

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

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

      Stacktrace:

      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)
      

      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:

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

        Attachments

          Activity

            People

            • Assignee:
              garydgregory Gary Gregory
              Reporter:
              kleopatra Jeanette Winzenburg
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: