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

ASF GitHub Bot logged work on CSV-300:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 09/Aug/22 20:06
            Start Date: 09/Aug/22 20:06
    Worklog Time Spent: 10m 
      Work Description: kinow commented on code in PR #249:
URL: https://github.com/apache/commons-csv/pull/249#discussion_r941754150


##########
src/main/java/org/apache/commons/csv/CSVRecord.java:
##########
@@ -298,13 +299,14 @@ public Stream<String> stream() {
     }
 
     /**
-     * Converts the values to a List.
+     * Converts the values to a new {@code List}.<br>
+     * Modifications to the list do not alter this record.
      *
-     * @return a new List
+     * @return a new {@code List}
      * @since 1.9.0
      */
     public List<String> toList() {
-        return Arrays.asList(values);
+        return new ArrayList<>(Arrays.asList(values));

Review Comment:
   See @aherbert 's comment in the JIRA linked about returning an immutable 
list. Unless there's a reason for allowing users to modify the returned list, I 
think an immutable list would be best :+1: 
   
   Thanks for the pull request!
   -Bruno





Issue Time Tracking
-------------------

    Worklog Id:     (was: 799488)
    Time Spent: 0.5h  (was: 20m)

> 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: 0.5h
>  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