JavacFileManager#setLocationFromPaths only works with the default filesystem

Jonathan Gibbons jonathan.gibbons at oracle.com
Fri Jul 10 21:53:24 UTC 2015


Liam,

Thanks for the feedback.  Obviously the intent is that you should be 
able to use Paths that don't rely on the use of the default filesystem, 
so this needs to be fixed.

-- Jon


On 07/10/2015 02:24 PM, Liam Miller-Cushon wrote:
> I've been using JavacPathFileManager and an in-memory filesystem 
> (github.com/google/jimfs <http://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)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20150710/d19abe25/attachment.html>


More information about the compiler-dev mailing list