The attached Excel file , which I believe is generated by Microsoft Access causes the following Exception when trying to create a workbook. The POI version this was tried with is 2.0 and 2.5 Final 20040302. The code fragment is: is = new FileInputStream(filepath); // String representing pathname of xls file POIFSFileSystem fs = new POIFSFileSystem(is); HSSFWorkbook wb = new HSSFWorkbook(fs); java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:274) at org.apache.poi.hssf.record.RecordFactory.createRecord (RecordFactory.java:224) at org.apache.poi.hssf.record.RecordFactory.createRecords (RecordFactory.java:160) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init> (HSSFWorkbook.java:165) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init> Caused by: java.lang.ArrayIndexOutOfBoundsException at org.apache.poi.util.LittleEndian.getNumber(LittleEndian.java:491) at org.apache.poi.util.LittleEndian.getInt(LittleEndian.java:139) at org.apache.poi.hssf.record.BOFRecord.fillFields(BOFRecord.java:133) at org.apache.poi.hssf.record.Record.fillFields(Record.java:90) at org.apache.poi.hssf.record.Record.<init>(Record.java:55) at org.apache.poi.hssf.record.BOFRecord.<init>(BOFRecord.java:98)
Created attachment 11426 [details] Excel file
testcase in UnfixedBugs. similar to bug 34575
This looks like a simple case of writing a bad record (95 format record?) either that or we read it wrong....
Created attachment 15801 [details] Patch for fixing the runtimeerror caused by the xls attached to this bugreport Andy is probably right. However since a runtime exception is caused, is it a BadThing to let it happen? The attached patch attempts to fix the runtime exception by setting default values in case the array runs out of data in fillFields(..). The patch was tested on the previous attachement to this issue (attachment#11426 [details]) and was found to be working. It seemed to work for both load and save file. Also passed the previously broken test in usermodel/TestUnfixedBugs
I'm -1 on that until its confirmed that the record is a Biff8 record. If it is a Biff 7 or previous we should throw an exception and say "Not a valid Excel 97+ file" -- Someone needs to do a org.apache.poi.hssf.dev.BiffViewer to check (probably after commenting the thing out of the RecordFactory to get the hex dump) out what all is different. We shouldn't punt on correctly reading the record and just "make it work"...we need to read it correctly. Its okay to write something different.
Yup this is a BIFF 5/7 file and not a BIFF 8. The BOF record is 12 bytes. A BIFF 8 BOF record should be 20 bytes. Jason