From 8e3620a344f83a21191bb70cf2af24e9ae1952ce Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Fri, 31 Oct 2025 09:52:02 +0000 Subject: [PATCH] 8370237: AssertionError in Annotate.fromAnnotations with -Xdoclint and type annotations Reviewed-by: jlahoda --- .../tools/javac/parser/ReferenceParser.java | 5 +++++ .../tools/doclint/CrashInAnnotateTest.out | 10 ++++----- .../doclint/CrashInTypeAnnotateTest.java | 21 +++++++++++++++++++ .../tools/doclint/CrashInTypeAnnotateTest.out | 2 ++ 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 test/langtools/tools/doclint/CrashInTypeAnnotateTest.java create mode 100644 test/langtools/tools/doclint/CrashInTypeAnnotateTest.out diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/ReferenceParser.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/ReferenceParser.java index acc655df276..2f6d68f2128 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/ReferenceParser.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/ReferenceParser.java @@ -211,6 +211,11 @@ public class ReferenceParser { if (p.token().kind != TokenKind.EOF) { throw new ParseException(beginIndex + p.token().pos, "dc.ref.unexpected.input"); } + Tree typeAnno = new TypeAnnotationFinder().scan(tree, null); + if (typeAnno != null) { + int annoPos = ((JCTree) typeAnno).getStartPosition(); + throw new ParseException(beginIndex + annoPos, "dc.ref.annotations.not.allowed"); + } checkDiags(dh, beginIndex); return tree; } finally { diff --git a/test/langtools/tools/doclint/CrashInAnnotateTest.out b/test/langtools/tools/doclint/CrashInAnnotateTest.out index 0275032554e..3db434db105 100644 --- a/test/langtools/tools/doclint/CrashInAnnotateTest.out +++ b/test/langtools/tools/doclint/CrashInAnnotateTest.out @@ -1,7 +1,7 @@ CrashInAnnotateTest.java:10:20: compiler.err.proc.messager: annotations not allowed -CrashInAnnotateTest.java:11:37: compiler.err.proc.messager: syntax error in reference +CrashInAnnotateTest.java:11:12: compiler.err.proc.messager: annotations not allowed CrashInAnnotateTest.java:16:39: compiler.err.proc.messager: annotations not allowed -CrashInAnnotateTest.java:21:23: compiler.err.proc.messager: syntax error in reference -CrashInAnnotateTest.java:24:54: compiler.err.proc.messager: syntax error in reference -CrashInAnnotateTest.java:25:37: compiler.err.proc.messager: syntax error in reference -6 errors \ No newline at end of file +CrashInAnnotateTest.java:21:12: compiler.err.proc.messager: annotations not allowed +CrashInAnnotateTest.java:24:12: compiler.err.proc.messager: annotations not allowed +CrashInAnnotateTest.java:25:12: compiler.err.proc.messager: annotations not allowed +6 errors diff --git a/test/langtools/tools/doclint/CrashInTypeAnnotateTest.java b/test/langtools/tools/doclint/CrashInTypeAnnotateTest.java new file mode 100644 index 00000000000..8f6401f415e --- /dev/null +++ b/test/langtools/tools/doclint/CrashInTypeAnnotateTest.java @@ -0,0 +1,21 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8370237 + * @summary AssertionError in Annotate.fromAnnotations with -Xdoclint and type annotations + * @compile/fail/ref=CrashInTypeAnnotateTest.out -Xdoclint:all,-missing -XDrawDiagnostics CrashInTypeAnnotateTest.java + */ + +import java.util.List; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE_PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@interface A {} + +/** {@link List<@A String>} + */ +class CrashInTypeAnnotateTest { +} diff --git a/test/langtools/tools/doclint/CrashInTypeAnnotateTest.out b/test/langtools/tools/doclint/CrashInTypeAnnotateTest.out new file mode 100644 index 00000000000..c192ecc80d4 --- /dev/null +++ b/test/langtools/tools/doclint/CrashInTypeAnnotateTest.out @@ -0,0 +1,2 @@ +CrashInTypeAnnotateTest.java:18:17: compiler.err.proc.messager: annotations not allowed +1 error