Bug 42844 - ContinueRecord incorrectly handled in HSSFEventFactory.processEvents
Summary: ContinueRecord incorrectly handled in HSSFEventFactory.processEvents
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-FINAL
Hardware: Macintosh Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-09 14:09 UTC by Daniel Stephens
Modified: 2008-04-27 11:03 UTC (History)
1 user (show)



Attachments
XLS file which causes POI to fail with internal error (63.00 KB, application/octet-stream)
2007-07-09 14:21 UTC, Daniel Stephens
Details
Excel file with print area that causes RecordFormatException (21.00 KB, text/plain)
2007-09-11 10:15 UTC, Sarah Waziruddin
Details
Failed excel file (24.00 KB, application/vnd.ms-excel)
2008-04-17 04:13 UTC, Sergey
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Stephens 2007-07-09 14:09:34 UTC
I have an XLS file which has been produced by Microsoft Excel 2007 saving in
compatibility mode that cannot be loaded by either 3.0-FINAL and 3.0.1-FINAL.
(It's also worth noting that the file confuses jxl as well, but figuring out how
to stop that from crashing was far easier). The presence of "Should not see this
exception" leads me to believe that there's a bug lurking within POI.

Exception in thread "main" org.apache.poi.hssf.record.RecordFormatException:
Records should handle ContinueRecord internally. Should not see this exception
        at
org.apache.poi.hssf.eventusermodel.HSSFEventFactory.genericProcessEvents(HSSFEventFactory.java:195)
        at
org.apache.poi.hssf.eventusermodel.HSSFEventFactory.processEvents(HSSFEventFactory.java:102)

I'll try and attach the problem spreadsheet (narrowed down as much as possible)
and/or a biffdump from it, if I fail it's available via email request.

(I'm using the POI builds from the maven repository, with sun a variety of Sun
1.4.2 JVM's)
Comment 1 Daniel Stephens 2007-07-09 14:21:50 UTC
Created attachment 20482 [details]
XLS file which causes POI to fail with internal error

This is a minimal file that causes the internal error in POI.

The problem may well be related to AutoFilter since turning that off causes it
to no longer fail.
Comment 2 Dan 2007-08-06 15:18:15 UTC
I also encountered such problem. But in my excel file, even if I close
AutoFilter, it still exists. After I check the source codes, I find that in
processEvents, there is no place to deal with ContinueRecord in event model. Not
like user model, it deals with ContinueRecords in RecordFactory.CreateRecords.
So I guess it may miss some handler codes here. Otherwise, if the
RecordInputStream contains ContinueRecords, it will surely invoke such kind of
exception.
Comment 3 Nick Burch 2007-08-23 11:22:59 UTC
This should now be fixed in svn. As suggested, ContinueRecord special cases
similar to in RecordFactory have been added
Comment 4 Sarah Waziruddin 2007-09-11 10:14:22 UTC
The fix for this bug does not account for all error cases.  I am attaching a
document for which the code fails.  I found that the problem with this document
is the print area defined.  If you unset the print area, POI parses this
document correctly.  Also, if you re-set the print area to something like 2
cells, POI parses the document fine.  I stepped through the POI code using the
debugger and found the error occurs on a Continue Record that occurs after an
Unknown Record with sid 77.
Comment 5 Sarah Waziruddin 2007-09-11 10:15:25 UTC
Created attachment 20790 [details]
Excel file with print area that causes RecordFormatException
Comment 6 Yegor Kozlov 2007-09-13 12:11:43 UTC
I see what's missing.
We borrowed the code from RecordFactory.CreateRecords but forgot to handle
unknown records that happen to be continued.

In RecordFactory.CreateRecords this piece of code looks as follows:

  if (lastRecord instanceof UnknownRecord) {
    //Gracefully handle records that we dont know about,
    //that happen to be continued
    records.add(record);
  } else 
    throw new RecordFormatException("Unhandled Continue Record");
  }


In HSSFEventFactory it should be like this:

  if (rec instanceof UnknownRecord) {
     ;//silently skip records we don't know about
  } else {
    throw new RecordFormatException("Records should handle ContinueRecord
internally. Should not see this exception");
  }

With this change it works without complains. I included the provided excel file
in the unit test. 

Regards,
Yegor
Comment 7 Sergey 2008-04-17 04:13:07 UTC
Created attachment 21824 [details]
Failed excel file
Comment 8 Sergey 2008-04-17 04:15:03 UTC
Fails on poi-bin-3.0.2-FINAL-20080204.zip event
Comment 9 Nick Burch 2008-04-27 11:03:51 UTC
Could you please try with 3.1 beta 1 (should be hitting the mirrors tomorrow or the day after), and see if that fixes it for you? I think it should do, but please re-open the bug if not.