6464public 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