monitorjbl / excel-streaming-reader

An easy-to-use implementation of a streaming Excel reader using Apache POI
Apache License 2.0
960 stars 345 forks source link

java.lang.IndexOutOfBoundsException when a blank cell is processed #186

Open ismailozgen opened 5 years ago

ismailozgen commented 5 years ago

Following exception is thrown when empty cell is processed in attached excel file. The error occurs when the sstCacheSize attribute of the reader is set explicitly.

Example test code

File file = new File("src/test/resources/excel_has_blank_cell.xlsx");
try(Workbook wb = StreamingReader.builder().sstCacheSize(1024).open(file)) {
      wb.getSheetAt(0).iterator().next();
    }

File: excel_has_blank_cell.xlsx

java.lang.IndexOutOfBoundsException: Index 5 out of bounds for length 5
    at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
    at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
    at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
    at java.base/java.util.Objects.checkIndex(Objects.java:372)
    at java.base/java.util.ArrayList.get(ArrayList.java:458)
    at com.monitorjbl.xlsx.sst.FileBackedList.getAt(FileBackedList.java:66)
    at com.monitorjbl.xlsx.sst.BufferedStringsTable.getItemAt(BufferedStringsTable.java:110)
    at com.monitorjbl.xlsx.sst.BufferedStringsTable.getEntryAt(BufferedStringsTable.java:115)
    at com.monitorjbl.xlsx.impl.StreamingSheetReader.unformattedContents(StreamingSheetReader.java:362)
    at com.monitorjbl.xlsx.impl.StreamingSheetReader.handleEvent(StreamingSheetReader.java:199)
    at com.monitorjbl.xlsx.impl.StreamingSheetReader.getRow(StreamingSheetReader.java:70)
    at com.monitorjbl.xlsx.impl.StreamingSheetReader.access$200(StreamingSheetReader.java:31)
    at com.monitorjbl.xlsx.impl.StreamingSheetReader$StreamingRowIterator.hasNext(StreamingSheetReader.java:401)
    at com.monitorjbl.xlsx.impl.StreamingSheetReader$StreamingRowIterator.<init>(StreamingSheetReader.java:395)
    at com.monitorjbl.xlsx.impl.StreamingSheetReader.iterator(StreamingSheetReader.java:381)
    at com.monitorjbl.xlsx.impl.StreamingSheet.rowIterator(StreamingSheet.java:57)
pjfanning commented 5 years ago

@ismailozgen I don't know if it helps but I added your test case to https://github.com/pjfanning/excel-streaming-reader and it works there. That codebase is a fork of this project but it handles shared strings differently.