Bug 44774 - RecordFormatException & IOException: Unable to construct record instance
Summary: RecordFormatException & IOException: Unable to construct record instance
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-dev
Hardware: All All
: P1 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-07 22:28 UTC by Lal M.R
Modified: 2016-01-28 08:47 UTC (History)
1 user (show)



Attachments
Excel FIle (95.50 KB, application/vnd.ms-excel)
2008-04-07 22:28 UTC, Lal M.R
Details
This file gives gives IO Exception. (227.97 KB, patch)
2008-04-07 22:37 UTC, Lal M.R
Details | Diff
This file also gives gives IO Exception. (108.23 KB, application/vnd.ms-excel)
2008-04-07 22:42 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-04-07 22:28:42 UTC
Created attachment 21790 [details]
Excel FIle

This file doest open in release 'poi-3.0.3-alpha1-20080404.jar" but it works opens with "poi-3.0.2-FINAL-20080204.jar"

Following is the error thrown.

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:41)
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.record.ExternalNameRecord.fillFields(ExternalNameRecord.java:156)
	at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
	at org.apache.poi.hssf.record.ExternalNameRecord.<init>(ExternalNameRecord.java:51)
	... 8 more
Comment 1 Lal M.R 2008-04-07 22:37:56 UTC
Created attachment 21791 [details]
This file gives gives IO Exception.

Cannot remove block[ 215 ]; out of range
java.io.IOException: Cannot remove block[ 215 ]; out of range
	at org.apache.poi.poifs.storage.BlockListImpl.remove(BlockListImpl.java:104)
	at org.apache.poi.poifs.storage.BlockAllocationTableReader.fetchBlocks(BlockAllocationTableReader.java:190)
	at org.apache.poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:129)
	at org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java:536)
	at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:175)
	at TestUserHome.main(TestUserHome.java:40)
Comment 2 Lal M.R 2008-04-07 22:42:21 UTC
Created attachment 21792 [details]
This file also gives gives IO Exception.

Cannot remove block[ 215 ]; out of range
java.io.IOException: Cannot remove block[ 215 ]; out of range
	at org.apache.poi.poifs.storage.BlockListImpl.remove(BlockListImpl.java:104)
	at org.apache.poi.poifs.storage.BlockAllocationTableReader.fetchBlocks(BlockAllocationTableReader.java:190)
	at org.apache.poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:129)
	at org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java:536)
	at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:175)
	at TestUserHome.main(TestUserHome.java:40)
Comment 3 Josh Micich 2008-04-10 00:20:28 UTC
(In reply to comment #0)
> Created an attachment (id=21790) [details]
> Excel FIle
> 
> This file doest open in release 'poi-3.0.3-alpha1-20080404.jar" but it works
> opens with "poi-3.0.2-FINAL-20080204.jar"
> 
> ... Caused by: java.lang.ArrayIndexOutOfBoundsException ...
> ... ExternalNameRecord.fillFields ....

I created a separate bugzilla (bug 44792) for this bug.  More problems were found (after the first one in ExternalNameRecord) when re-writing this XLS file.  Excel could not open the output file properly due to problems in CRNRecord.  These were also fixed in bug 44792.

POI now seems to be able to read attachment (id=21790) and write it back without any obvious corruption.
Comment 4 Josh Micich 2008-04-10 00:52:39 UTC
(In reply to comment #1)
> Created an attachment (id=21791) [details]
> ... java.io.IOException: Cannot remove block[ 215 ]; out of range
> ...

I get "Cannot remove block[ 454 ]; out of range".  (I assume you accidentally copied the stack trace from the attachment 21792 [details].

(In reply to comment #2)
> Created an attachment (id=21792) [details]
> ... java.io.IOException: Cannot remove block[ 215 ]; out of range
> ...

I get this error exactly. The following test code hits the same error, without HSSFWorkbook:

try {
  InputStream is = new FileInputStream("ex44774-21792.xls");
  new POIFSFileSystem(is);
} catch (IOException e) {
  if (e.getMessage().equals("Cannot remove block[ 215 ]; out of range")) {
    throw new AssertionFailedError("Identified bug 44774");
  }
  throw new RuntimeException(e);
}

I tried this code out against poi-3.0.2-FINAL-20080204.jar and got a different error:

java.lang.RuntimeException: java.io.IOException: Unable to read entire block; 479 bytes read before EOF; expected 512 bytes
	at example.poi.Test44774.test44774(Test44774.java:43)
Caused by: java.io.IOException: Unable to read entire block; 479 bytes read before EOF; expected 512 bytes
	at org.apache.poi.poifs.storage.RawDataBlock.<init>(RawDataBlock.java:78)
	at org.apache.poi.poifs.storage.RawDataBlock.<init>(RawDataBlock.java:50)
	at org.apache.poi.poifs.storage.RawDataBlockList.<init>(RawDataBlockList.java:52)
	at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:93)
	at example.poi.Test44774.test44774b(Test44774.java:38)
	... 18 more

There seems to have been some work done in this area recently.
(see bugzilla bug 28231 and bug 35928 / svn r634318 and r636786)

Hopefully someone with more knowledge of POIFS can help diagnose this further.
Comment 5 Nick Burch 2008-07-10 15:50:10 UTC
I believe this bug is fixed in 3.1 FINAL. Please re-open the bug, and attach a new stack trace if you're still having problems with 3.1 FINAL