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

CSVParser: getHeaderMap throws NPE

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.0
    • Parser
    • 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

            ggregory Gary D. Gregory
            kleopatra Jeanette Winzenburg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: