Skip to content
Draft
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 @@ -2325,15 +2325,18 @@ public void run() {
* 4.7.20.2 type_path to associate the annotation with the correct contained type.
*/
private void addTypeAnnotationsToSymbol(Symbol s, List<Attribute.TypeCompound> attributes) {
DeferredCompletionFailureHandler.Handler prevCFHandler = dcfh.setHandler(dcfh.speculativeCodeHandler);
try {
new TypeAnnotationSymbolVisitor(attributes).visit(s, null);
} catch (CompletionFailure ex) {
JavaFileObject prev = log.useSource(currentClassFile);
try {
log.error(Errors.CantAttachTypeAnnotations(attributes, s.owner, s.name, ex.getDetailValue()));
log.warning(Warnings.CantAttachTypeAnnotations(attributes, s.owner, s.name, ex.getDetailValue()));
} finally {
log.useSource(prev);
}
} finally {
dcfh.setHandler(prevCFHandler);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2465,7 +2465,7 @@ compiler.warn.annotation.method.not.found.reason=\
Cannot find annotation method ''{1}()'' in type ''{0}'': {2}

# 0: list of annotation, 1: symbol, 2: name, 3: message segment
compiler.err.cant.attach.type.annotations=\
compiler.warn.cant.attach.type.annotations=\
Cannot attach type annotations {0} to {1}.{2}:\n\
{3}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/*
* @test
* @bug 8337998
* @bug 8337998 8370800
* @summary CompletionFailure in getEnclosingType attaching type annotations
* @library /tools/javac/lib /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
Expand Down Expand Up @@ -56,13 +56,16 @@ void testMissingEnclosingType() throws Exception {
class A<E> {}

class B {
private @Anno A<String> a;
public @Anno A<String> a;
}
""";
String cSrc =
"""
class C {
B b;
public void test() {
b.a.toString();
}
}
""";

Expand All @@ -74,23 +77,26 @@ class C {
tb.createDirectories(out);
new JavacTask(tb).outdir(out).files(tb.findJavaFiles(src)).run();

// now if we remove A.class there will be an error but javac should not crash
// now if we remove A.class javac should not crash
tb.deleteFiles(out.resolve("A.class"));

List<String> log =
new JavacTask(tb)
.outdir(out)
.classpath(out)
.options("-XDrawDiagnostics")
// DO NOT SUBMIT - this is a draft, see discussion in PR
.options(/*"-Werror",*/ "-XDrawDiagnostics")
.files(src.resolve("C.java"))
.run(Expect.FAIL)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);

var expectedOutput =
List.of(
"B.class:-:-: compiler.err.cant.attach.type.annotations: @Anno, B, a,"
+ " (compiler.misc.class.file.not.found: A)",
"1 error");
"B.class:-:-: compiler.warn.cant.attach.type.annotations: @Anno, B, a, (compiler.misc.class.file.not.found: A)",
"C.java:4:8: compiler.err.cant.access: A, (compiler.misc.class.file.not.found: A)",
"1 error",
"1 warning");
if (!expectedOutput.equals(log)) {
throw new Exception("expected output not found: " + log);
}
Expand Down
2 changes: 1 addition & 1 deletion test/langtools/tools/javac/diags/examples.not-yet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ compiler.err.signature.doesnt.match.intf # UNUSED
compiler.err.signature.doesnt.match.supertype # UNUSED
compiler.err.source.cant.overwrite.input.file
compiler.err.stack.sim.error
compiler.err.cant.attach.type.annotations # bad class file
compiler.warn.cant.attach.type.annotations # bad class file
compiler.err.type.var.more.than.once # UNUSED
compiler.err.type.var.more.than.once.in.result # UNUSED
compiler.err.unexpected.type
Expand Down