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

URLClassLoader.addURL(URL) adds URLs to closed class loader

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 7
    • Component/s: core-libs
    • Subcomponent:
    • Resolved In Build:
      b64
    • CPU:
      generic
    • OS:
      generic

      Description

      The specification for URLClassLoader.addURL(URL) states:
      "If the URL specified is null or is already in the list of URLs, or if this loader is closed, then invoking this method has no effect."

      However the method successfully adds new url to closed class loader.

      Please see the following minitest:
      ------------------------------------------------------------
      import java.io.IOException;
      import java.net.URL;
      import java.net.URLClassLoader;
      import java.util.Arrays;

      public class addURL_minitest {
          static class CustomURLClassLoader extends URLClassLoader {
              public CustomURLClassLoader(URL[] urls) {
                  super(urls);
              }

              public void addURL(URL url) {
                  super.addURL(url);
              }
          }

          public static void main(String[] args) throws IOException {
              CustomURLClassLoader loader = new CustomURLClassLoader(
                      new URL[] { new URL("file:///a") });

              System.out.println("before close():"
                      + Arrays.toString(loader.getURLs()));
              loader.close();

              loader.addURL(new URL("file:///b"));
              System.out.println("after close() and addURL():"
                      + Arrays.toString(loader.getURLs()));
          }
      }
      ------------------------------------------------------------

      The output is:
      ------------------------------------------------------------
      before close():[file:/a]
      after close() and addURL():[file:/a, file:/b]
      ------------------------------------------------------------

        Attachments

          Activity

            People

            • Assignee:
              michaelm Michael McMahon
              Reporter:
              dmiltsov Dmitry Miltsov (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: