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

(sl) ServiceLoader interferes with URLClassLoader.close()

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 7, 8
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      The intent of URLClassLoader.close() is to release all resources opened by the loader, such that any jar files referenced by the URLClassLoader can be deleted. By itself, URLClassLoader now does that, but if you use a URLClassLoader with ServiceLoader, then the ServiceLoader will open additional handles onto any jar files, such that on Windows you can no longer delete jar files after calling URLClassLoader.close.

      This is because URLClassLoader uses private instances of JarFile to access jar files, but ServiceLoader uses ClassLoader.getResources to open service config files, which returns URLs, and ServiceLoader then uses url.openInputStream() which creates and uses instance of URLJarFile, which are /not/ closed when URLClassLoader.close is called.

      URLClassLoader (actually URLClassPath) and ServiceLoader need to coordinate on the handle used to access jar files, such that URLClassLoader can honor its contract to release resources when URLClassLoader.close is called.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                jjg Jonathan Gibbons
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: