Bug 53561

Summary: Unexpected adding of drawings into a workbook
Product: POI Reporter: Anton Kosyakov <anton.k.ekb>
Component: HSSFAssignee: POI Developers List <dev>
Severity: normal    
Priority: P2    
Version: 3.8-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Bug Depends on:    
Bug Blocks: 53010    
Attachments: Unit test, input and output workbooks

Description Anton Kosyakov 2012-07-18 07:37:43 UTC
Created attachment 29073 [details]
Unit test, input and output workbooks

When I try to add an auto filter to a workbook with POI the workbook contains the new drawings.

To reproduce this bug see an attachment.

Note that the attached workbook contains some list data validations. Without them the bug would not be reproduced.

Also I started investigating of this issue after I had got the following exception (i can't have reproduced this exception with unit testing yet but it is the real issue):
java.lang.IndexOutOfBoundsException: Index: 2, Size: 1
	at java.util.ArrayList.RangeCheck(ArrayList.java:547)
	at java.util.ArrayList.get(ArrayList.java:322)
	at org.apache.poi.hssf.model.DrawingManager2.getDrawingGroup(DrawingManager2.java:125)
	at org.apache.poi.hssf.model.DrawingManager2.allocateShapeId(DrawingManager2.java:71)
	at org.apache.poi.hssf.record.EscherAggregate.convertPatriarch(EscherAggregate.java:988)
	at org.apache.poi.hssf.record.EscherAggregate.convertUserModelToRecords(EscherAggregate.java:821)
	at org.apache.poi.hssf.record.EscherAggregate.getRecordSize(EscherAggregate.java:508)
	at org.apache.poi.hssf.model.InternalSheet.preSerialize(InternalSheet.java:1567)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:1285)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1205)
Comment 1 Yegor Kozlov 2012-07-18 08:21:46 UTC
The described behavior is a limitation of HSSF: it can create new drawings from scratch but cannot modify existing ones. Auto-filters in the binary .xls format are graphic elements (comboboxes in the filter header are shapes) and when you add a filter to a sheet that already has drawing objects then the output can be corrupted or invalid.
There is an ongoing work to improve drawing support in HSSF, we plan to finish it by late August 2012 and then merge with trunk. Please wait till September, your problem should be fixed by then.

Comment 2 Evgeniy Berlog 2012-08-12 11:47:08 UTC
This problem should be fixed in trunk.

Please try with a nightly build - see download links on http://poi.apache.org/
or build yourself from SVN trunk, see http://poi.apache.org/subversion.html