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

CSVRecord.get(Enum) should use Enum.name() instead of Enum.toString()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.8
    • 1.10.0
    • Parser
    • None

    Description

      I updated from 1.7 to 1.8 which breaks retrieving a value from CSVRecord using an Enum.

      It is caused by this piece of code:

      public String get(final Enum<?> e) {
          return get(Objects.toString(e, null));
      }
      

      This now uses Enum.toString() instead of Enum.name(). This works so long as the toString() method of the enum class has not been overridden. However, whereas Enum.name() is final and returns the correct value for this use case, toString() may be overridden to provide a human friendly desciption of the enum value.

      If the toString() method of the enum class is non-default, this results in

      java.lang.IllegalArgumentException: Mapping for [toString value] not found, expected one of [enum names]
      

      Please change this method to use the enum name instead of toString.

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            auke.tewinkel Auke te Winkel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: