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

ModuleReader.find on exploded module throws if resource name maps to invalid file path

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 21
    • 9, 17, 20, 21
    • core-libs
    • None

      An InvalidPathException is thrown by Class.getResource(String) by the following program when launched on Windows using the module path with exploded elements:

      `mod/module-info.java`
      ```
      module mod {}
      ```

      `mod/pac/Main.java`
      ```
        package pac;
        class Main {
          public static void main(String... args) {
            Main.class.getResource("a"); // -> null
            Main.class.getResource(":"); // -> null | InvalidPathException
          }
        }
      ```

      > javac -d classes --module-source-path . --module mod

      > java --module-path classes --module mod/pac.Main
      Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at index 4: pac\:
              at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
              at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
              at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
              at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
              at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:232)
              at java.base/jdk.internal.module.Resources.toSafeFilePath(Resources.java:143)
              at java.base/jdk.internal.module.Resources.toFilePath(Resources.java:97)
              at java.base/jdk.internal.module.ModuleReferences$ExplodedModuleReader.find(ModuleReferences.java:382)
              at java.base/jdk.internal.loader.BuiltinClassLoader.findResource(BuiltinClassLoader.java:497)
              at java.base/jdk.internal.loader.BuiltinClassLoader.findResource(BuiltinClassLoader.java:277)
              at java.base/java.lang.Class.getResource(Class.java:2927)
              at mod/pac.Main.main(Main.java:5)

      A work-around is running the program on the class path:

      > java --class-path classes/mod pac.Main

      Another work-around is to archive the program and run it on the module path:

      > jar --create --file mod.jar -C classes/mod .

      > java --module-path mod.jar --module mod/pac.Main

            alanb Alan Bateman
            cstein Christian Stein
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: