[ 
https://issues.apache.org/jira/browse/CSV-300?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17577499#comment-17577499
 ] 

Alex Herbert commented on CSV-300:
----------------------------------

Is there any reason to wish to modify the list?

If the list is intended for read-only usage then array copies can be prevented 
in the ArrayList constructor by avoiding creating a new ArrayList and instead 
using:
{code:java}
public List<String> toList() {
    // Current bug
    // return Arrays.asList(values);

    // Suggested
    // return new ArrayList<>(Arrays.asList(values));

    // Immutable return
    return Collections.unmodifiableList(Arrays.asList(values));
}
{code}
The javadoc would have to be updated to state that the list is not modifiable. 
Currently the present code returns a list that has mutable elements but cannot 
change in size so this is a minor functional compatibility change.

> CSVRecord.toList() gives write access to private values array
> -------------------------------------------------------------
>
>                 Key: CSV-300
>                 URL: https://issues.apache.org/jira/browse/CSV-300
>             Project: Commons CSV
>          Issue Type: Bug
>    Affects Versions: 1.9.0
>            Reporter: Markus Spann
>            Priority: Trivial
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> {{CSVRecord.toList()}} converts the values to a list by calling 
> {{Arrays.asList}} which writes to the private array in calls to 
> {{{}Arrays.ArrayList.set(int, E){}}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to