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

Can' t delete zip files accessed with jar protocol

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u10
    • core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_20"
      Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
      Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      I can't delete a zip file where I read an entry with the jar protocol.

      This bug is probably the same as bug #5041014 but adding a close() method to URLClassLoader described in that bug won't solve this bug.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the following test case:

      import java.io.*;
      import java.net.URL;
      import java.util.UUID;
      import java.util.zip.*;

      public class ZipFileDeleteTest {
         public static void main(String[] args) throws IOException {
             // Create a zip file
             File testFile = new File(UUID.randomUUID().toString() + ".zip");
             // Write an entry in the zip file
             ZipOutputStream out = new ZipOutputStream(new FileOutputStream(testFile));
             out.putNextEntry(new ZipEntry("test"));
             out.write('a');
             out.closeEntry();
             out.close();
             // Access to the entry with jar: protocol
             URL url = new URL("jar:" + testFile.toURI().toURL() + "!/test");
             InputStream in = url.openStream();
             in.read();
             in.close();
             // Try to delete the zip file
             System.out.println(testFile.delete());
         }
      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected the program would display "true"
      ACTUAL -
      The program displayed "false" meaning the file wasn't deleted.
      Under Mac OS X and Linux, it displays "true" as expected.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import java.net.URL;
      import java.util.UUID;
      import java.util.zip.*;

      public class ZipFileDeleteTest {
         public static void main(String[] args) throws IOException {
             // Create a zip file
             File testFile = new File(UUID.randomUUID().toString() + ".zip");
             // Write an entry in the zip file
             ZipOutputStream out = new ZipOutputStream(new FileOutputStream(testFile));
             out.putNextEntry(new ZipEntry("test"));
             out.write('a');
             out.closeEntry();
             out.close();
             // Access to the entry with jar: protocol
             URL url = new URL("jar:" + testFile.toURI().toURL() + "!/test");
             InputStream in = url.openStream();
             in.read();
             in.close();
             // Try to delete the zip file
             System.out.println(testFile.delete());
         }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Probably, not using jar protocol, or using a URLStreamHandler that changes the existing behavior of sun.net.www.protocol.jar.Handler class.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: