JavaFileObject of directory should throw IllegalArgumentException , If JavaFileObject is created on directory like javax.tools.JavaCompilerTool.getStandardFileManager().getFileForInput(directory). The DiagnosticMessage is also too much confusing.
<testcase>
import java.io.File;
import java.io.PrintWriter;
import javax.tools.*;
import static javax.tools.JavaFileObject.Kind.*;
class Foo {
public static void main(String[] args) throws Exception {
File dir = new File("temp" + args.hashCode());
if (!dir.exists())
dir.mkdir();
if (!dir.isDirectory())
throw new AssertionError("Not a directory " + dir);
try {
JavaCompilerTool compiler = ToolProvider.defaultJavaCompiler();
JavaFileManager jfm = compiler.getStandardFileManager();
JavaFileObject jfo = jfm.getFileForInput(dir.getName());
for(DiagnosticMessage dm :
compiler.run((PrintWriter)null, jfo).getDiagnostics())
System.out.println(dm);
} catch(Exception ex) {
ex.printStackTrace();
} finally {
dir.delete(); // cleanup
}
}
}
</testcase>
<java-version>
bash-3.00$ java -version
java version "1.6.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-beta-b59b)
Java HotSpot(TM) Client VM (build 1.6.0-beta-b59b, mixed mode)
</java-version>