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

Multi-release jar handling regressed support for non-default filesystems in JavacFileManager

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • None
    • 9
    • tools

      The following example demonstrates that the multi-release jar handling in JavacFileManager does not support paths to jars in non-default filesystems (in this case JimFS).

      Disabling the multi-release jar handling by commenting out the line containing `--multi-release` allows the example to succeed.

      === Test.java
      import com.google.common.jimfs.Jimfs;
      import java.nio.file.FileSystem;
      import java.nio.file.Files;
      import java.nio.file.Path;
      import java.util.Arrays;
      import java.util.EnumSet;
      import java.util.jar.JarEntry;
      import java.util.jar.JarOutputStream;
      import javax.tools.JavaCompiler;
      import javax.tools.JavaFileObject;
      import javax.tools.StandardJavaFileManager;
      import javax.tools.StandardLocation;
      import javax.tools.ToolProvider;

      class Test {

        public static void main(String[] args) throws Exception {
          FileSystem fs = Jimfs.newFileSystem();
          Path foo = fs.getPath("/foo");
          Files.createDirectory(foo);
          Path hello = foo.resolve("hello.jar");
          try (JarOutputStream jos = new JarOutputStream(Files.newOutputStream(hello))) {
            jos.putNextEntry(new JarEntry("Test.class"));
            jos.write(Test.class.getClassLoader().getResourceAsStream("Test.class").readAllBytes());
          }

          JavaCompiler javacTask = ToolProvider.getSystemJavaCompiler();
          StandardJavaFileManager fileManager = javacTask.getStandardFileManager(null, null, null);

          fileManager.handleOption("--multi-release", Arrays.asList("8").iterator());
          fileManager.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, Arrays.asList(hello));
          fileManager.list(
              StandardLocation.PLATFORM_CLASS_PATH, "", EnumSet.allOf(JavaFileObject.Kind.class), true);
        }
      }
      ===

      $ javac -cp jimfs-1.1.jar:guava-23.0.jar Test.java
      $ java -cp .:jimfs-1.1.jar:guava-23.0.jar Test
      Exception in thread "main" java.lang.UnsupportedOperationException
      at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:128)
      at jdk.compiler/com.sun.tools.javac.file.JavacFileManager$ArchiveContainer.<init>(JavacFileManager.java:517)
      at jdk.compiler/com.sun.tools.javac.file.JavacFileManager.getContainer(JavacFileManager.java:319)
      at jdk.compiler/com.sun.tools.javac.file.JavacFileManager.list(JavacFileManager.java:715)
      at Test.main(Test.java:32)

            jlamperth Jonathan Lampérth
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: