From 8adb052b46f90e8a0605cfc5ddc667acb7c61952 Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Fri, 6 Jun 2025 14:11:27 +0000 Subject: [PATCH] 8341778: Some javac tests ignore the result of JavacTask::call Reviewed-by: shade --- .../gc/g1/unloading/GenClassPoolJar.java | 4 ++- test/langtools/tools/javac/T6358024.java | 4 ++- test/langtools/tools/javac/T6358166.java | 4 ++- test/langtools/tools/javac/T6361619.java | 7 +++-- test/langtools/tools/javac/T6395974.java | 4 ++- test/langtools/tools/javac/T6397286.java | 1 + .../tools/javac/T6458823/T6458823.java | 4 ++- .../TryWithResources/TwrAvoidNullCheck.java | 4 ++- .../TryWithResources/TwrSimpleClose.java | 4 ++- .../tools/javac/api/6406133/T6406133.java | 4 ++- .../tools/javac/api/6410643/T6410643.java | 1 + .../tools/javac/api/6412656/T6412656.java | 4 ++- .../tools/javac/api/6423003/T6423003.java | 3 +- .../tools/javac/api/6731573/T6731573.java | 4 ++- .../tools/javac/api/7086261/T7086261.java | 4 ++- .../tools/javac/api/8007344/Test.java | 19 +++++++++--- test/langtools/tools/javac/api/DiagSpans.java | 30 ++++++++++++------- test/langtools/tools/javac/api/T6357331.java | 4 ++- .../tools/javac/api/TestTreePath.java | 4 ++- .../api/taskListeners/EventsBalancedTest.java | 4 ++- .../ImproveFatalErrorHandling.java | 4 ++- test/langtools/tools/javac/lib/DPrinter.java | 4 ++- .../tools/javac/modules/QueryBeforeEnter.java | 4 ++- .../patterns/SOEDeeplyNestedBlocksTest.java | 6 ++-- .../tools/javac/positions/TreeEndPosTest.java | 4 ++- .../javac/processing/6348499/T6348499.java | 4 ++- .../javac/processing/6414633/T6414633.java | 4 ++- .../javac/processing/6430209/T6430209.java | 4 ++- .../tools/javac/processing/T6439826.java | 4 ++- .../tools/javac/processing/T8142931.java | 4 ++- .../processing/model/LocalInAnonymous.java | 12 ++++++-- .../options/TestNoteOnImplicitProcessing.java | 8 +++-- .../processing/rounds/CompleteOnClosed.java | 4 ++- 33 files changed, 135 insertions(+), 48 deletions(-) diff --git a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/GenClassPoolJar.java b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/GenClassPoolJar.java index fb3fb4d0e8e..cea00fc2efc 100644 --- a/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/GenClassPoolJar.java +++ b/test/hotspot/jtreg/vmTestbase/gc/g1/unloading/GenClassPoolJar.java @@ -187,7 +187,9 @@ public class GenClassPoolJar { StandardJavaFileManager sjfm = compiler.getStandardFileManager(null, null, null); Iterable fileObjects = sjfm.getJavaFileObjects(files); 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(); } diff --git a/test/langtools/tools/javac/T6358024.java b/test/langtools/tools/javac/T6358024.java index 86bc37afda9..7388ce55cef 100644 --- a/test/langtools/tools/javac/T6358024.java +++ b/test/langtools/tools/javac/T6358024.java @@ -87,7 +87,9 @@ public class T6358024 extends AbstractProcessor { Arrays.asList(f)); MyTaskListener tl = new MyTaskListener(); task.setTaskListener(tl); - task.call(); + if (!task.call()) { + throw new AssertionError("test failed due to a compilation error"); + } if (tl.started != expect) throw new AssertionError("Unexpected number of TaskListener events; " + "expected " + expect + ", found " + tl.started); diff --git a/test/langtools/tools/javac/T6358166.java b/test/langtools/tools/javac/T6358166.java index e1aa2e00bbf..d3d4b2ae162 100644 --- a/test/langtools/tools/javac/T6358166.java +++ b/test/langtools/tools/javac/T6358166.java @@ -75,7 +75,9 @@ public class T6358166 extends AbstractProcessor { JavacTool tool = JavacTool.create(); 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); if (c.errorCount() != 0) diff --git a/test/langtools/tools/javac/T6361619.java b/test/langtools/tools/javac/T6361619.java index 67450129e3e..1f299a8f4c3 100644 --- a/test/langtools/tools/javac/T6361619.java +++ b/test/langtools/tools/javac/T6361619.java @@ -50,7 +50,8 @@ public class T6361619 extends AbstractProcessor { final PrintWriter out = new PrintWriter(System.err, true); - Iterable flags = Arrays.asList("-processorpath", testClassDir, + Iterable flags = Arrays.asList("--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "-processorpath", testClassDir, "-processor", self, "-d", "."); DiagnosticListener dl = new DiagnosticListener() { @@ -69,7 +70,9 @@ public class T6361619 extends AbstractProcessor { task.setTaskListener(tl); // should complete, without exceptions - task.call(); + if (!task.call()) { + throw new AssertionError("test failed due to a compilation error"); + } } } diff --git a/test/langtools/tools/javac/T6395974.java b/test/langtools/tools/javac/T6395974.java index e8d2b716735..623a9563695 100644 --- a/test/langtools/tools/javac/T6395974.java +++ b/test/langtools/tools/javac/T6395974.java @@ -63,7 +63,9 @@ public class T6395974 { MyTaskListener tl = new MyTaskListener(); task.setTaskListener(tl); - task.call(); + if (task.call()) { + throw new AssertionError("test compilation was expected to fail"); + } } } diff --git a/test/langtools/tools/javac/T6397286.java b/test/langtools/tools/javac/T6397286.java index 5153a61aa77..8e8ef882aa2 100644 --- a/test/langtools/tools/javac/T6397286.java +++ b/test/langtools/tools/javac/T6397286.java @@ -56,6 +56,7 @@ public class T6397286 { }); try { + // no need to check the result of JavacTask::call, reevaluate if the test is modified task.call(); throw new AssertionError("no exception thrown"); } catch (RuntimeException e) { diff --git a/test/langtools/tools/javac/T6458823/T6458823.java b/test/langtools/tools/javac/T6458823/T6458823.java index 91736229e5a..cd23066edc8 100644 --- a/test/langtools/tools/javac/T6458823/T6458823.java +++ b/test/langtools/tools/javac/T6458823/T6458823.java @@ -66,7 +66,9 @@ public class T6458823 { files.add(new File(T6458823.class.getResource("TestClass.java").toURI())); final CompilationTask task = compiler.getTask(null, fm, diagColl, options, null, fm.getJavaFileObjectsFromFiles(files)); - task.call(); + if (!task.call()) { + throw new AssertionError("test failed due to a compilation error"); + } int diagCount = 0; for (Diagnostic diag : diagColl.getDiagnostics()) { if (diag.getKind() != Diagnostic.Kind.WARNING) { diff --git a/test/langtools/tools/javac/TryWithResources/TwrAvoidNullCheck.java b/test/langtools/tools/javac/TryWithResources/TwrAvoidNullCheck.java index f095b92b571..045558374c7 100644 --- a/test/langtools/tools/javac/TryWithResources/TwrAvoidNullCheck.java +++ b/test/langtools/tools/javac/TryWithResources/TwrAvoidNullCheck.java @@ -76,7 +76,9 @@ public class TwrAvoidNullCheck { DumpLower.preRegister(ctx); Iterable files = Arrays.asList(new ToolBox.JavaSource(code)); 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; diff --git a/test/langtools/tools/javac/TryWithResources/TwrSimpleClose.java b/test/langtools/tools/javac/TryWithResources/TwrSimpleClose.java index af3f4ea19ef..11691a43040 100644 --- a/test/langtools/tools/javac/TryWithResources/TwrSimpleClose.java +++ b/test/langtools/tools/javac/TryWithResources/TwrSimpleClose.java @@ -89,7 +89,9 @@ public class TwrSimpleClose { JFMImpl fm = new JFMImpl(sfm)) { Iterable files = Arrays.asList(new ToolBox.JavaSource(code)); 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) { throw new AssertionError(); diff --git a/test/langtools/tools/javac/api/6406133/T6406133.java b/test/langtools/tools/javac/api/6406133/T6406133.java index 70e2fbe5fe6..24ddba1e602 100644 --- a/test/langtools/tools/javac/api/6406133/T6406133.java +++ b/test/langtools/tools/javac/api/6406133/T6406133.java @@ -90,7 +90,9 @@ public class T6406133 extends ToolTester { task = tool.getTask(pw, fm, listener, null, null, compilationUnits); task.setProcessors(Arrays.asList(processor)); task.setLocale(locale); //6443132 - task.call(); + if (task.call()) { + throw new AssertionError("test compilation was expected to fail"); + } if (!processor.locale.equals(locale)) throw new AssertionError("Error in diagnostic localization during annotation processing"); String res = useListener ? listener.result : pw.toString(); diff --git a/test/langtools/tools/javac/api/6410643/T6410643.java b/test/langtools/tools/javac/api/6410643/T6410643.java index a551f802d62..d8f5c798249 100644 --- a/test/langtools/tools/javac/api/6410643/T6410643.java +++ b/test/langtools/tools/javac/api/6410643/T6410643.java @@ -53,6 +53,7 @@ public class T6410643 extends ToolTester { void test(String... args) { task = tool.getTask(null, null, null, null, null, null); try { + // no need to check the result of JavacTask::call, reevaluate if the test is modified task.call(); throw new AssertionError("Error expected"); } catch (IllegalStateException e) { diff --git a/test/langtools/tools/javac/api/6412656/T6412656.java b/test/langtools/tools/javac/api/6412656/T6412656.java index b7976e036fd..cfea162ae98 100644 --- a/test/langtools/tools/javac/api/6412656/T6412656.java +++ b/test/langtools/tools/javac/api/6412656/T6412656.java @@ -47,7 +47,9 @@ public class T6412656 extends ToolTester { task = tool.getTask(null, fm, null, null, Collections.singleton(T6412656.class.getName()), null); 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) throw new AssertionError("Annotation processor not run"); System.out.println("OK"); diff --git a/test/langtools/tools/javac/api/6423003/T6423003.java b/test/langtools/tools/javac/api/6423003/T6423003.java index 893f2dd6344..58d055e9685 100644 --- a/test/langtools/tools/javac/api/6423003/T6423003.java +++ b/test/langtools/tools/javac/api/6423003/T6423003.java @@ -41,11 +41,12 @@ public class T6423003 extends ToolTester { void test(String... args) { task = tool.getTask(null, fm, null, Arrays.asList("-Xlint:all"), null, null); try { + // no need to check the result of JavacTask::call, reevaluate if the test is modified task.call(); + throw new AssertionError("Expected IllegalStateException not thrown"); } catch (IllegalStateException ex) { return; } - throw new AssertionError("Expected IllegalStateException not thrown"); } public static void main(String... args) throws IOException { try (T6423003 t = new T6423003()) { diff --git a/test/langtools/tools/javac/api/6731573/T6731573.java b/test/langtools/tools/javac/api/6731573/T6731573.java index 0d7ceb8fd2f..892b8e63ffb 100644 --- a/test/langtools/tools/javac/api/6731573/T6731573.java +++ b/test/langtools/tools/javac/api/6731573/T6731573.java @@ -93,7 +93,9 @@ public class T6731573 extends ToolTester { if (sourceLine.optValue != null) options.add(sourceLine.optValue); 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(), diagType.shouldDisplaySource(sourceLine), options); diff --git a/test/langtools/tools/javac/api/7086261/T7086261.java b/test/langtools/tools/javac/api/7086261/T7086261.java index 1bc2d1a2dc8..391e71c94a7 100644 --- a/test/langtools/tools/javac/api/7086261/T7086261.java +++ b/test/langtools/tools/javac/api/7086261/T7086261.java @@ -71,7 +71,9 @@ public class T7086261 { try (JavaFileManager jfm = javac.getStandardFileManager(null, null, null)) { JavaCompiler.CompilationTask task = 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"); + } } } diff --git a/test/langtools/tools/javac/api/8007344/Test.java b/test/langtools/tools/javac/api/8007344/Test.java index c99b77a101f..d230fb6086b 100644 --- a/test/langtools/tools/javac/api/8007344/Test.java +++ b/test/langtools/tools/javac/api/8007344/Test.java @@ -38,6 +38,7 @@ import java.io.File; import java.io.PrintWriter; import java.util.Arrays; +import java.util.List; import java.util.Set; import javax.annotation.processing.RoundEnvironment; @@ -75,6 +76,12 @@ public class Test { } } + static final List 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; int errors; @@ -102,10 +109,12 @@ public class Test { Iterable files, PrintWriter out, int expectedDocComments) { 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)); task.setProcessors(Arrays.asList(ap)); - task.call(); + if (!task.call()) { + throw new AssertionError("test failed due to a compilation error"); + } ap.checker.checkDocComments(expectedDocComments); } @@ -113,10 +122,12 @@ public class Test { Iterable files, PrintWriter out, int expectedDocComments) { 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)); task.addTaskListener(tl); - task.call(); + if (!task.call()) { + throw new AssertionError("test failed due to a compilation error"); + } tl.checker.checkDocComments(expectedDocComments); } diff --git a/test/langtools/tools/javac/api/DiagSpans.java b/test/langtools/tools/javac/api/DiagSpans.java index e4cdc6a5f07..527fe1aad62 100644 --- a/test/langtools/tools/javac/api/DiagSpans.java +++ b/test/langtools/tools/javac/api/DiagSpans.java @@ -72,7 +72,8 @@ public class DiagSpans extends TestRunner { } """, '/', - '^'); + '^', + false); } @Test @@ -87,7 +88,8 @@ public class DiagSpans extends TestRunner { } """, '/', - '^'); + '^', + false); } @Test @@ -102,7 +104,8 @@ public class DiagSpans extends TestRunner { } """, '/', - '^'); + '^', + false); } @Test @@ -118,7 +121,8 @@ public class DiagSpans extends TestRunner { } """, '/', - '^'); + '^', + false); } @Test @@ -134,7 +138,8 @@ public class DiagSpans extends TestRunner { } """, '/', - '^'); + '^', + false); } @Test @@ -158,7 +163,8 @@ public class DiagSpans extends TestRunner { class Sub2 extends Base2 {} """, '/', - '^'); + '^', + true); } @Test @@ -175,7 +181,8 @@ public class DiagSpans extends TestRunner { class Sub1 extends Base1 {} """, '/', - '^'); + '^', + false); } @Test @@ -192,10 +199,11 @@ public class DiagSpans extends TestRunner { 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 expectedError = new ArrayList(); int startPos = -1; @@ -238,7 +246,9 @@ public class DiagSpans extends TestRunner { }; var sourceFiles = List.of(new JFOImpl(realCode.toString())); 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)) { throw new AssertionError("Expected error spans not found, expected: " + expectedError + ", actual: " + actualErrors); diff --git a/test/langtools/tools/javac/api/T6357331.java b/test/langtools/tools/javac/api/T6357331.java index 5253ebededd..0bc4ff98a53 100644 --- a/test/langtools/tools/javac/api/T6357331.java +++ b/test/langtools/tools/javac/api/T6357331.java @@ -53,7 +53,9 @@ public class T6357331 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) try { diff --git a/test/langtools/tools/javac/api/TestTreePath.java b/test/langtools/tools/javac/api/TestTreePath.java index b3887619947..7a016f42545 100644 --- a/test/langtools/tools/javac/api/TestTreePath.java +++ b/test/langtools/tools/javac/api/TestTreePath.java @@ -116,7 +116,9 @@ public class TestTreePath extends AbstractProcessor { null, null, null, Arrays.asList("-processor", this.getClass().getName()), null, tests); - task.call(); + if (!task.call()) { + throw new AssertionError("test failed due to a compilation error"); + } } } diff --git a/test/langtools/tools/javac/api/taskListeners/EventsBalancedTest.java b/test/langtools/tools/javac/api/taskListeners/EventsBalancedTest.java index bd01d192b6e..759ec8d66ac 100644 --- a/test/langtools/tools/javac/api/taskListeners/EventsBalancedTest.java +++ b/test/langtools/tools/javac/api/taskListeners/EventsBalancedTest.java @@ -79,7 +79,9 @@ public class EventsBalancedTest { task.setTaskListener(listener); - task.call(); + if (!task.call()) { + throw new AssertionError("test failed due to a compilation error"); + } for (Entry e : listener.kind2Count.entrySet()) { if (e.getValue() != null && e.getValue() != 0) { diff --git a/test/langtools/tools/javac/fatalErrors/ImproveFatalErrorHandling.java b/test/langtools/tools/javac/fatalErrors/ImproveFatalErrorHandling.java index de55cd8d5f7..278d8863b4a 100644 --- a/test/langtools/tools/javac/fatalErrors/ImproveFatalErrorHandling.java +++ b/test/langtools/tools/javac/fatalErrors/ImproveFatalErrorHandling.java @@ -76,7 +76,9 @@ public class ImproveFatalErrorHandling extends TestRunner { .getSystemJavaCompiler() .getTask(null, null, null, null, null, files); Context context = task.getContext(); - task.call(); + if (!task.call()) { + throw new AssertionError("test failed due to a compilation error"); + } JavaCompiler compiler = context.get(compilerKey); compiler.closeables = com.sun.tools.javac.util.List.of( new CloseException1(), new CloseException2(), diff --git a/test/langtools/tools/javac/lib/DPrinter.java b/test/langtools/tools/javac/lib/DPrinter.java index 6fa2f17dc67..5092e0698c2 100644 --- a/test/langtools/tools/javac/lib/DPrinter.java +++ b/test/langtools/tools/javac/lib/DPrinter.java @@ -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) { diff --git a/test/langtools/tools/javac/modules/QueryBeforeEnter.java b/test/langtools/tools/javac/modules/QueryBeforeEnter.java index 226c6aed8e3..293b6302eec 100644 --- a/test/langtools/tools/javac/modules/QueryBeforeEnter.java +++ b/test/langtools/tools/javac/modules/QueryBeforeEnter.java @@ -359,7 +359,9 @@ public class QueryBeforeEnter extends ModuleTestBase { "-Xplugin:test"), null, 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, diff --git a/test/langtools/tools/javac/patterns/SOEDeeplyNestedBlocksTest.java b/test/langtools/tools/javac/patterns/SOEDeeplyNestedBlocksTest.java index 4e738cce028..8f64b4cff37 100644 --- a/test/langtools/tools/javac/patterns/SOEDeeplyNestedBlocksTest.java +++ b/test/langtools/tools/javac/patterns/SOEDeeplyNestedBlocksTest.java @@ -34,7 +34,7 @@ import javax.tools.*; public class SOEDeeplyNestedBlocksTest { - static final int NESTING_DEPTH = 1000; + static final int NESTING_DEPTH = 500; public static void main(String... args) { var lines = new ArrayList(); @@ -48,7 +48,9 @@ public class SOEDeeplyNestedBlocksTest { var source = SimpleJavaFileObject.forSource(URI.create("mem://Test.java"), String.join("\n", lines)); var compiler = ToolProvider.getSystemJavaCompiler(); 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 noErrors = d -> { diff --git a/test/langtools/tools/javac/positions/TreeEndPosTest.java b/test/langtools/tools/javac/positions/TreeEndPosTest.java index 990053a7d4e..dc87409f4b2 100644 --- a/test/langtools/tools/javac/positions/TreeEndPosTest.java +++ b/test/langtools/tools/javac/positions/TreeEndPosTest.java @@ -174,7 +174,9 @@ public class TreeEndPosTest { compiler.getTask(writer, javaFileManager, dc, options, null, sources); - task.call(); + if (task.call()) { + throw new AssertionError("test compilation was expected to fail"); + } for (Diagnostic diagnostic : (List) dc.getDiagnostics()) { long actualStart = diagnostic.getStartPosition(); long actualEnd = diagnostic.getEndPosition(); diff --git a/test/langtools/tools/javac/processing/6348499/T6348499.java b/test/langtools/tools/javac/processing/6348499/T6348499.java index f8f8c30bdd7..266caa1e14f 100644 --- a/test/langtools/tools/javac/processing/6348499/T6348499.java +++ b/test/langtools/tools/javac/processing/6348499/T6348499.java @@ -61,7 +61,9 @@ public class T6348499 { "-processorpath", testClassPath); StringWriter out = new StringWriter(); 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(); System.err.print(s); // Expect the following 1 multi-line diagnostic, and no output to log diff --git a/test/langtools/tools/javac/processing/6414633/T6414633.java b/test/langtools/tools/javac/processing/6414633/T6414633.java index d38d1acdd82..5ee7b5e646d 100644 --- a/test/langtools/tools/javac/processing/6414633/T6414633.java +++ b/test/langtools/tools/javac/processing/6414633/T6414633.java @@ -60,7 +60,9 @@ public class T6414633 { String[] opts = { "-proc:only", "-processor", A.class.getName() }; 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 if (dl.diags != 2) diff --git a/test/langtools/tools/javac/processing/6430209/T6430209.java b/test/langtools/tools/javac/processing/6430209/T6430209.java index 2f79b36a3e1..1371b7c09d6 100644 --- a/test/langtools/tools/javac/processing/6430209/T6430209.java +++ b/test/langtools/tools/javac/processing/6430209/T6430209.java @@ -66,7 +66,9 @@ public class T6430209 { "-processorpath", testClassPath); StringWriter out = new StringWriter(); 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(); System.err.print(s); s = s.replace(System.getProperty("line.separator"), "\n"); diff --git a/test/langtools/tools/javac/processing/T6439826.java b/test/langtools/tools/javac/processing/T6439826.java index 846d77c3a7e..fed293d4e5e 100644 --- a/test/langtools/tools/javac/processing/T6439826.java +++ b/test/langtools/tools/javac/processing/T6439826.java @@ -55,7 +55,9 @@ public class T6439826 extends AbstractProcessor { "-processorpath", testClasses); StringWriter out = new StringWriter(); 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(); System.err.print(s); // Expect the following 2 diagnostics, and no output to log diff --git a/test/langtools/tools/javac/processing/T8142931.java b/test/langtools/tools/javac/processing/T8142931.java index 5abeac83687..8ade5e19767 100644 --- a/test/langtools/tools/javac/processing/T8142931.java +++ b/test/langtools/tools/javac/processing/T8142931.java @@ -62,7 +62,9 @@ public class T8142931 extends AbstractProcessor { "-processorpath", testClasses); StringWriter out = new StringWriter(); 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(); System.err.print(s); System.err.println(dl.count + " diagnostics; " + s.length() + " characters"); diff --git a/test/langtools/tools/javac/processing/model/LocalInAnonymous.java b/test/langtools/tools/javac/processing/model/LocalInAnonymous.java index 6cbbe512784..616062bb542 100644 --- a/test/langtools/tools/javac/processing/model/LocalInAnonymous.java +++ b/test/langtools/tools/javac/processing/model/LocalInAnonymous.java @@ -81,7 +81,9 @@ public class LocalInAnonymous { List options = Arrays.asList("-d", classes.toString()); StringWriter out = new StringWriter(); 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()) { 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()) { throw new AssertionError("Unexpected output: " + out); } @@ -112,7 +116,9 @@ public class LocalInAnonymous { "-processorpath", System.getProperty("test.classes"), "-processor", Processor.class.getName()); 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()) { throw new AssertionError("Unexpected output: " + out); } diff --git a/test/langtools/tools/javac/processing/options/TestNoteOnImplicitProcessing.java b/test/langtools/tools/javac/processing/options/TestNoteOnImplicitProcessing.java index 73089a9a3cf..181c29eeb56 100644 --- a/test/langtools/tools/javac/processing/options/TestNoteOnImplicitProcessing.java +++ b/test/langtools/tools/javac/processing/options/TestNoteOnImplicitProcessing.java @@ -323,7 +323,9 @@ public class TestNoteOnImplicitProcessing extends TestRunner { List options = List.of("-classpath", jarFile.toString(), "-XDrawDiagnostics"); 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); } @@ -335,7 +337,9 @@ public class TestNoteOnImplicitProcessing extends TestRunner { (Processor) processorClass.getDeclaredConstructor().newInstance(); 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); } diff --git a/test/langtools/tools/javac/processing/rounds/CompleteOnClosed.java b/test/langtools/tools/javac/processing/rounds/CompleteOnClosed.java index 1ebc6b2acec..f724d605e51 100644 --- a/test/langtools/tools/javac/processing/rounds/CompleteOnClosed.java +++ b/test/langtools/tools/javac/processing/rounds/CompleteOnClosed.java @@ -56,7 +56,9 @@ public class CompleteOnClosed extends JavacTestingAbstractProcessor { Iterable files = Arrays.asList(new ToolBox.JavaSource(source)); Iterable options = Arrays.asList("-processor", "CompleteOnClosed"); 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 d : collector.getDiagnostics()) { System.out.println(d.toString()); }