8214571: -Xdoclint of array serialField gives "error: array type not allowed here"

Reviewed-by: jjg, sundar
This commit is contained in:
Hannes Wallnöfer 2018-12-06 12:34:28 +01:00
parent d4acf96543
commit c0099a8a0d
7 changed files with 39 additions and 32 deletions

View File

@ -884,8 +884,6 @@ public class Checker extends DocTreePathScanner<Void, Void> {
String sig = tree.getSignature();
if (sig.contains("<") || sig.contains(">")) {
env.messages.error(REFERENCE, tree, "dc.type.arg.not.allowed");
} else if (isArrayType(sig)) {
env.messages.error(REFERENCE, tree, "dc.array.type.not.allowed");
} else {
Element e = env.trees.getElement(getCurrentPath());
if (e == null)
@ -975,12 +973,6 @@ public class Checker extends DocTreePathScanner<Void, Void> {
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:

View File

@ -25,7 +25,6 @@
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}

View File

@ -443,11 +443,7 @@ public class JavacTrees extends DocTrees {
// 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.getKind() == TypeKind.ARRAY) {
// cannot refer to an array type
return null;
} else if (t.isErroneous()) {
if (t.isErroneous()) {
JCCompilationUnit toplevel =
treeMaker.TopLevel(List.nil());
final ModuleSymbol msym = modules.getDefaultModule();
@ -478,7 +474,11 @@ public class JavacTrees extends DocTrees {
}
}
} else {
tsym = t.tsym;
Type e = t;
// If this is an array type convert to element type
while (e instanceof ArrayType)
e = ((ArrayType)e).elemtype;
tsym = e.tsym;
memberName = (Name) ref.memberName;
}
}

View File

@ -95,7 +95,7 @@ public class TestSeeTag extends JavadocTester {
checkOutput("badref/Test.html", true,
"<dl>\n"
+ "<dt><span class=\"seeLabel\">See Also:</span></dt>\n"
+ "<dd><code>Object[]</code>, \n"
+ "<dd><code>Object</code>, \n"
+ "<code>Foo<String></code></dd>\n"
+ "</dl>");
}

View File

@ -31,13 +31,15 @@ public class SerializedForm implements Serializable {
/**
* @serialField name String a test
* @serialField longs Long[] the longs
* @see TestSerializedForm
*/
@Deprecated
private static final ObjectStreamField[] serialPersistentFields = {
new ObjectStreamField("i", int.class),
new ObjectStreamField("count", Integer.TYPE),
new ObjectStreamField("name", String.class)
new ObjectStreamField("name", String.class),
new ObjectStreamField("longs", Long[].class)
};
/**

View File

@ -84,6 +84,19 @@ public class TestSerializedForm extends JavadocTester {
+ "pkg1.ProtectedInnerClass.ProInnerClass</a> extends java.lang.Object implements Serializable</h3>",
"<h3>Class pkg1.PublicExcludeInnerClass.PubInnerClass extends java.lang.Object implements "
+ "Serializable</h3>");
checkOutput("serialized-form.html", true,
"<h3>Serialized Fields</h3>\n" +
"<ul class=\"blockList\">\n" +
"<li class=\"blockList\">\n" +
"<h4>longs</h4>\n" +
"<pre>Long[] longs</pre>\n" +
"<div class=\"block\">the longs</div>\n" +
"</li>\n" +
"<li class=\"blockListLast\">\n" +
"<h4>name</h4>\n" +
"<pre>java.lang.String name</pre>\n" +
"<div class=\"block\">a test</div>");
}
@Test
@ -113,6 +126,19 @@ public class TestSerializedForm extends JavadocTester {
"<h3>Class <a href=\"pkg1/PublicExcludeInnerClass.PubInnerClass.html\" "
+ "title=\"class in pkg1\">pkg1.PublicExcludeInnerClass.PubInnerClass</a> "
+ "extends java.lang.Object implements Serializable</h3>");
checkOutput("serialized-form.html", true,
"<h3>Serialized Fields</h3>\n" +
"<ul class=\"blockList\">\n" +
"<li class=\"blockList\">\n" +
"<h4>longs</h4>\n" +
"<pre>Long[] longs</pre>\n" +
"<div class=\"block\">the longs</div>\n" +
"</li>\n" +
"<li class=\"blockListLast\">\n" +
"<h4>name</h4>\n" +
"<pre>java.lang.String name</pre>\n" +
"<div class=\"block\">a test</div>");
}
@Test

View File

@ -43,24 +43,12 @@ ReferenceTest.java:64: error: type arguments not allowed here
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
ReferenceTest.java:72: error: reference not found
* {@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
ReferenceTest.java:75: error: reference not found
* @see not.Found[]
^
20 errors
16 errors
1 warning