Bug 49529 - HSSFWorkbook.cloneSheet after createDrawingPatriarch -> Exception
HSSFWorkbook.cloneSheet after createDrawingPatriarch -> Exception
Product: POI
Classification: Unclassified
Component: HSSF
PC Windows XP
: P2 normal (vote)
: ---
Assigned To: POI Developers List
Depends on:
  Show dependency tree
Reported: 2010-06-30 08:56 UTC by olivier.masseau
Modified: 2012-03-29 10:36 UTC (History)
0 users

Excel workbook used to reproduce the bug. (16.00 KB, application/vnd.excel)
2010-06-30 08:56 UTC, olivier.masseau
Fixed bug with cloning empty EscherAggregate records (1008 bytes, patch)
2012-03-27 20:52 UTC, Evgeniy Berlog
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description olivier.masseau 2010-06-30 08:56:29 UTC
Created attachment 25668 [details]
Excel workbook used to reproduce the bug.

If I open an existing workbook with one sheet and then create a drawing patriarch for the sheet, I cannot clone the sheet anymore.

Simple code to reproduce the bug :

public static void main(String[] args) {
		try {
			Workbook workbook = WorkbookFactory.create(new FileInputStream("C:\\test.xls"));
		catch(Exception e) {

It produces this exception :

java.lang.IllegalStateException: EOF - next record not available
	at org.apache.poi.hssf.record.RecordInputStream.nextRecord(RecordInputStream.java:190)
	at org.apache.poi.hssf.record.Record.cloneViaReserialise(Record.java:88)
	at org.apache.poi.hssf.record.AbstractEscherHolderRecord.clone(AbstractEscherHolderRecord.java:150)
	at org.apache.poi.hssf.model.Sheet.cloneSheet(Sheet.java:375)
	at org.apache.poi.hssf.usermodel.HSSFSheet.cloneSheet(HSSFSheet.java:121)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.cloneSheet(HSSFWorkbook.java:662)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.cloneSheet(HSSFWorkbook.java:87)
Comment 1 Evgeniy Berlog 2012-03-27 20:52:14 UTC
Created attachment 28512 [details]
Fixed bug with cloning empty EscherAggregate records

Bug appears only if sheet has no drawing records. If we try to serialize empty EscherRecord it returns empty bytes array what can cause exceptions.
Comment 2 Yegor Kozlov 2012-03-29 10:36:36 UTC
Thanks for the patch, applied in r1306781 along with a unit test. The attached sample was included in our collection of test files.