Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
8266082: AssertionError in Annotate.fromAnnotations with -Xdoclint
Browse files Browse the repository at this point in the history
Reviewed-by: yan
Backport-of: 0b8a0e2b58dbdd5c9553e502212d32c033a5efb5
  • Loading branch information
Alexey Pavlyutkin authored and Yuri Nesterenko committed Sep 20, 2022
1 parent e024f6d commit a0d9cc2
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
Expand Up @@ -30,6 +30,9 @@
import java.util.Map;

import com.sun.source.doctree.AttributeTree.ValueKind;
import com.sun.source.tree.AnnotatedTypeTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.TreeScanner;
import com.sun.tools.javac.parser.DocCommentParser.TagParser.Kind;
import com.sun.tools.javac.parser.Tokens.Comment;
import com.sun.tools.javac.parser.Tokens.TokenKind;
Expand Down Expand Up @@ -576,9 +579,24 @@ List<JCTree> parseParams(String s) throws ParseException {
if (p.token().kind != TokenKind.EOF)
throw new ParseException("dc.ref.unexpected.input");

if (new TypeAnnotationFinder().scan(paramTypes, null) != null)
throw new ParseException("dc.ref.annotations.not.allowed");

return paramTypes.toList();
}

static class TypeAnnotationFinder extends TreeScanner<Tree, Void> {
@Override
public Tree visitAnnotatedType(AnnotatedTypeTree t, Void ignore) {
return t;
}

@Override
public Tree reduce(Tree t1, Tree t2) {
return t1 != null ? t1 : t2;
}
}

/**
* Read Java identifier
* Matching pairs of { } are skipped; the text is terminated by the first
Expand Down
Expand Up @@ -3136,6 +3136,9 @@ compiler.err.dc.unterminated.signature=\
compiler.err.dc.unterminated.string=\
unterminated string

compiler.err.dc.ref.annotations.not.allowed=\
annotations not allowed

###
# errors related to modules

Expand Down
31 changes: 31 additions & 0 deletions test/langtools/tools/doclint/CrashInAnnotateTest.java
@@ -0,0 +1,31 @@
/*
* @test /nodynamiccopyright/
* @bug 8266082
* @summary javac should not crash when seeing type annotations in links
* @compile/fail/ref=CrashInAnnotateTest.out -Xdoclint -XDrawDiagnostics CrashInAnnotateTest.java
*/

import java.util.List;

/** {@link #equals(@Deprecated Object)}
* {@link java.util.Map.@Deprecated Entry#getKey()}
*/
class CrashInAnnotateTest {
}

/** {@link #compare(Object, List<List<@Deprecated Object>>)} */
class CrashInAnnotateTest2 {
void compare(Object o, List<List<Object>> l) {}
}

/** {@link @Deprecated java.lang.Object#hashCode()} */
class CrashInAnnotateTest3 { }

/** {@link CrashInAnnotateTest4.@java.lang.Deprecated Inner#aField}
* {@link java.util.Map.@Deprecated#getKey()}
*/
class CrashInAnnotateTest4 {
class Inner {
Object aField;
}
}
11 changes: 11 additions & 0 deletions test/langtools/tools/doclint/CrashInAnnotateTest.out
@@ -0,0 +1,11 @@
CrashInAnnotateTest.java:10:5: compiler.err.proc.messager: annotations not allowed
CrashInAnnotateTest.java:11:5: compiler.err.proc.messager: syntax error in reference
CrashInAnnotateTest.java:16:5: compiler.err.proc.messager: annotations not allowed
CrashInAnnotateTest.java:18:10: compiler.warn.proc.messager: no comment
CrashInAnnotateTest.java:21:5: compiler.err.proc.messager: syntax error in reference
CrashInAnnotateTest.java:24:5: compiler.err.proc.messager: syntax error in reference
CrashInAnnotateTest.java:25:5: compiler.err.proc.messager: syntax error in reference
CrashInAnnotateTest.java:28:5: compiler.warn.proc.messager: no comment
CrashInAnnotateTest.java:29:16: compiler.warn.proc.messager: no comment
6 errors
3 warnings
32 changes: 32 additions & 0 deletions test/langtools/tools/javac/diags/examples/NoAnnotationsInLink.java
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

// key: compiler.err.dc.ref.annotations.not.allowed
// key: compiler.note.note
// key: compiler.note.proc.messager
// run: backdoor
// options: -processor DocCommentProcessor -proc:only

/** {@link #equals(@Deprecated Object)} */
class NoAnnotationsInLink {
}

1 comment on commit a0d9cc2

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.