Bug 28772 - Excel file causes InvocationTargetException
Summary: Excel file causes InvocationTargetException
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: PC All
: P3 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2004-05-04 17:50 UTC by Dan McConnell
Modified: 2005-07-28 20:12 UTC (History)
0 users

Excel file (27.00 KB, application/excel)
2004-05-04 17:55 UTC, Dan McConnell
Patch for fixing the runtimeerror caused by the xls attached to this bugreport (1.05 KB, patch)
2005-07-27 23:00 UTC, Amol Deshmukh
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dan McConnell 2004-05-04 17:50:23 UTC
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);

	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
	at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
	at org.apache.poi.hssf.record.RecordFactory.createRecord
	at org.apache.poi.hssf.record.RecordFactory.createRecords
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
	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)
Comment 1 Dan McConnell 2004-05-04 17:55:43 UTC
Created attachment 11426 [details]
Excel file
Comment 2 Avik Sengupta 2005-05-20 13:45:56 UTC
testcase in UnfixedBugs. similar to bug 34575
Comment 3 Andy Oliver 2005-07-27 22:20:47 UTC
This looks like a simple case of writing a bad record (95 format record?) either
that or we read it wrong....
Comment 4 Amol Deshmukh 2005-07-27 23:00:29 UTC
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
Comment 5 Andy Oliver 2005-07-28 04:25:04 UTC
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.
Comment 6 Jason Height 2005-07-29 04:12:04 UTC
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.