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

NullPointerException when building BufferedStringsTable #205

Open jamesblewitt opened 5 years ago

jamesblewitt commented 5 years ago

Version 2.1.0

If I import an Excel document with the sstCacheSize set to a positive value I get a NullPointerException.

java.lang.NullPointerException: null at com.monitorjbl.xlsx.sst.FileBackedList.writeToFile(FileBackedList.java:74) ~[xlsx-streamer-2.1.0.jar:na] at com.monitorjbl.xlsx.sst.FileBackedList.add(FileBackedList.java:52) ~[xlsx-streamer-2.1.0.jar:na] at com.monitorjbl.xlsx.sst.BufferedStringsTable.readFrom(BufferedStringsTable.java:43) ~[xlsx-streamer-2.1.0.jar:na] at com.monitorjbl.xlsx.sst.BufferedStringsTable.<init>(BufferedStringsTable.java:31) ~[xlsx-streamer-2.1.0.jar:na] at com.monitorjbl.xlsx.sst.BufferedStringsTable.getSharedStringsTable(BufferedStringsTable.java:26) ~[xlsx-streamer-2.1.0.jar:na] at com.monitorjbl.xlsx.impl.StreamingWorkbookReader.init(StreamingWorkbookReader.java:120) ~[xlsx-streamer-2.1.0.jar:na] at com.monitorjbl.xlsx.impl.StreamingWorkbookReader.init(StreamingWorkbookReader.java:91) ~[xlsx-streamer-2.1.0.jar:na] at com.monitorjbl.xlsx.StreamingReader$Builder.open(StreamingReader.java:251) ~[xlsx-streamer-2.1.0.jar:na]

This happens because BufferedStringsTable.parseCT_Rst returns a NULL value which is then passed into the FileBackedList.add method which causes an error.

This could be fixed by performing a NULL check before adding it to the list. For example:

list.add(parseCT_Rst(xmlEventReader)); Becomes: String str = parseCT_Rst(xmlEventReader); if (str != null) list.add(str);

awilson9 commented 5 years ago

There's a pull request for this: https://github.com/monitorjbl/excel-streaming-reader/pull/187

Would love to see this get released. Running into the same problem.