Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ void compile(File[] files, String destDir) throws IOException {
StandardJavaFileManager sjfm = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> 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();
}

Expand Down
4 changes: 3 additions & 1 deletion test/langtools/tools/javac/T6358024.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ static void test(JavacFileManager fm, JavaFileObject f, Option[] opts, int expec
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);
Expand Down
4 changes: 3 additions & 1 deletion test/langtools/tools/javac/T6358166.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ static void test(JavacFileManager fm, JavaFileObject f, List<String> addExports,

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)
Expand Down
7 changes: 5 additions & 2 deletions test/langtools/tools/javac/T6361619.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public static void main(String... args) throws Throwable {

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,
"-d", ".");
DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() {
Expand All @@ -69,7 +70,9 @@ public void report(Diagnostic<? extends JavaFileObject> m) {
task.setTaskListener(tl);

// should complete, without exceptions
task.call();
if (!task.call()) {
throw new AssertionError("test failed due to a compilation error");
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion test/langtools/tools/javac/T6395974.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public static void main(String... args) throws Throwable {
MyTaskListener tl = new MyTaskListener();
task.setTaskListener(tl);

task.call();
if (task.call()) {
throw new AssertionError("test compilation was expected to fail");
}
}
}

Expand Down
1 change: 1 addition & 0 deletions test/langtools/tools/javac/T6397286.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void finished(TaskEvent e) {
});

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) {
Expand Down
4 changes: 3 additions & 1 deletion test/langtools/tools/javac/T6458823/T6458823.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public static void main(String[] args) throws Exception {
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<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
if (diag.getKind() != Diagnostic.Kind.WARNING) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ void run(String resourceSpecification, boolean expected) throws IOException {
DumpLower.preRegister(ctx);
Iterable<ToolBox.JavaSource> 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ void run(String trySpec, int expectedCloseCount) throws Exception {
JFMImpl fm = new JFMImpl(sfm)) {
Iterable<ToolBox.JavaSource> 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();
Expand Down
4 changes: 3 additions & 1 deletion test/langtools/tools/javac/api/6406133/T6406133.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ String exec(boolean useListener, Locale locale) {
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();
Expand Down
1 change: 1 addition & 0 deletions test/langtools/tools/javac/api/6410643/T6410643.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void testGetTask(Iterable<String> options,
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) {
Expand Down
4 changes: 3 additions & 1 deletion test/langtools/tools/javac/api/6412656/T6412656.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ void test(String... args) {
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");
Expand Down
3 changes: 2 additions & 1 deletion test/langtools/tools/javac/api/6423003/T6423003.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
4 changes: 3 additions & 1 deletion test/langtools/tools/javac/api/6731573/T6731573.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ void exec(DiagnosticType diagType, SourceLine sourceLine) {
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);
Expand Down
4 changes: 3 additions & 1 deletion test/langtools/tools/javac/api/7086261/T7086261.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ void test() throws Throwable {
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");
}
}
}

Expand Down
19 changes: 15 additions & 4 deletions test/langtools/tools/javac/api/8007344/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,6 +76,12 @@ public static void main(String... args) throws Exception {
}
}

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;
int errors;

Expand Down Expand Up @@ -102,21 +109,25 @@ void testAnnoProcessor(JavacTool javac, StandardJavaFileManager fm,
Iterable<? extends JavaFileObject> 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);
}

void testTaskListener(JavacTool javac, StandardJavaFileManager fm,
Iterable<? extends JavaFileObject> 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);
}

Expand Down
30 changes: 20 additions & 10 deletions test/langtools/tools/javac/api/DiagSpans.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public void exception() {
}
""",
'/',
'^');
'^',
false);
}

@Test
Expand All @@ -87,7 +88,8 @@ public void exception() {
}
""",
'/',
'^');
'^',
false);
}

@Test
Expand All @@ -102,7 +104,8 @@ public void exception() {
}
""",
'/',
'^');
'^',
false);
}

@Test
Expand All @@ -118,7 +121,8 @@ public void exception() {
}
""",
'/',
'^');
'^',
false);
}

@Test
Expand All @@ -134,7 +138,8 @@ public void exception() {
}
""",
'/',
'^');
'^',
false);
}

@Test
Expand All @@ -158,7 +163,8 @@ class Base2 extends Exception {}
class Sub2 extends Base2 {}
""",
'/',
'^');
'^',
true);
}

@Test
Expand All @@ -175,7 +181,8 @@ class Base1 extends Exception {}
class Sub1 extends Base1 {}
""",
'/',
'^');
'^',
false);
}

@Test
Expand All @@ -192,10 +199,11 @@ class Base1 extends Exception {}
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<String>();
int startPos = -1;
Expand Down Expand Up @@ -238,7 +246,9 @@ private void runDiagSpanTest(String code, char spanMarker, char prefMarker) thro
};
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);
Expand Down
4 changes: 3 additions & 1 deletion test/langtools/tools/javac/api/T6357331.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public void started(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)
try {
Expand Down
4 changes: 3 additions & 1 deletion test/langtools/tools/javac/api/TestTreePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ public void run() throws IOException {
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");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ void test(List<String> options, List<JavaFileObject> files) throws IOException {

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()) {
if (e.getValue() != null && e.getValue() != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public void testIOExceptionInMethodClose() throws Exception {
.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(),
Expand Down
4 changes: 3 additions & 1 deletion test/langtools/tools/javac/lib/DPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,9 @@ private void handle(TaskEvent e) {
}
});

task.call();
if (!task.call()) {
throw new AssertionError("compilation failed at DPrinter.Main::run");
}
}

TaskEvent.Kind getKind(String s) {
Expand Down
4 changes: 3 additions & 1 deletion test/langtools/tools/javac/modules/QueryBeforeEnter.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ public void testTooSoon(Path base) throws Exception {
"-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,
Expand Down
Loading