JDK-8130944 : JavacFileManager#setLocationFromPaths only works with the default filesystem
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2015-07-10
  • Updated: 2018-02-02
  • Resolved: 2015-08-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
From Liam at Google:


I've been using JavacPathFileManager and an in-memory filesystem (github.com/google/jimfs) for testing some code that uses the compiler API.

I noticed that JDK-8076420 deleted JavacPathFileManager and moved the Path-based methods into the regular JavacFileManager. I think that's great, but I'm having trouble using the Path-based API in JavacFileManager. The implementation uses Path#toFile(), which only works with the default filesystem.

Is this a known issue? JDK-8059976 looks like it would probably fix it.

Repro:

===
import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;

import static java.nio.charset.StandardCharsets.UTF_8;

import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Log;

import java.nio.file.FileSystem;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Locale;

import javax.tools.StandardLocation;

public class Test {
  public static void main(String[] args) throws IOException {
    FileSystem fs = Jimfs.newFileSystem(Configuration.unix());

    Path foo = fs.getPath("/foo");
    Files.createDirectory(foo);
    Path hello = foo.resolve("hello.jar");
    Files.write(hello, Arrays.asList("hello world"), UTF_8);

    Context context = new Context();
    context.put(Log.outKey, new PrintWriter(new OutputStreamWriter(System.err, UTF_8), true));
    JavacFileManager jfm = new JavacFileManager(context, true, UTF_8);

    jfm.setLocationFromPaths(StandardLocation.CLASS_PATH, Arrays.asList(hello));
  }
}
===

$ javac -cp jimfs.jar:javac.jar Test.java
$ java -cp jimfs.jar:javac.jar:guava.jar:. Test
Exception in thread "main" java.lang.UnsupportedOperationException
        at com.google.common.jimfs.JimfsPath.toFile(JimfsPath.java:397)
        at com.sun.tools.javac.file.FSInfo.getJarClassPath(FSInfo.java:69)
        at com.sun.tools.javac.file.Locations$SearchPath.addJarClassPath(Locations.java:321)
        at com.sun.tools.javac.file.Locations$SearchPath.addFile(Locations.java:311)
        at com.sun.tools.javac.file.Locations$SearchPath.addFiles(Locations.java:250)
        at com.sun.tools.javac.file.Locations$SearchPath.addFiles(Locations.java:257)
        at com.sun.tools.javac.file.Locations$SimpleLocationHandler.setLocation(Locations.java:463)
        at com.sun.tools.javac.file.Locations.setLocation(Locations.java:783)
        at com.sun.tools.javac.file.JavacFileManager.setLocationFromPaths(JavacFileManager.java:914)
        at Test.main(Test.java:34)