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); }
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