Bug 60042 - PartAlreadyExistsException thrown when removing and adding slides.
Summary: PartAlreadyExistsException thrown when removing and adding slides.
Status: RESOLVED DUPLICATE of bug 55791
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: 3.14-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Blocks: 60810
  Show dependency tree
Reported: 2016-08-25 10:13 UTC by John Littlewood
Modified: 2017-03-19 20:41 UTC (History)
1 user (show)

Presentation file which triggers the bug when used with the code in the description. (30.72 KB, application/vnd.openxmlformats-officedocument.presentationml.presentation)
2016-08-25 10:13 UTC, John Littlewood

Note You need to log in before you can comment on or make changes to this bug.
Description John Littlewood 2016-08-25 10:13:03 UTC
Created attachment 34172 [details]
Presentation file which triggers the bug when used with the code in the description.

I have a use case which requires taking a template presentation, deleting some slides, and adding some more. When doing this, I get the following error message when attempting to add a new slide after removing an old one:
Exception in thread "main" org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException: A part with the name '/ppt/slides/slide2.xml' 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:811)
	at org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:775)
	at org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:536)
	at org.apache.poi.xslf.usermodel.XMLSlideShow.createSlide(XMLSlideShow.java:220)
	at org.apache.poi.xslf.usermodel.XMLSlideShow.createSlide(XMLSlideShow.java:243)
	at com.thalesgroup.uk.airscape.investigations.briefinggenerator.PresentationBugger.main(PresentationBugger.java:35)

The following code results in the exception being thrown:

public class PresentationBugger {

  public static void main(String... args) throws IOException, OpenXML4JException, XmlException {
    try (XMLSlideShow pptx = new XMLSlideShow(new FileInputStream(new File("pres.pptx")))) {

"pres.pptx" is a presentation (tested with PowerPoint 2010). With one slide in the presentation, the bug doesn't occur, but with two or more, it does. I've attached an example of pres.pptx which triggers the bug.
Comment 1 Javen O'Neal 2016-08-25 15:56:19 UTC
Should searching for file name (slide2.xml) be case insensitive?

Also, slideNumber may not be computed correctly if the slides are out of order.

> for (CTSlideIdListEntry slideId : slideList.getSldIdArray()){
>     slideNumber = (int)Math.max(slideId.getId() + 1, slideNumber);
>     cnt++;
> }

It would be better to store slide numbers in a set and find the largest or smallest slide number and find the next unused number.
Comment 2 Dominik Stadler 2017-03-19 20:41:19 UTC
This seems to have been fixed shortly after version 3.14 was released, see bug 55791. I tried the test-code with the attached sample and it did work fine in current trunk.

*** This bug has been marked as a duplicate of bug 55791 ***