Reputation: 21
A colleague was struggling with the following error when attempting to write to a new xlsx file using Java POI 3.17 APIs
org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save: an error occurs while saving the package : The part /docProps/core.xml failed to be saved in the stream with marshaller org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller@4ae061e
at org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:595)
at org.apache.poi.openxml4j.opc.OPCPackage.save(OPCPackage.java:1539)
at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:227)
The code was able to pass unit tests but failed as part of system tests. I thought I would share my results here
Upvotes: 1
Views: 6025
Reputation: 21
After digging into the POI code I noticed that POI does not re throw the exception in class StreamHelper when it attempts to write the org.w3c.dom.Document object to the OutputStream using transform(Source,Result) A TransformerException is being thrown by the Transformer implementation.
When a DOMSource is used, saxon9-dom.jar must be on the classpath
This is resulting in a False being returned from the the saveXmlInStream method resulting in the OpenXML4JRuntimeException being thrown. I also noted that the unit test was using the JRE 7 Xalan implementation of the Transformer while the system test required Saxon 9. When we introduced the saxon9.jar to the Test case we were able to replicate the error.
We were able to identify the route cause as the 9.1.0.8 implementation of Saxon did not include an implementation for DOMSource. an additional jar saxon9-dom-9.1.0.8.jar was required.
Alternatively use saxon9He.jar (9.3 or Higher) which does have an implement for DOMSource
Upvotes: 1