diff --git a/WHATSNEW b/WHATSNEW index 8077debb4..51f4ab55b 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -331,6 +331,11 @@ Fixed bugs: * resource collection kept only one of entries deemed equal by the chosen Comparator. Bugzilla report 46527. + * the ZipFile class used by and others could leave the + archive open (making it undeletable on Windows as long as the java + VM was running) for files with an unexpected internal structure. + Bugzilla Report 46559. + Other changes: -------------- diff --git a/src/main/org/apache/tools/zip/ZipFile.java b/src/main/org/apache/tools/zip/ZipFile.java index feed30d01..6a85f770a 100644 --- a/src/main/org/apache/tools/zip/ZipFile.java +++ b/src/main/org/apache/tools/zip/ZipFile.java @@ -150,16 +150,19 @@ public class ZipFile { public ZipFile(File f, String encoding) throws IOException { this.encoding = encoding; archive = new RandomAccessFile(f, "r"); + boolean success = false; try { populateFromCentralDirectory(); resolveLocalFileHeaderData(); - } catch (IOException e) { - try { - archive.close(); - } catch (IOException e2) { - // swallow, throw the original exception instead + success = true; + } finally { + if (!success) { + try { + archive.close(); + } catch (IOException e2) { + // swallow, throw the original exception instead + } } - throw e; } } diff --git a/src/tests/antunit/taskdefs/unzip-test.xml b/src/tests/antunit/taskdefs/unzip-test.xml index cb4af6be5..ed75de469 100644 --- a/src/tests/antunit/taskdefs/unzip-test.xml +++ b/src/tests/antunit/taskdefs/unzip-test.xml @@ -43,4 +43,18 @@ dest="${output}"/> + + + + + + + + + + + + diff --git a/src/tests/antunit/taskdefs/zip/Bugzilla-42940.zip b/src/tests/antunit/taskdefs/zip/Bugzilla-42940.zip new file mode 100644 index 000000000..2f7566082 Binary files /dev/null and b/src/tests/antunit/taskdefs/zip/Bugzilla-42940.zip differ diff --git a/src/tests/antunit/taskdefs/zip/Bugzilla-46559.zip b/src/tests/antunit/taskdefs/zip/Bugzilla-46559.zip new file mode 100644 index 000000000..2f7566082 Binary files /dev/null and b/src/tests/antunit/taskdefs/zip/Bugzilla-46559.zip differ