[ 
https://issues.apache.org/jira/browse/COMPRESS-297?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14272680#comment-14272680
 ] 

Dawid Weiss commented on COMPRESS-297:
--------------------------------------

That close field should be declared volatile since finalize is invoked from a 
system thread and the write may not propagate properly.

> 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
>             Fix For: 1.10
>
>
> 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)

Reply via email to