aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2020-01-07 18:46:11 +0000
committerPJ Fanning <fanningpj@apache.org>2020-01-07 18:46:11 +0000
commitd8cfe433dd82789916ef546d73dfcd712523336d (patch)
tree19317a0c3c54ca30562ad8d11d4095a16e3d710b /src
parente875bd81435bc7627e4eab9a18490583d2cee604 (diff)
downloadpoi-d8cfe433dd82789916ef546d73dfcd712523336d.tar.gz
poi-d8cfe433dd82789916ef546d73dfcd712523336d.zip
close OPCPackage if there is an exception
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872453 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java2
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java4
2 files changed, 4 insertions, 2 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index c57db95506..38fe4e4df5 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -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>
*/
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
index 5313ea735a..4c9796871d 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
@@ -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);
}
}