Use revert() instead of close() when processing fails

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
This commit is contained in:
Dominik Stadler 2023-12-16 12:08:54 +00:00
parent 4b84986671
commit ffc4795258
1 changed files with 4 additions and 4 deletions

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