filemanager option handling and -Xlint:path
Liam Miller-Cushon
cushon at google.com
Mon Oct 24 16:12:04 UTC 2016
-Xlint:path doesn't work when javac is invoked using JSR 199.
The CLI breaks a circular dependency between option handling and
filemanager initialization, but JSR 199 eagerly initializes the filemanager
before xlint options have been processed.
Do you consider this to be a bug? I'm not sure what should happen for
user-supplied filemanagers, but the example below seems fixable:
=== JavacToolDemo.java ===
import javax.tools.JavaCompiler;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
import java.util.Arrays;
public class JavacToolDemo {
public static void main(String[] args) {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager =
compiler.getStandardFileManager(null, null, null);
JavaCompiler.CompilationTask task =
compiler.getTask(
null,
null,
null,
Arrays.asList("-verbose", "-Xlint:path,unchecked", "-cp",
"lib.jar"),
null,
fileManager.getJavaFileObjects("Hello.java"));
System.exit(task.call() ? 0 : 1);
}
}
===
The javac CLI handles -Xlint correctly:
$ echo "class Hello { java.util.List xs; }" > Hello.java
$ echo "Class-Path: NoSuch.jar" > Manifest.txt
$ jar cfm lib.jar Manifest.txt
$ javac -verbose -Xlint:all -cp lib.jar Hello.java
...
[search path for class files: ... NoSuch.jar]
...
warning: [path] bad path element "NoSuch.jar": no such file or directory
Hello.java:1: warning: [rawtypes] found raw type: List
The API does not:
$ javac JavacToolDemo.java
$ java JavacToolDemo
...
[search path for class files: ... NoSuch.jar]
...
Hello.java:1: warning: [rawtypes] found raw type: List
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20161024/43653830/attachment.html>
More information about the compiler-dev
mailing list