Andrew Liu created COMPRESS-297:
-----------------------------------
Summary: Cleaning up unclosed ZipFile for archive
Key: COMPRESS-297
URL: https://issues.apache.org/jira/browse/COMPRESS-297
Project: Commons Compress
Issue Type: Bug
Components: Archivers
Affects Versions: 1.8.1
Environment: Windows 7 64-bit
Reporter: Andrew Liu
Priority: Minor
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:
{code:title=TCommonCompressZipFileConstructor.java|borderStyle=solid}
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();
}
}
}
{code}
And here is the test output:
{color:red}
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*
{color}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)