aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2020-01-03 11:27:01 +0000
committerPJ Fanning <fanningpj@apache.org>2020-01-03 11:27:01 +0000
commit578d78da37fd4b2035e865d746e40471f417c116 (patch)
tree84155111b3cfda1495936e52a7400ae4a05d6c59 /src
parent4a7aee8b1fe32075792ef467d07e42cd950035ce (diff)
downloadpoi-578d78da37fd4b2035e865d746e40471f417c116.tar.gz
poi-578d78da37fd4b2035e865d746e40471f417c116.zip
[bug-64045] close resources if we throw exceptions
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872284 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java b/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java
index d329d44a3f..7d3bcc40a9 100644
--- a/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java
+++ b/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java
@@ -759,7 +759,7 @@ public class POIXMLDocumentPart {
/**
* Retrieves the core document part
*
- * @since POI 3.14-Beta1
+ * Since POI 4.1.2 - pkg is closed if this method throws an exception
*/
private static PackagePart getPartFromOPCPackage(OPCPackage pkg, String coreDocumentRel) {
PackageRelationship coreRel = pkg.getRelationshipsByType(coreDocumentRel).getRelationship(0);
@@ -767,6 +767,7 @@ public class POIXMLDocumentPart {
if (coreRel != null) {
PackagePart pp = pkg.getPart(coreRel);
if (pp == null) {
+ IOUtils.closeQuietly(pkg);
throw new POIXMLException("OOXML file structure broken/invalid - core document '" + coreRel.getTargetURI() + "' not found.");
}
return pp;
@@ -778,6 +779,7 @@ public class POIXMLDocumentPart {
throw new POIXMLException("Strict OOXML isn't currently supported, please see bug #57699");
}
+ IOUtils.closeQuietly(pkg);
throw new POIXMLException("OOXML file structure broken/invalid - no core document found!");
}
}