Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit b81b547

Browse files
committed
1 parent f66a839 commit b81b547

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ private CSVFormat(final char delimiter, final Character quoteChar, final QuoteMo
648648
this.recordSeparator = recordSeparator;
649649
this.nullString = nullString;
650650
this.headerComments = toStringArray(headerComments);
651+
// Note: .clone() is generally not-OK, but this is safe as Strings are immutable
651652
this.header = header == null ? null : header.clone();
652653
this.skipHeaderRecord = skipHeaderRecord;
653654
this.ignoreHeaderCase = ignoreHeaderCase;
@@ -798,6 +799,7 @@ public Character getEscapeCharacter() {
798799
* @return a copy of the header array; {@code null} if disabled, the empty array if to be read from the file
799800
*/
800801
public String[] getHeader() {
802+
// Note: .clone() is generally not-OK, but this is safe as Strings are immutable
801803
return header != null ? header.clone() : null;
802804
}
803805

src/main/java/org/apache/commons/csv/CSVRecord.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ public final boolean hasComment() {
199199
public final CSVRecord immutable() {
200200
if (isMutable()) {
201201
// Subclass is probably CSVMutableRecord, freeze values
202+
//
203+
// Note: Normally we should not use .clone() as it has many
204+
// issues and pitfalls - here we have an array of immutable Strings
205+
// so it's OK.
202206
String[] frozenValue = values.clone();
203207
return new CSVRecord(frozenValue, mapping, comment, recordNumber, characterPosition);
204208
} else {
@@ -260,7 +264,10 @@ public final CSVRecord mutable() {
260264
if (isMutable()) {
261265
return this;
262266
}
263-
String[] newValues = values.clone();
267+
// Note: Normally we should not use .clone() as it has many
268+
// issues and pitfalls - here we have an array of immutable Strings
269+
// so it's OK.
270+
String[] newValues = values.clone();
264271
return new CSVMutableRecord(newValues, mapping, comment, recordNumber, characterPosition);
265272
}
266273

0 commit comments

Comments
 (0)