summaryrefslogtreecommitdiffstats
path: root/poi-ooxml
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2023-10-15 21:06:01 +0000
committerPJ Fanning <fanningpj@apache.org>2023-10-15 21:06:01 +0000
commitedef04dce7e8d3afb2fa3ea04e245c114a26dcb4 (patch)
tree9135c4820989d06ea30cca2443d453d8c0c7d23d /poi-ooxml
parentdbddc32c1bd2a8d5aef823949e2f58b4f4689750 (diff)
downloadpoi-edef04dce7e8d3afb2fa3ea04e245c114a26dcb4.tar.gz
poi-edef04dce7e8d3afb2fa3ea04e245c114a26dcb4.zip
try harder to close zipArchive in ZipPackage (edge cases)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912986 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java21
1 files changed, 17 insertions, 4 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
index dce58c7169..cf0202e3ad 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
@@ -458,22 +458,35 @@ public final class ZipPackage extends OPCPackage {
@Override
protected void closeImpl() throws IOException {
// Flush the package
- flush();
+ try {
+ flush();
+ } catch (RuntimeException|Error e) {
+ IOUtils.closeQuietly(zipArchive);
+ throw e;
+ }
if (this.originalPackagePath == null || this.originalPackagePath.isEmpty()) {
+ IOUtils.closeQuietly(zipArchive);
return;
}
// Save the content
File targetFile = new File(this.originalPackagePath);
if (!targetFile.exists()) {
+ IOUtils.closeQuietly(zipArchive);
throw new InvalidOperationException(
"Can't close a package not previously open with the open() method !");
}
// Case of a package previously open
- String tempFileName = generateTempFileName(FileHelper.getDirectory(targetFile));
- File tempFile = TempFile.createTempFile(tempFileName, ".tmp");
+ File tempFile;
+ try {
+ String tempFileName = generateTempFileName(FileHelper.getDirectory(targetFile));
+ tempFile = TempFile.createTempFile(tempFileName, ".tmp");
+ } catch (IOException|RuntimeException|Error e) {
+ IOUtils.closeQuietly(zipArchive);
+ throw e;
+ }
// Save the final package to a temporary file
boolean success = false;
@@ -482,7 +495,7 @@ public final class ZipPackage extends OPCPackage {
success = true;
} finally {
// Close the current zip file, so we can overwrite it on all platforms
- IOUtils.closeQuietly(this.zipArchive);
+ IOUtils.closeQuietly(zipArchive);
try {
// Copy the new file over the old one if save() succeed
if(success) {