Bug 39970 - ArrayIndexOutOfBoundsException when opening EXCEL file
Summary: ArrayIndexOutOfBoundsException when opening EXCEL file
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.5-FINAL
Hardware: All Windows XP
: P5 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-05 18:18 UTC by Venkatramana Vishwanatham
Modified: 2006-07-26 05:00 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Venkatramana Vishwanatham 2006-07-05 18:18:40 UTC
ArrayIndexOutOfBoundsException Occured when opening EXCEL file that contains 
values in such a way that some values span to other columns but some doesn't 
span to other columns is display.

The error stacktrace is-

java.lang.reflect.InvocationTargetException: 
java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at org.apache.poi.hssf.record.UnknownRecord.<init>
(UnknownRecord.java:62)
	at org.apache.poi.hssf.record.SubRecord.createSubRecord
(SubRecord.java:57)
	at org.apache.poi.hssf.record.ObjRecord.fillFields(ObjRecord.java:99)
	at org.apache.poi.hssf.record.Record.fillFields(Record.java(Compiled 
Code))
	at org.apache.poi.hssf.record.Record.<init>(Record.java(Compiled Code))
	at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:61)
	at java.lang.reflect.Constructor.newInstance(Native Method)
	at org.apache.poi.hssf.record.RecordFactory.createRecord
(RecordFactory.java(Compiled Code))
	at org.apache.poi.hssf.record.RecordFactory.createRecords
(RecordFactory.java(Compiled Code))
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
(HSSFWorkbook.java:163)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
(HSSFWorkbook.java:210)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
(HSSFWorkbook.java:191)
	at com.mastercard.mcideas.atmdir.util.ExcelUtil.openWorkBook
(ExcelUtil.java:263)
	at com.mastercard.mcideas.atmdir.util.ExcelUtil.TestReadingWorkBook
(ExcelUtil.java:399)
	at com.mastercard.mcideas.atmdir.util.ExcelUtil.main
(ExcelUtil.java:318)

The problem is with System.arrayCopy() method call in UnknownRecord class. A 
fix can be applied to this problem as follows (By making sure the array 
doesn't go beyond limits)


 public UnknownRecord( short id, short size, byte[] data, int offset )
    {
        sid     = id;
        thedata = new byte[size];
        
        if((data.length - offset) < size)
		size = (short)(data.length - offset);
        
        
        System.arraycopy(data, offset, thedata, 0, size);
    }
Comment 1 Jason Height 2006-07-26 12:00:50 UTC
Completely invalid bug, if there is an excel file that is generating this
exception then upload/attach it to a bug report. 

Feel free to repoen this bug, if you can upload the excel causing the troyble.

Jason