Summary: | Constructing HSSFWorkbook is failed,threw ArrayIndexOutOfBoundsException for creating UnknownRecord | ||
---|---|---|---|
Product: | POI | Reporter: | zealz <zealz> |
Component: | HSSF | Assignee: | POI Developers List <dev> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | P2 | ||
Version: | 2.5-FINAL | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Attachments: | The testing xls file which cause exception |
Description
zealz
2006-12-08 18:23:04 UTC
Created attachment 19234 [details]
The testing xls file which cause exception
I have run into the same bug (UnknownRecord throwing an ArrayIndexOutOfBoundsException), and here is a possible solution Change the 3rd constructor to read: public UnknownRecord( short id, short size, byte[] data, int offset ) { sid = id; // ObjRecord's fillFields was getting an obviously wrong subRecordSize, // which it passes to SubRecord.createSubRecord, which passes the value // here as "size". // // Instead of allowing an ArrayIndexOutOfBoundsException // to happen, let's change the size if appropriate. if ( size > (data.length - offset) ) { size = (short)(data.length - offset); } thedata = new byte[size]; System.arraycopy(data, offset, thedata, 0, size); } It could be argued that this is just patching the real problem; the real problem is that we have bogus length/size for some Unknown record type in Excel. Works with POI-3.0.2-BETA2. Regards, Yegor |