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

Class loading failure due to archived map issue in ModuleLoaderMap.Mapper

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 24
    • None
    • core-libs
    • None
    • b22

      [~cushon] reported a strange class loader issue with recent JDK mainline change. Below is a test case constructed by [~cushon] for demonstrating the issue:

      ```
      import java.util.List;

      class LoadJavacClassTest {
        public static void main(String[] args) throws Exception {
          for (var c :
              List.of(
                  "com.sun.tools.javac.processing.JavacProcessingEnvironment")) {
            var cl = ClassLoader.getSystemClassLoader().loadClass(c).getClassLoader();
            System.err.printf("%s loaded from %s\n", c, cl);
            if (cl == null) {
              throw new AssertionError();
            }
          }
        }
      }
      ```
      com.sun.tools.javac.processing.JavacProcessingEnvironment is provided by jdk.compiler module and should be loaded by the PlatformClassLoader.

      Running with `java -cp <path> LoadJavacClassTest`, the test works as expected.

      When running the test with extra `--enable-native-access=ALL-UNNAMED -Djava.lang.Integer.IntegerCache.high=3000`, it fails to load the class JavacProcessingEnvironment.

      When running with `--enable-native-access=ALL-UNNAMED -Djava.lang.Integer.IntegerCache.high=3000` and with `-Xshare:off` to disable the default CDS, the test works ok.

      I investigated the issue and found it's caused by the archived map in ModuleLoaderMap.Mapper. Will provide details in additional comments.

            jiangli Jiangli Zhou
            jiangli Jiangli Zhou
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: