Bug 49529

Summary: HSSFWorkbook.cloneSheet after createDrawingPatriarch -> Exception
Product: POI Reporter: olivier.masseau
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.6-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Excel workbook used to reproduce the bug.
Fixed bug with cloning empty EscherAggregate records

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"));
			workbook.getSheetAt(0).createDrawingPatriarch();
			workbook.cloneSheet(0);
			System.out.println("OK");
		}
		catch(Exception e) {
			e.printStackTrace();
		}
	}

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.

Yegor