Bug 44710 - org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance
Summary: org.apache.poi.hssf.record.RecordFormatException: Unable to construct record ...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-FINAL
Hardware: All All
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
: 44951 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-03-31 00:09 UTC by Lal M.R
Modified: 2008-05-07 19:33 UTC (History)
1 user (show)



Attachments
Excel File (243.50 KB, application/vnd.ms-excel)
2008-03-31 00:10 UTC, Lal M.R
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lal M.R 2008-03-31 00:09:13 UTC
This file gets opened in '2.5.1-final' but wont open in 'poi-3.0.2-FINAL'.

org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance
	at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:199)
	at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:117)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:207)
	at TestUserHome.main(TestUserHome.java:29)
Caused by: 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:494)
	at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:187)
	... 3 more
Caused by: java.lang.ArrayIndexOutOfBoundsException
	at org.apache.poi.hssf.record.RecordInputStream.checkRecordPosition(RecordInputStream.java:132)
	at org.apache.poi.hssf.record.RecordInputStream.readShort(RecordInputStream.java:152)
	at org.apache.poi.hssf.util.HSSFCellRangeAddress.fillFields(HSSFCellRangeAddress.java:77)
	at org.apache.poi.hssf.util.HSSFCellRangeAddress.<init>(HSSFCellRangeAddress.java:65)
	at org.apache.poi.hssf.record.DVRecord.fillFields(DVRecord.java:208)
	at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
	at org.apache.poi.hssf.record.DVRecord.<init>(DVRecord.java:134)
	... 8 more
Comment 1 Lal M.R 2008-03-31 00:10:03 UTC
Created attachment 21739 [details]
Excel File
Comment 2 Nick Burch 2008-03-31 07:08:54 UTC
Have you tried with a recent svn checkout / nightly build? There have been some fixes to DVRecord since 3.0.2

You can get a nightly build from http://encore.torchbox.com/poi-svn-build/
Comment 3 Lal M.R 2008-03-31 23:08:30 UTC
Thanks for your comments.

Today I tried with the latest build (ie  poi-source-3.1-alpha1-20080330.zip 30-Mar-2008 05:32 2.0M )

Now the following error is thrown.

WARNING: POIFS is closing the supplied input stream of type (java.io.BufferedInputStream) which supports mark/reset.  This will be a problem for the caller if the stream will still be used.  If that is the case the caller should wrap the input stream to avoid this close logic.  This warning is only temporary and will not be present in future versions of POI.
org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance
	at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:206)
	at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:124)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:204)
	at TestUserHome.main(TestUserHome.java:29)
Caused by: 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:494)
	at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:194)
	... 3 more
Caused by: java.lang.ArrayIndexOutOfBoundsException
	at org.apache.poi.hssf.record.RecordInputStream.checkRecordPosition(RecordInputStream.java:132)
	at org.apache.poi.hssf.record.RecordInputStream.readShort(RecordInputStream.java:152)
	at org.apache.poi.hssf.util.HSSFCellRangeAddress.fillFields(HSSFCellRangeAddress.java:80)
	at org.apache.poi.hssf.util.HSSFCellRangeAddress.<init>(HSSFCellRangeAddress.java:70)
	at org.apache.poi.hssf.record.DVRecord.fillFields(DVRecord.java:207)
	at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
	at org.apache.poi.hssf.record.DVRecord.<init>(DVRecord.java:134)
	... 8 more
Comment 4 Lal M.R 2008-03-31 23:09:54 UTC
Sorry this is the ERROR.

WARNING: POIFS is closing the supplied input stream of type (java.io.BufferedInputStream) which supports mark/reset.  This will be a problem for the caller if the stream will still be used.  If that is the case the caller should wrap the input stream to avoid this close logic.  This warning is only temporary and will not be present in future versions of POI.
org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance
	at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:206)
	at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:124)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:204)
	at TestUserHome.main(TestUserHome.java:29)
Caused by: 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:494)
	at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:194)
	... 3 more
Caused by: java.lang.UnsupportedOperationException:  Unknown Ptg in Formula: 0xffffffff (-1)
	at org.apache.poi.hssf.record.formula.Ptg.createPtg(Ptg.java:361)
	at org.apache.poi.hssf.record.DVRecord.fillFields(DVRecord.java:201)
	at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
	at org.apache.poi.hssf.record.DVRecord.<init>(DVRecord.java:134)
	... 8 more
Comment 5 Josh Micich 2008-04-01 16:58:54 UTC
Fixed in svn r643654.

There was an incorrect call to input stream skip() in DVRecord.fillFields(RecordInputStream).  I have not written a junit for this because there seems to be many other things wrong with DVRecord.

I have closed this bug because this specific problem should not occur anymore. With the patch, HSSFWorkbook.<init>(InputStream) completes OK now.  

However, if you need to re-write the spreadsheet back to an XLS file, you are likely to encounter more bugs.  I have opened bug 44735 to track all of those problems.
Comment 6 Josh Micich 2008-05-07 19:33:13 UTC
*** Bug 44951 has been marked as a duplicate of this bug. ***