Uploaded image for project: 'Commons Compress'
  1. Commons Compress
  2. COMPRESS-297

Cleaning up unclosed ZipFile for archive

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.8.1
    • 1.10
    • Archivers
    • None
    • Windows 7 64-bit

    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:

      TCommonCompressZipFileConstructor.java
      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

      Attachments

        Activity

          People

            Unassigned Unassigned
            aliu Andrew Liu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: