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

Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")

    Details

    • Subcomponent:
    • Resolved In Build:
      b28

      Backports

        Description

        ClassLoaders.toFileURL is called only from hotspot, apparently from appcds.
        It should only be called with a String that is an actual filename, but it gets called with the String "jrt:/java.compiler" which seems wrong. toFileURL canonicalizes the input String, causing undesired risky I/O.

        Recipe:
        Apply a patch to get toFileURL to throw:
        --- a/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java
        +++ b/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java
        @@ -219,6 +219,7 @@
              */
             @Deprecated
             private static URL toFileURL(String s) {
        + if (s.contains(":")) throw new Error("toFileURL(" + s + ")");
                 try {
                     // Use an intermediate File object to construct a URI/URL without
                     // authority component as URLClassPath can't handle URLs with a UNC

        and then
        cd test/hotspot/jtreg
        and run the :hotspot_appcds tests, resulting in 8 failures.
        Here's one:
        TEST: runtime/appcds/jigsaw/overridetests/OverrideTests.java
        ...
         stdout: [];
         stderr: [openjdk version "12-internal" 2019-03-19
        OpenJDK Runtime Environment (build 12-internal+0-adhoc.martinrb.toFileURL)
        OpenJDK 64-Bit Server VM (build 12-internal+0-adhoc.martinrb.toFileURL, mixed mode, sharing)
        Exception in thread "main" java.lang.Error: toFileURL(jrt:/jdk.compiler)
        at java.base/jdk.internal.loader.ClassLoaders.toFileURL(ClassLoaders.java:223)
        at java.base/java.lang.ClassLoader.findLoadedClass0(Native Method)
        at java.base/java.lang.ClassLoader.findLoadedClass(ClassLoader.java:1280)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:595)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:408)
        at test/jdk.test.Main.main(Main.java:73)
        ]
         exitValue = 1

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  jiangli Jiangli Zhou
                  Reporter:
                  martin Martin Buchholz
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  7 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: