JavacTool will fail to work when trying to the compile the file which is not there.
Please see the following code:
<code>
import java.io.*;
import javax.tools.*;
public class Test2 {
public static void test(String... args) {
try{
JavacTool javac = com.sun.tools.javac.Tool.create();
DiagnosticListener dl = new DiagnosticListener() {
public void problemFound(DiagnosticMessage message) {
System.out.println("Source Name :" + new File(message.getSourceName().toString()));
System.out.println("Start position :" + message.getStartPosition());
System.out.println("Position :" + message.getStartPosition());
System.out.println("End position :" + message.getEndPosition());
System.out.flush();
}
};
PrintWriter writer = null;
javac.run((InputLocator)null, null, dl, writer, args);
}catch(Exception ex){
ex.printStackTrace();
}
}
public static void main(String... arg){
try{
Test1 test = new Test1();
test.test("nofile.java");
}catch(Exception ex){
ex.printStackTrace();
}
}
}
<\code>
Ouput of the code :
<output>
bash-2.05b$ $b/java Test2
__input:-1:-1:-1
error: cannot read: nofile.java
<\output>
###@###.### 2005-04-20 09:32:42 GMT
Please see the following code:
<code>
import java.io.*;
import javax.tools.*;
public class Test2 {
public static void test(String... args) {
try{
JavacTool javac = com.sun.tools.javac.Tool.create();
DiagnosticListener dl = new DiagnosticListener() {
public void problemFound(DiagnosticMessage message) {
System.out.println("Source Name :" + new File(message.getSourceName().toString()));
System.out.println("Start position :" + message.getStartPosition());
System.out.println("Position :" + message.getStartPosition());
System.out.println("End position :" + message.getEndPosition());
System.out.flush();
}
};
PrintWriter writer = null;
javac.run((InputLocator)null, null, dl, writer, args);
}catch(Exception ex){
ex.printStackTrace();
}
}
public static void main(String... arg){
try{
Test1 test = new Test1();
test.test("nofile.java");
}catch(Exception ex){
ex.printStackTrace();
}
}
}
<\code>
Ouput of the code :
<output>
bash-2.05b$ $b/java Test2
__input:-1:-1:-1
error: cannot read: nofile.java
<\output>
###@###.### 2005-04-20 09:32:42 GMT
- relates to
-
JDK-6260444 javac sometimes does not use source when it is available
-
- Closed
-