8341778: Some javac tests ignore the result of JavacTask::call

Reviewed-by: shade
This commit is contained in:
Vicente Romero 2025-06-06 14:11:27 +00:00
parent 9658cecde3
commit 8adb052b46
33 changed files with 135 additions and 48 deletions

View File

@ -187,7 +187,9 @@ public class GenClassPoolJar {
StandardJavaFileManager sjfm = compiler.getStandardFileManager(null, null, null); StandardJavaFileManager sjfm = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> fileObjects = sjfm.getJavaFileObjects(files); Iterable<? extends JavaFileObject> fileObjects = sjfm.getJavaFileObjects(files);
JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, optionList, null, fileObjects); JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, optionList, null, fileObjects);
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
sjfm.close(); sjfm.close();
} }

View File

@ -87,7 +87,9 @@ public class T6358024 extends AbstractProcessor {
Arrays.asList(f)); Arrays.asList(f));
MyTaskListener tl = new MyTaskListener(); MyTaskListener tl = new MyTaskListener();
task.setTaskListener(tl); task.setTaskListener(tl);
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
if (tl.started != expect) if (tl.started != expect)
throw new AssertionError("Unexpected number of TaskListener events; " throw new AssertionError("Unexpected number of TaskListener events; "
+ "expected " + expect + ", found " + tl.started); + "expected " + expect + ", found " + tl.started);

View File

@ -75,7 +75,9 @@ public class T6358166 extends AbstractProcessor {
JavacTool tool = JavacTool.create(); JavacTool tool = JavacTool.create();
JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, fm, null, allArgs, null, List.of(f), context); JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, fm, null, allArgs, null, List.of(f), context);
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
JavaCompiler c = JavaCompiler.instance(context); JavaCompiler c = JavaCompiler.instance(context);
if (c.errorCount() != 0) if (c.errorCount() != 0)

View File

@ -50,7 +50,8 @@ public class T6361619 extends AbstractProcessor {
final PrintWriter out = new PrintWriter(System.err, true); final PrintWriter out = new PrintWriter(System.err, true);
Iterable<String> flags = Arrays.asList("-processorpath", testClassDir, Iterable<String> flags = Arrays.asList("--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"-processorpath", testClassDir,
"-processor", self, "-processor", self,
"-d", "."); "-d", ".");
DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() { DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() {
@ -69,7 +70,9 @@ public class T6361619 extends AbstractProcessor {
task.setTaskListener(tl); task.setTaskListener(tl);
// should complete, without exceptions // should complete, without exceptions
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
} }
} }

View File

@ -63,7 +63,9 @@ public class T6395974 {
MyTaskListener tl = new MyTaskListener(); MyTaskListener tl = new MyTaskListener();
task.setTaskListener(tl); task.setTaskListener(tl);
task.call(); if (task.call()) {
throw new AssertionError("test compilation was expected to fail");
}
} }
} }

View File

@ -56,6 +56,7 @@ public class T6397286 {
}); });
try { try {
// no need to check the result of JavacTask::call, reevaluate if the test is modified
task.call(); task.call();
throw new AssertionError("no exception thrown"); throw new AssertionError("no exception thrown");
} catch (RuntimeException e) { } catch (RuntimeException e) {

View File

@ -66,7 +66,9 @@ public class T6458823 {
files.add(new File(T6458823.class.getResource("TestClass.java").toURI())); files.add(new File(T6458823.class.getResource("TestClass.java").toURI()));
final CompilationTask task = compiler.getTask(null, fm, diagColl, final CompilationTask task = compiler.getTask(null, fm, diagColl,
options, null, fm.getJavaFileObjectsFromFiles(files)); options, null, fm.getJavaFileObjectsFromFiles(files));
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
int diagCount = 0; int diagCount = 0;
for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) { for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
if (diag.getKind() != Diagnostic.Kind.WARNING) { if (diag.getKind() != Diagnostic.Kind.WARNING) {

View File

@ -76,7 +76,9 @@ public class TwrAvoidNullCheck {
DumpLower.preRegister(ctx); DumpLower.preRegister(ctx);
Iterable<ToolBox.JavaSource> files = Arrays.asList(new ToolBox.JavaSource(code)); Iterable<ToolBox.JavaSource> files = Arrays.asList(new ToolBox.JavaSource(code));
JavacTask task = JavacTool.create().getTask(null, null, null, null, null, files, ctx); JavacTask task = JavacTool.create().getTask(null, null, null, null, null, files, ctx);
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
boolean hasNullCheck = ((DumpLower) DumpLower.instance(ctx)).hasNullCheck; boolean hasNullCheck = ((DumpLower) DumpLower.instance(ctx)).hasNullCheck;

View File

@ -89,7 +89,9 @@ public class TwrSimpleClose {
JFMImpl fm = new JFMImpl(sfm)) { JFMImpl fm = new JFMImpl(sfm)) {
Iterable<ToolBox.JavaSource> files = Arrays.asList(new ToolBox.JavaSource(code)); Iterable<ToolBox.JavaSource> files = Arrays.asList(new ToolBox.JavaSource(code));
JavacTask task = (JavacTask) compiler.getTask(null, fm, null, null, null, files); JavacTask task = (JavacTask) compiler.getTask(null, fm, null, null, null, files);
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
if (fm.classBytes.size() != 1) { if (fm.classBytes.size() != 1) {
throw new AssertionError(); throw new AssertionError();

View File

@ -90,7 +90,9 @@ public class T6406133 extends ToolTester {
task = tool.getTask(pw, fm, listener, null, null, compilationUnits); task = tool.getTask(pw, fm, listener, null, null, compilationUnits);
task.setProcessors(Arrays.asList(processor)); task.setProcessors(Arrays.asList(processor));
task.setLocale(locale); //6443132 task.setLocale(locale); //6443132
task.call(); if (task.call()) {
throw new AssertionError("test compilation was expected to fail");
}
if (!processor.locale.equals(locale)) if (!processor.locale.equals(locale))
throw new AssertionError("Error in diagnostic localization during annotation processing"); throw new AssertionError("Error in diagnostic localization during annotation processing");
String res = useListener ? listener.result : pw.toString(); String res = useListener ? listener.result : pw.toString();

View File

@ -53,6 +53,7 @@ public class T6410643 extends ToolTester {
void test(String... args) { void test(String... args) {
task = tool.getTask(null, null, null, null, null, null); task = tool.getTask(null, null, null, null, null, null);
try { try {
// no need to check the result of JavacTask::call, reevaluate if the test is modified
task.call(); task.call();
throw new AssertionError("Error expected"); throw new AssertionError("Error expected");
} catch (IllegalStateException e) { } catch (IllegalStateException e) {

View File

@ -47,7 +47,9 @@ public class T6412656 extends ToolTester {
task = tool.getTask(null, fm, null, null, task = tool.getTask(null, fm, null, null,
Collections.singleton(T6412656.class.getName()), null); Collections.singleton(T6412656.class.getName()), null);
task.setProcessors(Collections.singleton(new MyProc(this))); task.setProcessors(Collections.singleton(new MyProc(this)));
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
if (count == 0) if (count == 0)
throw new AssertionError("Annotation processor not run"); throw new AssertionError("Annotation processor not run");
System.out.println("OK"); System.out.println("OK");

View File

@ -41,11 +41,12 @@ public class T6423003 extends ToolTester {
void test(String... args) { void test(String... args) {
task = tool.getTask(null, fm, null, Arrays.asList("-Xlint:all"), null, null); task = tool.getTask(null, fm, null, Arrays.asList("-Xlint:all"), null, null);
try { try {
// no need to check the result of JavacTask::call, reevaluate if the test is modified
task.call(); task.call();
throw new AssertionError("Expected IllegalStateException not thrown");
} catch (IllegalStateException ex) { } catch (IllegalStateException ex) {
return; return;
} }
throw new AssertionError("Expected IllegalStateException not thrown");
} }
public static void main(String... args) throws IOException { public static void main(String... args) throws IOException {
try (T6423003 t = new T6423003()) { try (T6423003 t = new T6423003()) {

View File

@ -93,7 +93,9 @@ public class T6731573 extends ToolTester {
if (sourceLine.optValue != null) if (sourceLine.optValue != null)
options.add(sourceLine.optValue); options.add(sourceLine.optValue);
task = tool.getTask(pw, fm, null, options, null, compilationUnits); task = tool.getTask(pw, fm, null, options, null, compilationUnits);
task.call(); if (task.call()) {
throw new AssertionError("test compilation was expected to fail");
}
checkErrorLine(pw.toString(), checkErrorLine(pw.toString(),
diagType.shouldDisplaySource(sourceLine), diagType.shouldDisplaySource(sourceLine),
options); options);

View File

@ -71,7 +71,9 @@ public class T7086261 {
try (JavaFileManager jfm = javac.getStandardFileManager(null, null, null)) { try (JavaFileManager jfm = javac.getStandardFileManager(null, null, null)) {
JavaCompiler.CompilationTask task = JavaCompiler.CompilationTask task =
javac.getTask(null, jfm, new DiagnosticChecker(), null, null, Arrays.asList(new ErroneousSource())); javac.getTask(null, jfm, new DiagnosticChecker(), null, null, Arrays.asList(new ErroneousSource()));
task.call(); if (task.call()) {
throw new AssertionError("test compilation was expected to fail");
}
} }
} }

View File

@ -38,6 +38,7 @@
import java.io.File; import java.io.File;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Set; import java.util.Set;
import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.RoundEnvironment;
@ -75,6 +76,12 @@ public class Test {
} }
} }
static final List<String> OPTIONS = List.of(
"--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED");
PrintWriter out; PrintWriter out;
int errors; int errors;
@ -102,10 +109,12 @@ public class Test {
Iterable<? extends JavaFileObject> files, PrintWriter out, Iterable<? extends JavaFileObject> files, PrintWriter out,
int expectedDocComments) { int expectedDocComments) {
out.println("Test annotation processor"); out.println("Test annotation processor");
JavacTask task = javac.getTask(out, fm, null, null, null, files); JavacTask task = javac.getTask(out, fm, null, OPTIONS, null, files);
AnnoProc ap = new AnnoProc(DocTrees.instance(task)); AnnoProc ap = new AnnoProc(DocTrees.instance(task));
task.setProcessors(Arrays.asList(ap)); task.setProcessors(Arrays.asList(ap));
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
ap.checker.checkDocComments(expectedDocComments); ap.checker.checkDocComments(expectedDocComments);
} }
@ -113,10 +122,12 @@ public class Test {
Iterable<? extends JavaFileObject> files, PrintWriter out, Iterable<? extends JavaFileObject> files, PrintWriter out,
int expectedDocComments) { int expectedDocComments) {
out.println("Test task listener"); out.println("Test task listener");
JavacTask task = javac.getTask(out, fm, null, null, null, files); JavacTask task = javac.getTask(out, fm, null, OPTIONS, null, files);
TaskListnr tl = new TaskListnr(DocTrees.instance(task)); TaskListnr tl = new TaskListnr(DocTrees.instance(task));
task.addTaskListener(tl); task.addTaskListener(tl);
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
tl.checker.checkDocComments(expectedDocComments); tl.checker.checkDocComments(expectedDocComments);
} }

View File

@ -72,7 +72,8 @@ public class DiagSpans extends TestRunner {
} }
""", """,
'/', '/',
'^'); '^',
false);
} }
@Test @Test
@ -87,7 +88,8 @@ public class DiagSpans extends TestRunner {
} }
""", """,
'/', '/',
'^'); '^',
false);
} }
@Test @Test
@ -102,7 +104,8 @@ public class DiagSpans extends TestRunner {
} }
""", """,
'/', '/',
'^'); '^',
false);
} }
@Test @Test
@ -118,7 +121,8 @@ public class DiagSpans extends TestRunner {
} }
""", """,
'/', '/',
'^'); '^',
false);
} }
@Test @Test
@ -134,7 +138,8 @@ public class DiagSpans extends TestRunner {
} }
""", """,
'/', '/',
'^'); '^',
false);
} }
@Test @Test
@ -158,7 +163,8 @@ public class DiagSpans extends TestRunner {
class Sub2 extends Base2 {} class Sub2 extends Base2 {}
""", """,
'/', '/',
'^'); '^',
true);
} }
@Test @Test
@ -175,7 +181,8 @@ public class DiagSpans extends TestRunner {
class Sub1 extends Base1 {} class Sub1 extends Base1 {}
""", """,
'/', '/',
'^'); '^',
false);
} }
@Test @Test
@ -192,10 +199,11 @@ public class DiagSpans extends TestRunner {
class Sub1 extends Base1 {} class Sub1 extends Base1 {}
""", """,
'/', '/',
'^'); '^',
false);
} }
private void runDiagSpanTest(String code, char spanMarker, char prefMarker) throws Exception { private void runDiagSpanTest(String code, char spanMarker, char prefMarker, boolean succCompilationExpected) throws Exception {
var realCode = new StringBuilder(); var realCode = new StringBuilder();
var expectedError = new ArrayList<String>(); var expectedError = new ArrayList<String>();
int startPos = -1; int startPos = -1;
@ -238,7 +246,9 @@ public class DiagSpans extends TestRunner {
}; };
var sourceFiles = List.of(new JFOImpl(realCode.toString())); var sourceFiles = List.of(new JFOImpl(realCode.toString()));
var task = compiler.getTask(null, null, dl, null, null, sourceFiles); var task = compiler.getTask(null, null, dl, null, null, sourceFiles);
task.call(); if (task.call() != succCompilationExpected) {
throw new AssertionError("unexpected compilation result");
}
if (!Objects.equals(expectedError, actualErrors)) { if (!Objects.equals(expectedError, actualErrors)) {
throw new AssertionError("Expected error spans not found, expected: " + throw new AssertionError("Expected error spans not found, expected: " +
expectedError + ", actual: " + actualErrors); expectedError + ", actual: " + actualErrors);

View File

@ -53,7 +53,9 @@ public class T6357331
public void finished(TaskEvent e) { } public void finished(TaskEvent e) { }
}); });
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
// now the compilation is over, we expect IllegalStateException (not NPE) // now the compilation is over, we expect IllegalStateException (not NPE)
try { try {

View File

@ -116,7 +116,9 @@ public class TestTreePath extends AbstractProcessor {
null, null, null, null, null, null,
Arrays.asList("-processor", this.getClass().getName()), null, Arrays.asList("-processor", this.getClass().getName()), null,
tests); tests);
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
} }
} }

View File

@ -79,7 +79,9 @@ public class EventsBalancedTest {
task.setTaskListener(listener); task.setTaskListener(listener);
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
for (Entry<Kind, Integer> e : listener.kind2Count.entrySet()) { for (Entry<Kind, Integer> e : listener.kind2Count.entrySet()) {
if (e.getValue() != null && e.getValue() != 0) { if (e.getValue() != null && e.getValue() != 0) {

View File

@ -76,7 +76,9 @@ public class ImproveFatalErrorHandling extends TestRunner {
.getSystemJavaCompiler() .getSystemJavaCompiler()
.getTask(null, null, null, null, null, files); .getTask(null, null, null, null, null, files);
Context context = task.getContext(); Context context = task.getContext();
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
JavaCompiler compiler = context.get(compilerKey); JavaCompiler compiler = context.get(compilerKey);
compiler.closeables = com.sun.tools.javac.util.List.of( compiler.closeables = com.sun.tools.javac.util.List.of(
new CloseException1(), new CloseException2(), new CloseException1(), new CloseException2(),

View File

@ -1602,7 +1602,9 @@ public class DPrinter {
} }
}); });
task.call(); if (!task.call()) {
throw new AssertionError("compilation failed at DPrinter.Main::run");
}
} }
TaskEvent.Kind getKind(String s) { TaskEvent.Kind getKind(String s) {

View File

@ -359,7 +359,9 @@ public class QueryBeforeEnter extends ModuleTestBase {
"-Xplugin:test"), "-Xplugin:test"),
null, null,
fm.getJavaFileObjects(testSource)); fm.getJavaFileObjects(testSource));
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
} }
Main.compile(new String[] {"--processor-path", processorPath, Main.compile(new String[] {"--processor-path", processorPath,

View File

@ -34,7 +34,7 @@ import javax.tools.*;
public class SOEDeeplyNestedBlocksTest { public class SOEDeeplyNestedBlocksTest {
static final int NESTING_DEPTH = 1000; static final int NESTING_DEPTH = 500;
public static void main(String... args) { public static void main(String... args) {
var lines = new ArrayList<String>(); var lines = new ArrayList<String>();
@ -48,7 +48,9 @@ public class SOEDeeplyNestedBlocksTest {
var source = SimpleJavaFileObject.forSource(URI.create("mem://Test.java"), String.join("\n", lines)); var source = SimpleJavaFileObject.forSource(URI.create("mem://Test.java"), String.join("\n", lines));
var compiler = ToolProvider.getSystemJavaCompiler(); var compiler = ToolProvider.getSystemJavaCompiler();
var task = compiler.getTask(null, null, noErrors, null, null, List.of(source)); var task = compiler.getTask(null, null, noErrors, null, null, List.of(source));
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
} }
static DiagnosticListener<? super JavaFileObject> noErrors = d -> { static DiagnosticListener<? super JavaFileObject> noErrors = d -> {

View File

@ -174,7 +174,9 @@ public class TreeEndPosTest {
compiler.getTask(writer, javaFileManager, compiler.getTask(writer, javaFileManager,
dc, options, null, dc, options, null,
sources); sources);
task.call(); if (task.call()) {
throw new AssertionError("test compilation was expected to fail");
}
for (Diagnostic diagnostic : (List<Diagnostic>) dc.getDiagnostics()) { for (Diagnostic diagnostic : (List<Diagnostic>) dc.getDiagnostics()) {
long actualStart = diagnostic.getStartPosition(); long actualStart = diagnostic.getStartPosition();
long actualEnd = diagnostic.getEndPosition(); long actualEnd = diagnostic.getEndPosition();

View File

@ -61,7 +61,9 @@ public class T6348499 {
"-processorpath", testClassPath); "-processorpath", testClassPath);
StringWriter out = new StringWriter(); StringWriter out = new StringWriter();
JavacTask task = tool.getTask(out, fm, dl, opts, null, files); JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
task.call(); if (task.call()) {
throw new AssertionError("test compilation was expected to fail");
}
String s = out.toString(); String s = out.toString();
System.err.print(s); System.err.print(s);
// Expect the following 1 multi-line diagnostic, and no output to log // Expect the following 1 multi-line diagnostic, and no output to log

View File

@ -60,7 +60,9 @@ public class T6414633 {
String[] opts = { "-proc:only", String[] opts = { "-proc:only",
"-processor", A.class.getName() }; "-processor", A.class.getName() };
JavacTask task = tool.getTask(null, fm, dl, Arrays.asList(opts), null, files); JavacTask task = tool.getTask(null, fm, dl, Arrays.asList(opts), null, files);
task.call(); if (task.call()) {
throw new AssertionError("test compilation was expected to fail");
}
// two annotations on the same element -- expect 2 diags from the processor // two annotations on the same element -- expect 2 diags from the processor
if (dl.diags != 2) if (dl.diags != 2)

View File

@ -66,7 +66,9 @@ public class T6430209 {
"-processorpath", testClassPath); "-processorpath", testClassPath);
StringWriter out = new StringWriter(); StringWriter out = new StringWriter();
JavacTask task = tool.getTask(out, fm, null, opts, null, files); JavacTask task = tool.getTask(out, fm, null, opts, null, files);
task.call(); if (task.call()) {
throw new AssertionError("test compilation was expected to fail");
}
String s = out.toString(); String s = out.toString();
System.err.print(s); System.err.print(s);
s = s.replace(System.getProperty("line.separator"), "\n"); s = s.replace(System.getProperty("line.separator"), "\n");

View File

@ -55,7 +55,9 @@ public class T6439826 extends AbstractProcessor {
"-processorpath", testClasses); "-processorpath", testClasses);
StringWriter out = new StringWriter(); StringWriter out = new StringWriter();
JavacTask task = tool.getTask(out, fm, dl, opts, null, files); JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
task.call(); if (task.call()) {
throw new AssertionError("test compilation was expected to fail");
}
String s = out.toString(); String s = out.toString();
System.err.print(s); System.err.print(s);
// Expect the following 2 diagnostics, and no output to log // Expect the following 2 diagnostics, and no output to log

View File

@ -62,7 +62,9 @@ public class T8142931 extends AbstractProcessor {
"-processorpath", testClasses); "-processorpath", testClasses);
StringWriter out = new StringWriter(); StringWriter out = new StringWriter();
JavacTask task = (JavacTask)tool.getTask(out, fm, dl, opts, null, files); JavacTask task = (JavacTask)tool.getTask(out, fm, dl, opts, null, files);
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
String s = out.toString(); String s = out.toString();
System.err.print(s); System.err.print(s);
System.err.println(dl.count + " diagnostics; " + s.length() + " characters"); System.err.println(dl.count + " diagnostics; " + s.length() + " characters");

View File

@ -81,7 +81,9 @@ public class LocalInAnonymous {
List<String> options = Arrays.asList("-d", classes.toString()); List<String> options = Arrays.asList("-d", classes.toString());
StringWriter out = new StringWriter(); StringWriter out = new StringWriter();
JavacTask task = (JavacTask) compiler.getTask(out, null, noErrors, options, null, files); JavacTask task = (JavacTask) compiler.getTask(out, null, noErrors, options, null, files);
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
if (!out.toString().isEmpty()) { if (!out.toString().isEmpty()) {
throw new AssertionError("Unexpected output: " + out); throw new AssertionError("Unexpected output: " + out);
} }
@ -103,7 +105,9 @@ public class LocalInAnonymous {
} }
} }
}); });
task2.call(); if (!task2.call()) {
throw new AssertionError("test failed due to a compilation error");
}
if (!out.toString().isEmpty()) { if (!out.toString().isEmpty()) {
throw new AssertionError("Unexpected output: " + out); throw new AssertionError("Unexpected output: " + out);
} }
@ -112,7 +116,9 @@ public class LocalInAnonymous {
"-processorpath", System.getProperty("test.classes"), "-processorpath", System.getProperty("test.classes"),
"-processor", Processor.class.getName()); "-processor", Processor.class.getName());
JavacTask task3 = (JavacTask) compiler.getTask(out, null, noErrors, options, null, files); JavacTask task3 = (JavacTask) compiler.getTask(out, null, noErrors, options, null, files);
task3.call(); if (!task3.call()) {
throw new AssertionError("test failed due to a compilation error");
}
if (!out.toString().isEmpty()) { if (!out.toString().isEmpty()) {
throw new AssertionError("Unexpected output: " + out); throw new AssertionError("Unexpected output: " + out);
} }

View File

@ -323,7 +323,9 @@ public class TestNoteOnImplicitProcessing extends TestRunner {
List<String> options = List.of("-classpath", jarFile.toString(), "-XDrawDiagnostics"); List<String> options = List.of("-classpath", jarFile.toString(), "-XDrawDiagnostics");
CompilationTask task = provider.getTask(compilerOut, null, null, options, null, inputFile); CompilationTask task = provider.getTask(compilerOut, null, null, options, null, inputFile);
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
verifyMessages(out, compilerOut, false, false); verifyMessages(out, compilerOut, false, false);
} }
@ -335,7 +337,9 @@ public class TestNoteOnImplicitProcessing extends TestRunner {
(Processor) processorClass.getDeclaredConstructor().newInstance(); (Processor) processorClass.getDeclaredConstructor().newInstance();
task.setProcessors(List.of(processor)); task.setProcessors(List.of(processor));
task.call(); if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
verifyMessages(out, compilerOut, false, true); verifyMessages(out, compilerOut, false, true);
} }

View File

@ -56,7 +56,9 @@ public class CompleteOnClosed extends JavacTestingAbstractProcessor {
Iterable<JavaFileObject> files = Arrays.<JavaFileObject>asList(new ToolBox.JavaSource(source)); Iterable<JavaFileObject> files = Arrays.<JavaFileObject>asList(new ToolBox.JavaSource(source));
Iterable<String> options = Arrays.asList("-processor", "CompleteOnClosed"); Iterable<String> options = Arrays.asList("-processor", "CompleteOnClosed");
CompilationTask task = compiler.getTask(null, null, collector, options, null, files); CompilationTask task = compiler.getTask(null, null, collector, options, null, files);
task.call(); if (task.call()) {
throw new AssertionError("test compilation was expected to fail");
}
for (Diagnostic<? extends JavaFileObject> d : collector.getDiagnostics()) { for (Diagnostic<? extends JavaFileObject> d : collector.getDiagnostics()) {
System.out.println(d.toString()); System.out.println(d.toString());
} }