From: Yegor Kozlov Date: Thu, 29 Mar 2012 10:35:41 +0000 (+0000) Subject: Bugzilla 49529 - avoid exception when cloning sheets with no drawing records and... X-Git-Tag: 3.10-beta1~202 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0afefcd2b852519b036d24f971980a3c21bf9d38;p=poi.git Bugzilla 49529 - avoid exception when cloning sheets with no drawing records and initialized drawing patriarch git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1306781 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 0dac8461ae..b0a09088e7 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,7 +34,7 @@ - + 49529 - avoid exception when cloning sheets with no drawing records and initialized drawing patriarch 52928 - DateFormatConverter: an utility to convert instances of java.text.DateFormat to Excel format patterns diff --git a/src/java/org/apache/poi/hssf/model/InternalSheet.java b/src/java/org/apache/poi/hssf/model/InternalSheet.java index 0f03bbc457..cbacbc0ca1 100644 --- a/src/java/org/apache/poi/hssf/model/InternalSheet.java +++ b/src/java/org/apache/poi/hssf/model/InternalSheet.java @@ -386,6 +386,14 @@ public final class InternalSheet { ((RecordAggregate) rb).visitContainedRecords(new RecordCloner(clonedRecords)); continue; } + if (rb instanceof EscherAggregate){ + // EscherAggregate is used only as a container for SODRAWING and OBJ record combinations + // So, if the container is empty, there is no reason to clone this record + // See https://issues.apache.org/bugzilla/show_bug.cgi?id=49529 + if (0 == rb.getRecordSize()){ + continue; + } + } Record rec = (Record) ((Record) rb).clone(); clonedRecords.add(rec); } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 111130e29d..0864549f6c 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -2227,4 +2227,15 @@ if(1==2) { cell.getCellFormula()); } + public void test49529() throws Exception { + // user code reported in Bugzilla #49529 + HSSFWorkbook workbook = openSample("49529.xls"); + workbook.getSheetAt(0).createDrawingPatriarch(); + // prior to the fix the line below failed with + // java.lang.IllegalStateException: EOF - next record not available + workbook.cloneSheet(0); + + // make sure we are still readable + writeOutAndReadBack(workbook); + } } diff --git a/test-data/spreadsheet/49529.xls b/test-data/spreadsheet/49529.xls new file mode 100644 index 0000000000..1989a6a1d3 Binary files /dev/null and b/test-data/spreadsheet/49529.xls differ