diff --git a/core/src/main/java/tech/tablesaw/io/FileReader.java b/core/src/main/java/tech/tablesaw/io/FileReader.java index 4c8f96e51..b31850499 100644 --- a/core/src/main/java/tech/tablesaw/io/FileReader.java +++ b/core/src/main/java/tech/tablesaw/io/FileReader.java @@ -94,6 +94,11 @@ public String[] getColumnNames( if (options.header()) { String[] headerNames = parser.parseNext(); + + if (headerNames == null) { + // no header because file is empty + return new String[] {}; + } // work around issue where Univocity returns null if a column has no header. for (int i = 0; i < headerNames.length; i++) { diff --git a/core/src/test/java/tech/tablesaw/io/csv/CsvReaderTest.java b/core/src/test/java/tech/tablesaw/io/csv/CsvReaderTest.java index e9b418c6b..87ef74644 100644 --- a/core/src/test/java/tech/tablesaw/io/csv/CsvReaderTest.java +++ b/core/src/test/java/tech/tablesaw/io/csv/CsvReaderTest.java @@ -756,7 +756,7 @@ public void testReadFailure2() throws IOException { @Test public void testEmptyFileHeaderEnabled() throws IOException { - Table table1 = Table.read().csv(CsvReadOptions.builder("../data/empty_file.csv").header(false)); + Table table1 = Table.read().csv(CsvReadOptions.builder("../data/empty_file.csv").header(true)); assertEquals("empty_file.csv: 0 rows X 0 cols", table1.shape()); }