Description
If you try to create a ZipFile from a non-existent file, then it throws a FileNotFoundException, which is fine. The problem is that the constructor appears to leave behind objects that the caller cannot close. So, later on when the garbage collector runs, a message is printed to stdout that says "Cleaning up unclosed ZipFile for archive". Here is a failing unit test:
import org.apache.commons.compress.archivers.zip.ZipFile; import org.junit.Test; import java.io.File; import java.io.IOException; public final class TCommonCompressZipFileConstructor { @Test public void constructorThatThrowsExceptionLeavesBehindObjects() { final File file = new File(""); try { new ZipFile(file); } catch (final IOException e) { e.printStackTrace(); System.gc(); } } }
And here is the test output:
java.io.FileNotFoundException:
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:241)
at org.apache.commons.compress.archivers.zip.ZipFile.<init>(ZipFile.java:213)
at org.apache.commons.compress.archivers.zip.ZipFile.<init>(ZipFile.java:192)
at org.apache.commons.compress.archivers.zip.ZipFile.<init>(ZipFile.java:153)
at com.mathworks.mlwidgets.explorer.unittest.TCommonCompressZipFileConstructor.constructorThatThrowsExceptionLeavesBehindObjects(TCommonCompressZipFileConstructor.java:14)
...
com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Cleaning up unclosed ZipFile for archive L:\IntelliJ projects\foo