fixed re-open of bug #42844. HSSFEventFactory silently skips unknown records that happen to be continued.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@575406 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2007-09-13 19:11:10 +00:00
parent b65d864b2c
commit edf5dc307b
3 changed files with 25 additions and 11 deletions

View File

@ -22,15 +22,7 @@ import java.io.InputStream;
import java.io.IOException;
import org.apache.poi.hssf.eventusermodel.HSSFUserException;
import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.RecordFactory;
import org.apache.poi.hssf.record.ContinueRecord;
import org.apache.poi.hssf.record.DrawingRecord;
import org.apache.poi.hssf.record.DrawingGroupRecord;
import org.apache.poi.hssf.record.ObjRecord;
import org.apache.poi.hssf.record.TextObjectRecord;
import org.apache.poi.hssf.record.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/**
@ -151,7 +143,7 @@ public class HSSFEventFactory
{
in.nextRecord();
sid = in.getSid();;
//
// for some reasons we have to make the workbook to be at least 4096 bytes
// but if we have such workbook we fill the end of it with zeros (many zeros)
@ -215,7 +207,11 @@ public class HSSFEventFactory
rec = lastRec;
}
else {
throw new RecordFormatException("Records should handle ContinueRecord internally. Should not see this exception");
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");
}
}
}

Binary file not shown.

View File

@ -76,6 +76,24 @@ public class TestHSSFEventFactory extends TestCase {
}
}
/**
* Unknown records can be continued.
* Check that HSSFEventFactory doesn't break on them.
* (the test file was provided in a reopen of bug #42844)
*/
public void testUnknownContinueRecords() throws Exception {
File f = new File(dirname + "/42844.xls");
HSSFRequest req = new HSSFRequest();
MockHSSFListener mockListen = new MockHSSFListener();
req.addListenerForAllRecords(mockListen);
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(f));
HSSFEventFactory factory = new HSSFEventFactory();
factory.processWorkbookEvents(req, fs);
assertTrue("no errors while processing the file", true);
}
private static class MockHSSFListener implements HSSFListener {
private MockHSSFListener() {}