8200432: javadoc fails with ClassCastException on {@link byte[]}
Reviewed-by: jjg, sundar
--- a/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java Thu Nov 22 11:15:53 2018 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java Thu Nov 22 15:38:20 2018 +0100
@@ -882,12 +882,15 @@
@Override @DefinedBy(Api.COMPILER_TREE)
public Void visitReference(ReferenceTree tree, Void ignore) {
String sig = tree.getSignature();
- if (sig.contains("<") || sig.contains(">"))
+ if (sig.contains("<") || sig.contains(">")) {
env.messages.error(REFERENCE, tree, "dc.type.arg.not.allowed");
-
- Element e = env.trees.getElement(getCurrentPath());
- if (e == null)
- env.messages.error(REFERENCE, tree, "dc.ref.not.found");
+ } else if (isArrayType(sig)) {
+ env.messages.error(REFERENCE, tree, "dc.array.type.not.allowed");
+ } else {
+ Element e = env.trees.getElement(getCurrentPath());
+ if (e == null)
+ env.messages.error(REFERENCE, tree, "dc.ref.not.found");
+ }
return super.visitReference(tree, ignore);
}
@@ -972,6 +975,12 @@
return scan(tree.getDescription(), ignore);
}
+ private boolean isArrayType(String signature) {
+ int brackets = signature.indexOf('[');
+ int parens = signature.indexOf('(');
+ return brackets >= 0 && (parens < 0 || brackets < parens);
+ }
+
private boolean isThrowable(TypeMirror tm) {
switch (tm.getKind()) {
case DECLARED:
--- a/src/jdk.compiler/share/classes/com/sun/tools/doclint/resources/doclint.properties Thu Nov 22 11:15:53 2018 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/doclint/resources/doclint.properties Thu Nov 22 15:38:20 2018 +0100
@@ -25,6 +25,7 @@
dc.anchor.already.defined = anchor already defined: "{0}"
dc.anchor.value.missing = no value given for anchor
+dc.array.type.not.allowed = array type not allowed here
dc.attr.lacks.value = attribute lacks value
dc.attr.not.number = attribute value is not a number
dc.attr.not.supported.html4 = attribute not supported in HTML4: {0}
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java Thu Nov 22 11:15:53 2018 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java Thu Nov 22 15:38:20 2018 +0100
@@ -443,7 +443,11 @@
// we first check if qualifierExpression identifies a type,
// and if not, then we check to see if it identifies a package.
Type t = attr.attribType(ref.qualifierExpression, env);
- if (t.isErroneous()) {
+
+ if (t.getKind() == TypeKind.ARRAY) {
+ // cannot refer to an array type
+ return null;
+ } else if (t.isErroneous()) {
JCCompilationUnit toplevel =
treeMaker.TopLevel(List.nil());
final ModuleSymbol msym = modules.getDefaultModule();
@@ -451,6 +455,9 @@
toplevel.packge = msym.unnamedPackage;
Symbol sym = attr.attribIdent(ref.qualifierExpression, toplevel);
+ if (sym == null)
+ return null;
+
sym.complete();
if ((sym.kind == PCK || sym.kind == TYP) && sym.exists()) {
--- a/test/langtools/jdk/javadoc/doclet/testSeeTag/TestSeeTag.java Thu Nov 22 11:15:53 2018 +0100
+++ b/test/langtools/jdk/javadoc/doclet/testSeeTag/TestSeeTag.java Thu Nov 22 15:38:20 2018 +0100
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 8017191 8182765
+ * @bug 8017191 8182765 8200432
* @summary Javadoc is confused by at-link to imported classes outside of the set of generated packages
* @author jjg
* @library ../lib
@@ -83,5 +83,20 @@
+ "<a href=\"http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#see\">Javadoc</a>, \n"
+ "<a href=\"Test.InnerOne.html#baz-float-\"><code>something</code></a></dd>\n"
+ "</dl>");
+ }
+
+ @Test
+ void testBadReference() {
+ javadoc("-d", "out-badref",
+ "-sourcepath", testSrc,
+ "badref");
+ checkExit(Exit.ERROR);
+
+ checkOutput("badref/Test.html", true,
+ "<dl>\n"
+ + "<dt><span class=\"seeLabel\">See Also:</span></dt>\n"
+ + "<dd><code>Object[]</code>, \n"
+ + "<code>Foo<String></code></dd>\n"
+ + "</dl>");
+ }
}
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testSeeTag/badref/Test.java Thu Nov 22 15:38:20 2018 +0100
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+package badref;
+
+/**
+ * @see Object[]
+ * @see Foo<String>
+ */
+public interface Test {}
--- a/test/langtools/tools/doclint/ReferenceTest.java Thu Nov 22 11:15:53 2018 +0100
+++ b/test/langtools/tools/doclint/ReferenceTest.java Thu Nov 22 15:38:20 2018 +0100
@@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
- * @bug 8004832 8020556 8002154
+ * @bug 8004832 8020556 8002154 8200432
* @summary Add new doclint package
* @modules jdk.compiler/com.sun.tools.doclint
* @build DocLintTester
@@ -59,9 +59,21 @@
/**
* {@link java.util.List<String>}
* {@link java.util.List<String>#equals}
+ * {@link not.Found<String>}
* @see java.util.List<String>
* @see java.util.List<String>#equals
+ * @see not.Found<String>
*/
public void invalid_type_args() { }
+
+ /**
+ * {@link java.lang.String[]}
+ * {@link java.lang.String[]#equals}
+ * {@link not.Found[]}
+ * @see java.lang.String[]
+ * @see java.lang.String[]#equals
+ * @see not.Found[]
+ */
+ public void invalid_array_types() { }
}
--- a/test/langtools/tools/doclint/ReferenceTest.out Thu Nov 22 11:15:53 2018 +0100
+++ b/test/langtools/tools/doclint/ReferenceTest.out Thu Nov 22 15:38:20 2018 +0100
@@ -32,11 +32,35 @@
* {@link java.util.List<String>#equals}
^
ReferenceTest.java:62: error: type arguments not allowed here
+ * {@link not.Found<String>}
+ ^
+ReferenceTest.java:63: error: type arguments not allowed here
* @see java.util.List<String>
^
-ReferenceTest.java:63: error: type arguments not allowed here
+ReferenceTest.java:64: error: type arguments not allowed here
* @see java.util.List<String>#equals
^
-12 errors
+ReferenceTest.java:65: error: type arguments not allowed here
+ * @see not.Found<String>
+ ^
+ReferenceTest.java:70: error: array type not allowed here
+ * {@link java.lang.String[]}
+ ^
+ReferenceTest.java:71: error: array type not allowed here
+ * {@link java.lang.String[]#equals}
+ ^
+ReferenceTest.java:72: error: array type not allowed here
+ * {@link not.Found[]}
+ ^
+ReferenceTest.java:73: error: array type not allowed here
+ * @see java.lang.String[]
+ ^
+ReferenceTest.java:74: error: array type not allowed here
+ * @see java.lang.String[]#equals
+ ^
+ReferenceTest.java:75: error: array type not allowed here
+ * @see not.Found[]
+ ^
+20 errors
1 warning