]> source.dussan.org Git - poi.git/commitdiff
Use revert() instead of close() when processing fails
authorDominik Stadler <centic@apache.org>
Sat, 16 Dec 2023 12:08:54 +0000 (12:08 +0000)
committerDominik Stadler <centic@apache.org>
Sat, 16 Dec 2023 12:08:54 +0000 (12:08 +0000)
Otherwise we might write partial changes to the
underlying file which is unexpected.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1914706 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java

index e99f8ff00860a60bc45f779a35a7b2f97fac1ac1..c83ccfcaaa87e4eb772354ae4c8da607b1299ac1 100644 (file)
@@ -746,7 +746,7 @@ public class POIXMLDocumentPart {
             if (coreRel != null) {
                 PackagePart pp = pkg.getPart(coreRel);
                 if (pp == null) {
-                    IOUtils.closeQuietly(pkg);
+                    pkg.revert();
                     throw new POIXMLException("OOXML file structure broken/invalid - core document '" + coreRel.getTargetURI() + "' not found.");
                 }
                 return pp;
@@ -754,16 +754,16 @@ public class POIXMLDocumentPart {
 
             coreRel = pkg.getRelationshipsByType(PackageRelationshipTypes.STRICT_CORE_DOCUMENT).getRelationship(0);
             if (coreRel != null) {
-                IOUtils.closeQuietly(pkg);
+                pkg.revert();
                 throw new POIXMLException("Strict OOXML isn't currently supported, please see bug #57699");
             }
 
-            IOUtils.closeQuietly(pkg);
+            pkg.revert();
             throw new POIXMLException("OOXML file structure broken/invalid - no core document found!");
         } catch (POIXMLException e) {
             throw e;
         } catch (RuntimeException e) {
-            IOUtils.closeQuietly(pkg);
+            pkg.revert();
             throw new POIXMLException("OOXML file structure broken/invalid", e);
         }
     }