Bug 59378 - Docx file corruption on write - The part /_rels/.rels does not have any content type
Summary: Docx file corruption on write - The part /_rels/.rels does not have any conte...
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 3.15-dev
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-26 14:42 UTC by Thomas Schwery
Modified: 2016-06-02 20:10 UTC (History)
0 users



Attachments
File corrupted after a write (25.45 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2016-04-26 14:42 UTC, Thomas Schwery
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Schwery 2016-04-26 14:42:51 UTC
Created attachment 33805 [details]
File corrupted after a write

Some docx files that are fine to Word become corrupt after being opened and saved, even without any modifications.

The attached file exhibits this behavior:
- The file can be opened fine with Word
- The file can be opened fine with POI through XWPFDocument
- On save by POI, the file cannot be opened by Word (the error message indicates that the document is corrupt but can be repaired)
- On reopen by POI through XWPFDocument, an InvalidFormatException is thrown

    XWPFDocument doc = new XWPFDocument( [ input file ] );
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    doc.write(out);
    out.close();
    
    XWPFDocument doc2 = new XWPFDocument(new ByteArrayInputStream(out.toByteArray()));

This code throws the following exception:
    org.apache.poi.openxml4j.exceptions.InvalidFormatException: The part /_rels/.rels does not have any content type ! Rule: Package require content types when retrieving a part from a package. [M.1.14]
    org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: The part /_rels/.rels 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.util.PackageHelper.open(PackageHelper.java:39)
            at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:128)
            [...]
    Caused by: org.apache.poi.openxml4j.exceptions.InvalidFormatException: The part /_rels/.rels 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.getPartsImpl(ZipPackage.java:291)
            at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:713)
            at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:296)
            at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
Comment 1 Dominik Stadler 2016-05-19 19:09:02 UTC
I tried to reproduce this, but could not, reading the document, then writing it out and reading back in did work fine. Is there anything else that is involved to make it fail?
Comment 2 Thomas Schwery 2016-05-23 12:11:24 UTC
It now works.

The error was caused by the inclusion in my projects of an old Xalan (2.5) library. Upgrading it to Xalan 2.7 solved the error.

Sorry for the false report.
Comment 3 Dominik Stadler 2016-06-02 20:10:04 UTC
There is now a unit-test via r1746623 which verifies that it stays fixed.