commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stefan Bodewig (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (COMPRESS-297) Cleaning up unclosed ZipFile for archive
Date Mon, 22 Dec 2014 16:34:13 GMT

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

Stefan Bodewig commented on COMPRESS-297:
-----------------------------------------

The log message you see is ZipFile's finalize method which looks at the closed flag - which
is false by default and is not set to false in case of an error in RandomAccessFile's constructor.
 So what you see is - fortunately - not a resource leak but just a bad log statement.  Will
be fixed in trunk in a few seconds.

> 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)

Mime
View raw message