Repository: commons-csv
Updated Branches:
  refs/heads/CSV-216 f66a83901 -> b81b547c3


Warning about .clone()

See
https://lists.apache.org/thread.html/e7c54a595325f1faf7c78b86e76c048c98a914fbb869b8f6d648e4f5@%3Cdev.commons.apache.org%3E


Project: http://git-wip-us.apache.org/repos/asf/commons-csv/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-csv/commit/b81b547c
Tree: http://git-wip-us.apache.org/repos/asf/commons-csv/tree/b81b547c
Diff: http://git-wip-us.apache.org/repos/asf/commons-csv/diff/b81b547c

Branch: refs/heads/CSV-216
Commit: b81b547c34a1905fa235a400dd9e011515601b2f
Parents: f66a839
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Feb 20 11:32:40 2018 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Feb 20 11:34:01 2018 +0000

----------------------------------------------------------------------
 src/main/java/org/apache/commons/csv/CSVFormat.java | 2 ++
 src/main/java/org/apache/commons/csv/CSVRecord.java | 9 ++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-csv/blob/b81b547c/src/main/java/org/apache/commons/csv/CSVFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java 
b/src/main/java/org/apache/commons/csv/CSVFormat.java
index 6a0713d..5c11ebb 100644
--- a/src/main/java/org/apache/commons/csv/CSVFormat.java
+++ b/src/main/java/org/apache/commons/csv/CSVFormat.java
@@ -648,6 +648,7 @@ public final class CSVFormat implements Serializable {
         this.recordSeparator = recordSeparator;
         this.nullString = nullString;
         this.headerComments = toStringArray(headerComments);
+       // Note: .clone() is generally not-OK, but this is safe as Strings are 
immutable
         this.header = header == null ? null : header.clone();
         this.skipHeaderRecord = skipHeaderRecord;
         this.ignoreHeaderCase = ignoreHeaderCase;
@@ -798,6 +799,7 @@ public final class CSVFormat implements Serializable {
      * @return a copy of the header array; {@code null} if disabled, the empty 
array if to be read from the file
      */
     public String[] getHeader() {
+       // Note: .clone() is generally not-OK, but this is safe as Strings are 
immutable
         return header != null ? header.clone() : null;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-csv/blob/b81b547c/src/main/java/org/apache/commons/csv/CSVRecord.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/csv/CSVRecord.java 
b/src/main/java/org/apache/commons/csv/CSVRecord.java
index 2be5c49..6f5e768 100644
--- a/src/main/java/org/apache/commons/csv/CSVRecord.java
+++ b/src/main/java/org/apache/commons/csv/CSVRecord.java
@@ -199,6 +199,10 @@ public class CSVRecord implements Serializable, 
Iterable<String> {
     public final CSVRecord immutable() {
        if (isMutable()) {
                // Subclass is probably CSVMutableRecord, freeze values
+               //
+               // Note: Normally we should not use .clone() as it has many 
+               // issues and pitfalls - here we have an array of immutable 
Strings
+               // so it's OK.
                String[] frozenValue = values.clone();
                return new CSVRecord(frozenValue, mapping, comment, 
recordNumber, characterPosition);
        } else {
@@ -260,7 +264,10 @@ public class CSVRecord implements Serializable, 
Iterable<String> {
        if (isMutable()) {
                return this;
        }
-               String[] newValues = values.clone();
+       // Note: Normally we should not use .clone() as it has many 
+       // issues and pitfalls - here we have an array of immutable Strings
+       // so it's OK.
+       String[] newValues = values.clone();
        return new CSVMutableRecord(newValues, mapping, comment, recordNumber, 
characterPosition);
        }    
 

Reply via email to