I have a Microsoft Excel XLS file (2003 format) that when trying to open using Apache POI 3.17 (and 4.1.2) I get the below stack trace. I can open the Excel file without any errors in Excel 2016.
I do notice that when saving the file using Excel 2016 I can open it via Apache POI. It also shows a reduction in file size from 15 MB to 11 MB after saving it using Excel 2016.
The original file does have a lot of blank columns that extends out very far and reducing some of the lines in the file does eventually allow me to open it with Apache POI but it's not particular to any specific content in the line. I cannot post the original file due to sensitive info and inability to edit it which ends up fixing the issue.
Code to open XLS file
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
final POIFSFileSystem fs = new POIFSFileSystem(new File("/home/dev/Downloads/test.xls"), true);
final HSSFWorkbook xlsToAppendWorkbook = new HSSFWorkbook(fs);
Stacktrace
java.lang.ArrayIndexOutOfBoundsException: Index -2 out of bounds for length 46410
at org.apache.poi.poifs.filesystem.BlockStore$ChainLoopDetector.claim(BlockStore.java:99)
at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.readCoreContents(NPOIFSFileSystem.java:414)
at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:234)
at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:167)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:98)
at