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
This commit is contained in:
Yegor Kozlov 2012-03-29 10:35:41 +00:00
parent 6facec409f
commit 083c1368b3
4 changed files with 20 additions and 1 deletions

View File

@ -34,7 +34,7 @@
<changes>
<release version="3.9-beta1" date="2012-??-??">
<action dev="poi-developers" type="fix">49529 - avoid exception when cloning sheets with no drawing records and initialized drawing patriarch</action>
</release>
<release version="3.8-FINAL" date="2012-03-26">
<action dev="poi-developers" type="add">52928 - DateFormatConverter: an utility to convert instances of java.text.DateFormat to Excel format patterns</action>

View File

@ -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);
}

View File

@ -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);
}
}

Binary file not shown.