-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
6u10
-
generic
-
generic
Compile and run test case below ( javac/api/Diagnostic/DiagnosticTest08/DiagnosticTest08.java).
----------------------
import java.util.Arrays;
import javax.tools.*;
// This test for the message kind note.
public class DiagnosticTest08 {
static volatile int passed = 0, failed = 0;
static void pass() { passed++; }
static void fail() { failed++; Thread.dumpStack(); }
static void fail(String msg) { System.out.println(msg); fail(); }
static void unexpected(Throwable t) { failed++; t.printStackTrace(); }
static void check(boolean cond) { if (cond) pass(); else fail(); }
static void equal(Object x, Object y) {
if (x == null ? y == null : x.equals(y)) pass();
else {System.out.println(x + " not equal to " + y); fail(); }}
public static void main(String... arg) throws Throwable {
String javafilename = "DiagnosticTest08.java";
if(arg.length > 0) javafilename = arg[0];
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector dc = new DiagnosticCollector();
StandardJavaFileManager sjfm = javac.getStandardFileManager(null,null,null);
Iterable<? extends JavaFileObject> ite = sjfm.getJavaFileObjects(javafilename);
JavaCompiler.CompilationTask task =
javac.getTask(null,sjfm,dc,null,null,ite);
task.call();
int i=0;
for(Object message : dc.getDiagnostics()) {
Diagnostic d = (Diagnostic)message;
equal(d.getSource().toString(),javafilename); //<=NullPointerException on call to toString()
equal(d.getKind().toString(),"NOTE");
if(i == 0)
equal(d.getCode().toString(),"compiler.note.unchecked.filename");
else equal(d.getCode().toString(),"compiler.note.unchecked.recompile");
equal(d.getColumnNumber(),-1l);
equal(d.getStartPosition(),-1l);
equal(d.getEndPosition(),-1l);
equal(d.getLineNumber(),-1l);
equal(d.getPosition(),-1l);
i++;
}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new Exception("Some tests failed");
}
}
----------------------
import java.util.Arrays;
import javax.tools.*;
// This test for the message kind note.
public class DiagnosticTest08 {
static volatile int passed = 0, failed = 0;
static void pass() { passed++; }
static void fail() { failed++; Thread.dumpStack(); }
static void fail(String msg) { System.out.println(msg); fail(); }
static void unexpected(Throwable t) { failed++; t.printStackTrace(); }
static void check(boolean cond) { if (cond) pass(); else fail(); }
static void equal(Object x, Object y) {
if (x == null ? y == null : x.equals(y)) pass();
else {System.out.println(x + " not equal to " + y); fail(); }}
public static void main(String... arg) throws Throwable {
String javafilename = "DiagnosticTest08.java";
if(arg.length > 0) javafilename = arg[0];
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector dc = new DiagnosticCollector();
StandardJavaFileManager sjfm = javac.getStandardFileManager(null,null,null);
Iterable<? extends JavaFileObject> ite = sjfm.getJavaFileObjects(javafilename);
JavaCompiler.CompilationTask task =
javac.getTask(null,sjfm,dc,null,null,ite);
task.call();
int i=0;
for(Object message : dc.getDiagnostics()) {
Diagnostic d = (Diagnostic)message;
equal(d.getSource().toString(),javafilename); //<=NullPointerException on call to toString()
equal(d.getKind().toString(),"NOTE");
if(i == 0)
equal(d.getCode().toString(),"compiler.note.unchecked.filename");
else equal(d.getCode().toString(),"compiler.note.unchecked.recompile");
equal(d.getColumnNumber(),-1l);
equal(d.getStartPosition(),-1l);
equal(d.getEndPosition(),-1l);
equal(d.getLineNumber(),-1l);
equal(d.getPosition(),-1l);
i++;
}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new Exception("Some tests failed");
}
}
- duplicates
-
JDK-6347778 JSR 199: Diagnostic.getSource() returns null for notes
- Closed