Browse Source

close OPCPackage if there is an exception

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872453 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_4_1_2
PJ Fanning 4 years ago
parent
commit
d8cfe433dd

+ 1
- 1
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java View File

@@ -301,7 +301,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
* OPCPackage pkg = OPCPackage.open(path);
* XSSFWorkbook wb = new XSSFWorkbook(pkg);
* // work with the wb object
* ......
* ......XWPFDocument
* pkg.close(); // gracefully closes the underlying zip file
* </code></pre>
*/

+ 3
- 1
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java View File

@@ -154,8 +154,9 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* Create a new WordProcessingML package and setup the default minimal content
*/
protected static OPCPackage newPackage() {
OPCPackage pkg = null;
try {
OPCPackage pkg = OPCPackage.create(new ByteArrayOutputStream()); // NOSONAR - we do not want to close this here
pkg = OPCPackage.create(new ByteArrayOutputStream()); // NOSONAR - we do not want to close this here
// Main part
PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
// Create main part relationship
@@ -167,6 +168,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {

return pkg;
} catch (Exception e) {
IOUtils.closeQuietly(pkg);
throw new POIXMLException(e);
}
}

Loading…
Cancel
Save