Bug 62717

Summary: Content type of parts could not always be saved
Product: POI Reporter: pouponbe
Component: OPCAssignee: POI Developers List <dev>
Severity: regression    
Priority: P2    
Version: 3.17-FINAL   
Target Milestone: ---   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 62718    

Description pouponbe 2018-09-13 16:45:36 UTC
In the class org.apache.poi.openxml4j.opc.internal.ContentTypeManager the method addContentType(PackagePartName,String) doesn't authorized to register the same contentType string for two different package part name if those part name have different extension.
Comment 1 PJ Fanning 2018-09-13 19:28:09 UTC
Can you provide a code snippet to avoid confusion?

Would you be able to try the latest POI version - 4.0.0?
Comment 2 pouponbe 2018-09-14 12:54:07 UTC
Code that reproduce :
File testFile = new File("test.zip");
    OPCPackage mainPkg = OPCPackage.openOrCreate(testFile);

    PackagePartName firstPartName = PackagingURIHelper.createPartName("/dummy/text.txt");
    PackagePart firstPkg = mainPkg.createPart(firstPartName, "text/plain");
    OutputStreamWriter osW = new OutputStreamWriter(firstPkg.getOutputStream(), "UTF8");

    PackagePartName secondPartName = PackagingURIHelper.createPartName("/dummy/text.properties");
    PackagePart secondPkg = mainPkg.createPart(secondPartName, "text/plain");
    osW = new OutputStreamWriter(secondPkg.getOutputStream(), "UTF8");
    osW.append("BAR FOO");


    mainPkg = OPCPackage.openOrCreate(testFile);

And yes it failed also with 4.0.
Comment 3 pouponbe 2018-11-12 10:00:53 UTC
Exception in thread "main" org.apache.poi.openxml4j.exceptions.InvalidFormatException: The part /dummy/text.properties does not have any content type ! Rule: Package require content types when retrieving a part from a package. [M.1.14]
	at org.apache.poi.openxml4j.opc.ZipPackage$EntryTriple.register(ZipPackage.java:325)
	at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:293)
	at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:725)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:238)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:167)
	at org.apache.poi.openxml4j.opc.OPCPackage.openOrCreate(OPCPackage.java:322)
	at test.Main.main(Main.java:59)
Comment 4 Dominik Stadler 2019-06-20 08:34:33 UTC
I quickly tried to reproduce this, but could not on latest trunk. 

Which operating system are you running this on?

BTW in your sample, you do not flush/close secondPkg, maybe that is related?
Comment 5 Dominik Stadler 2019-12-15 12:56:36 UTC
*** Bug 62718 has been marked as a duplicate of this bug. ***
Comment 6 Dominik Stadler 2020-10-25 04:58:26 UTC
Could not reproduce and no reply for a long time, thus closing for now, please repoen with more information if this is still a problem for you.