Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8266082: AssertionError in Annotate.fromAnnotations with -Xdoclint #675

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -25,6 +25,9 @@

package com.sun.tools.javac.parser;

import com.sun.source.tree.AnnotatedTypeTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.TreeScanner;
import com.sun.tools.javac.parser.Tokens.TokenKind;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.util.List;
Expand Down Expand Up @@ -193,6 +196,21 @@ private 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;
}
}
}
Expand Up @@ -3269,6 +3269,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 {
}