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

URLClassLoader.getResourceAsStream locks jar files

XMLWordPrintable

    • x86
    • windows_xp

      To reproduce the problem, on a Windows machine, create a test.jar, and run the following test case in jdb. Stop at the first println, "test.jar" is now locked and cannot be deleted.

      Note that the test is only trying to get a non-existant resource. Note also that this is only a problem for the Windows platform.

      This bug breaks an important functionality in AppServer, because it makes undeployment of a web applications impossible (in Windows), because jar files in it cannot be deleted. See bug 5004315. There does not seems to be any workarounds.

      % cat Test.java
      import java.io.*;
      import java.net.*;

      class Test {
          public static void main(String args[]) {

              try {
                  File jarf = (new File("test.jar")).getCanonicalFile();
                  URL urls[] = { jarf.toURL() };
                  URLClassLoader loader =
                      new URLClassLoader(urls, Test.class.getClassLoader());
                  InputStream is = loader.getResourceAsStream("BadName");
                  System.out.println("stream is " + is);
              } catch (Exception ex) {
                  System.out.println("Error: " + ex);
              }
          }
      }


      ###@###.### 2004-04-30

            michaelm Michael McMahon
            kichung Kinman Chung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: