8364987: javac fails with an exception when looking for diamond creation

Reviewed-by: vromero
This commit is contained in:
Jan Lahoda 2025-08-11 10:28:59 +00:00
parent 1fc0b01601
commit 8b5bb01355
2 changed files with 41 additions and 2 deletions

View File

@ -240,7 +240,7 @@ public class Analyzer {
@Override
List<JCNewClass> rewrite(JCNewClass oldTree) {
if (oldTree.clazz.hasTag(TYPEAPPLY)) {
if (oldTree.clazz.hasTag(TYPEAPPLY) && !oldTree.type.isErroneous()) {
JCNewClass nc = copier.copy(oldTree);
((JCTypeApply)nc.clazz).arguments = List.nil();
return List.of(nc);

View File

@ -23,7 +23,7 @@
/**
* @test
* @bug 8349132
* @bug 8349132 8364987
* @summary Check behavior of the diamond analyzer
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
@ -139,4 +139,43 @@ public class Diamond extends TestRunner {
}
}
@Test //JDK-8364987:
public void testNoCrashErroneousTypes(Path base) throws Exception {
Path current = base.resolve(".");
Path src = current.resolve("src");
Path classes = current.resolve("classes");
tb.writeJavaFiles(src,
"""
public class Test {
void t() {
L<Object> l = new L<Test>();
}
static class L<T> { }
}
""");
Files.createDirectories(classes);
var out = new JavacTask(tb)
.options("-XDfind=diamond",
"-XDshould-stop.at=FLOW",
"-XDrawDiagnostics")
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Task.Expect.FAIL)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);
var expectedOut = List.of(
"Test.java:3:23: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Test.L<Test>, Test.L<java.lang.Object>)",
"1 error"
);
if (!Objects.equals(expectedOut, out)) {
throw new AssertionError("Incorrect Output, expected: " + expectedOut +
", actual: " + out);
}
}
}