You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/08/09 20:06:16 UTC

[GitHub] [commons-csv] kinow commented on a diff in pull request #249: [CSV-300] Return new ArrayList in CSVRecord.toList() to prevent access to private values array

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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org