Bug 65120

Summary: [PATCH] PartAlreadyExistsException when creating cell comments
Product: POI Reporter: Raúl Wegmann <raul>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: raul
Priority: P2    
Version: 4.1.2-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: patch including test

Description Raúl Wegmann 2021-02-02 15:56:43 UTC
When creating a new VML drawing (as part of creating a cell comment), the number assigned to the part file only takes the current number of parts into account, but this "ID" might already been taken if one of the parts has been previously removed (i.e. by deleting a sheet).

org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException: A part with the name '/xl/drawings/vmlDrawing2.vml' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]
	at org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:840)
	at org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:803)
	at org.apache.poi.ooxml.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:586)
	at org.apache.poi.xssf.usermodel.XSSFSheet.getVMLDrawing(XSSFSheet.java:606)
	at org.apache.poi.xssf.usermodel.XSSFDrawing.createCellComment(XSSFDrawing.java:371)
	at org.apache.poi.xssf.usermodel.XSSFDrawing.createCellComment(XSSFDrawing.java:78)

When assigning the number to a new part, it must be checked for uniqueness.

The attached patch uses the same solution in the XSSFSheet.getVMLDrawing() method as already implemented in XSSFSheet.createDrawingPatriarch().
Comment 1 Raúl Wegmann 2021-02-02 16:06:11 UTC
Created attachment 37724 [details]
patch including test
Comment 2 PJ Fanning 2021-02-02 21:15:00 UTC
thanks - applied using r1886143 (the gradle change has since been reverted)