Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4351422

ZipFileInputStreams become invalid when ZipFiles are garbage collected

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • core-libs
    • x86
    • windows_2000



      Name: stC104175 Date: 07/07/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      ZipFileInputStreams do not maintain references to their associated zip files.
      When a ZipFile object gets finalized, it frees up native file structures used
      by the input stream. Here is a program that demonstrates the problem (note that
      the zip file must be relatively large to exhibit this behavior):

      import java.util.zip.ZipFile;
      import java.io.InputStream;
      import java.io.IOException;

      public class ZipFileBug
      {
          public static void main(String[] args) throws IOException {
      InputStream is = getZipStream(args);
      System.gc();
      is.read(); // error occurs here...
          }
          
          private static InputStream getZipStream(String[] args) throws IOException {
      ZipFile zf = new ZipFile(args[0]);
      return zf.getInputStream(zf.getEntry(args[1]));
          }
      }

      the error is:

      java.io.IOException: Bad file descriptor
      at java.util.zip.ZipFile.read(Native Method)
      at java.util.zip.ZipFile.access$700(ZipFile.java:29)
      at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:389)
      at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:402)
      at ZipFileBug.main(ZipFileBug.java:10)
      (Review ID: 105290)
      ======================================================================

            kkladkosunw Konstantin Kladko (Inactive)
            stompkinsunw Sean Tompkins (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: