Bug 62717 - Content type of parts could not always be saved
Summary: Content type of parts could not always be saved
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: OPC (show other bugs)
Version: 3.17-FINAL
Hardware: All All
: P2 regression (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-13 16:45 UTC by pouponbe
Modified: 2018-11-12 10:00 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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");
    osW.append("FOO");
    osW.flush();
    osW.close();
    firstPkg.flush();
    firstPkg.close();

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

    mainPkg.close();

    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)