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

JarFile created by URLJarFile is not closed properly

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Issue was also reproduced with Java 1.8.0_221-x64 and Java 11.0.2

      A DESCRIPTION OF THE PROBLEM :
      Given a jar file entry URL
      When closing the InputStream created by a call to URL.openStream API
      Then the close method inherited by the java.util.jar.JarFile created by the JDK is not called
      And an attempt to delete the jar file using Java libraries or Windows Explorer fails with "The process cannot access the file because it is being used by another process."

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      For the below test code, create a the folder D:\temp\jdkbug and copy into it jrt-fs.jar (from the jdk).
      - One can of course change the directories and adapt the code
      - There's a huge chance any jar and any entry of that jar will reproduce the issue


      ---------- BEGIN SOURCE ----------
      import java.io.IOException;
      import java.io.InputStream;
      import java.net.URL;
      import java.nio.file.Files;
      import java.nio.file.Paths;

      public class UrlStreamClose {
          public static void main(String[] args) throws Exception {
              try (InputStream is = new URL("jar:file:D:/temp/jdkbug/jrt-fs.jar!/META-INF/MANIFEST.MF").openStream()) {
                  System.out.println("hello");
              }
              Files.delete(Paths.get("D:\\temp\\jdkbug\\jrt-fs.jar"));
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              michaelm Michael McMahon
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated: