[
https://issues.apache.org/jira/browse/CSV-269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17264418#comment-17264418
]
Gary D. Gregory commented on CSV-269:
-------------------------------------
Thank you for your report. Feel free to provide PR on GitHub with a unit test.
> CSVRecord.get(Enum) should use Enum.name() instead of Enum.toString()
> ---------------------------------------------------------------------
>
> Key: CSV-269
> URL: https://issues.apache.org/jira/browse/CSV-269
> Project: Commons CSV
> Issue Type: Bug
> Components: Parser
> Affects Versions: 1.8
> Reporter: Auke te Winkel
> Priority: Minor
>
> 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:
> {code:java}
> public String get(final Enum<?> e) {
> return get(Objects.toString(e, null));
> }
> {code}
> 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
> {code:java}
> java.lang.IllegalArgumentException: Mapping for [toString value] not found,
> expected one of [enum names]
> {code}
> Please change this method to use the enum name instead of toString.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)