Bug 55791

Summary: PartAlreadyExistsException when removing and adding slides
Product: POI Reporter: Monica <monicapatra90>
Component: XSLFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: critical CC: john.littlewood
Priority: P2    
Version: 3.9-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   
Bug Depends on: 57165    
Bug Blocks: 60810    

Description Monica 2013-11-18 12:29:29 UTC
Whenever am trying to delete slides of a simple PPT , it is possible. But am working on a program where i have to use the previous layouts to create new slides dynamically for more data. 

Now when i try to delete a slide, it starts throwing error on that layout part of code irrespective of the slide i want to delete.

The error is as shown

Exception in thread "main" org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException: A part with the name '/ppt/slides/slide22.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:774)
       at org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:738)
       at org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:350)
       at org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:334)
       at org.apache.poi.xslf.usermodel.XMLSlideShow.createSlide(XMLSlideShow.java:206)
       at Table.main(Table.java:9)

And my code is:


XMLSlideShow ppt = new XMLSlideShow(new FileInputStream("Template.pptx"));
XSLFSlide[] slide = ppt.getSlides();
ppt.removeSlide(11);
XSLFTable tbl = slide[1].createTable();
tbl.setAnchor(new Rectangle2D.Double(30, 100, 600, 800));
             
XSLFSlideMaster master = ppt.getSlideMasters()[0];
XSLFSlideLayout layout1 = master.getLayout(SlideLayout.TITLE_ONLY);
XSLFSlide slide1 = ppt.createSlide(layout1) ;
String str1 = slide[1].getTitle();
XSLFTextShape[] pht = slide1.getPlaceholders();

Thank you.
Comment 1 Dominik Stadler 2015-03-01 20:28:07 UTC
Reproducer with existing sample documents, so it is not really related to layout/master slides: 

    @Test
    public void bug55791a() {
        XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("45541_Footer.pptx");
        removeAndCreateSlide(ppt);
    }

    @Test
    public void bug55791b() {
        XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("SampleShow.pptx");
        removeAndCreateSlide(ppt);
    }

	private void removeAndCreateSlide(XMLSlideShow ppt) {
		assertTrue(ppt.getSlides().length > 1);
    	ppt.removeSlide(1);
    	assertNotNull(ppt.createSlide());
	}
Comment 2 Dominik Stadler 2015-03-18 19:09:12 UTC
There was a similar problem for XSSF reported in bug 57165, maybe a similar fix will be neceswsary here.
Comment 3 Dominik Stadler 2016-03-13 21:35:15 UTC
With r1734862 we now try harder to find a unique name for new slides to avoid name-clashes when some parts of the previous slide still linger on for some reason.
Comment 4 Dominik Stadler 2017-03-19 20:41:19 UTC
*** Bug 60042 has been marked as a duplicate of this bug. ***