close OPCPackage if there is an exception

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872453 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2020-01-07 18:46:11 +00:00
parent e875bd8143
commit d8cfe433dd
2 changed files with 4 additions and 2 deletions

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>
*/

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);
}
}