Skip to content

containsColumn throws ArrayIndexOutOfBoundsException, in combination with selectFields #316

@mickaeltr

Description

@mickaeltr

Hello,

It seems that containsColumn throws an ArrayIndexOutOfBoundsException, when used in combination with selectFields. The following test fails because of that:

import com.univocity.parsers.csv.CsvParser;
import com.univocity.parsers.csv.CsvParserSettings;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;

class CsvParserTest {

  @Test
  void testContainColumns() {
    var settings = new CsvParserSettings();
    settings.setHeaderExtractionEnabled(true);
    settings.selectFields("AAA", "BBB", "CCC");
    var parser = new CsvParser(settings);
    var inputStream = new ByteArrayInputStream("AAA,BBB\na,b".getBytes());
    parser.beginParsing(inputStream);
    Assertions.assertFalse(parser.getRecordMetadata().containsColumn("CCC"));
  }

}
java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 2

	at com.univocity.parsers.common.ColumnMap.indexOf(ColumnMap.java:69)
	at com.univocity.parsers.common.DefaultContext.indexOf(DefaultContext.java:82)
	at com.univocity.parsers.common.record.RecordMetaDataImpl.containsColumn(RecordMetaDataImpl.java:481)

Thanks

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions