Skip to content

Commit d0035e6

Browse files
committed
headerMapping is only created once, so make it final
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1303455 13f79535-47bb-0310-9956-ffa450edef68
1 parent 10bf28e commit d0035e6

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
public class CSVParser implements Iterable<CSVRecord> {
6565

6666
private final CSVLexer lexer;
67-
private Map<String, Integer> headerMapping;
67+
private final Map<String, Integer> headerMapping;
6868

6969
// the following objects are shared to reduce garbage
7070

@@ -94,7 +94,7 @@ public CSVParser(Reader input, CSVFormat format) throws IOException {
9494

9595
this.lexer = new CSVLexer(format, new ExtendedBufferedReader(input));
9696

97-
initializeHeader(format);
97+
this.headerMapping = initializeHeader(format);
9898
}
9999

100100
/**
@@ -172,9 +172,10 @@ CSVRecord getRecord() throws IOException {
172172
/**
173173
* Initializes the name to index mapping if the format defines a header.
174174
*/
175-
private void initializeHeader(CSVFormat format) throws IOException {
175+
private Map<String, Integer> initializeHeader(CSVFormat format) throws IOException {
176+
Map<String, Integer> hdrMap = null;
176177
if (format.getHeader() != null) {
177-
headerMapping = new HashMap<String, Integer>();
178+
hdrMap = new HashMap<String, Integer>();
178179

179180
String[] header = null;
180181
if (format.getHeader().length == 0) {
@@ -190,10 +191,11 @@ private void initializeHeader(CSVFormat format) throws IOException {
190191
// build the name to index mappings
191192
if (header != null) {
192193
for (int i = 0; i < header.length; i++) {
193-
headerMapping.put(header[i], Integer.valueOf(i));
194+
hdrMap.put(header[i], Integer.valueOf(i));
194195
}
195196
}
196197
}
198+
return hdrMap;
197199
}
198200

199201
/**

0 commit comments

Comments
 (0)