8179704: doclet crashes with an empty package.html

Reviewed-by: jjg
This commit is contained in:
Kumar Srinivasan 2017-07-05 13:46:05 -07:00
parent 0a79d06e97
commit 95784b44db
8 changed files with 169 additions and 30 deletions

View File

@ -1757,6 +1757,9 @@ public class HtmlDocletWriter extends HtmlDocWriter {
return true;
}
// Notify the next DocTree handler to take necessary action
private boolean commentRemoved = false;
/**
* Converts inline tags and text to text strings, expanding the
* inline tags along the way. Called wherever text can contain
@ -1782,27 +1785,32 @@ public class HtmlDocletWriter extends HtmlDocWriter {
CommentHelper ch = utils.getCommentHelper(element);
// Array of all possible inline tags for this javadoc run
configuration.tagletManager.checkTags(utils, element, tags, true);
for (ListIterator<? extends DocTree> iterator = tags.listIterator(); iterator.hasNext();) {
DocTree tag = iterator.next();
// zap block tags
if (isFirstSentence && ignoreNonInlineTag(tag))
continue;
commentRemoved = false;
if (isFirstSentence && iterator.nextIndex() == tags.size() &&
(tag.getKind() == TEXT && isAllWhiteSpace(ch.getText(tag))))
continue;
for (ListIterator<? extends DocTree> iterator = tags.listIterator(); iterator.hasNext();) {
boolean isFirstNode = !iterator.hasPrevious();
DocTree tag = iterator.next();
boolean isLastNode = !iterator.hasNext();
if (isFirstSentence) {
// Ignore block tags
if (ignoreNonInlineTag(tag))
continue;
// Ignore any trailing whitespace OR whitespace after removed html comment
if ((isLastNode || commentRemoved)
&& tag.getKind() == TEXT
&& isAllWhiteSpace(ch.getText(tag)))
continue;
// Ignore any leading html comments
if ((isFirstNode || commentRemoved) && tag.getKind() == COMMENT) {
commentRemoved = true;
continue;
}
}
boolean allDone = new SimpleDocTreeVisitor<Boolean, Content>() {
// notify the next DocTree handler to take necessary action
boolean commentRemoved = false;
private boolean isLast(DocTree node) {
return node.equals(tags.get(tags.size() - 1));
}
private boolean isFirst(DocTree node) {
return node.equals(tags.get(0));
}
private boolean inAnAtag() {
if (utils.isStartElement(tag)) {
@ -1847,14 +1855,14 @@ public class HtmlDocletWriter extends HtmlDocWriter {
if (text.startsWith("/..") && !configuration.docrootparent.isEmpty()) {
result.addContent(configuration.docrootparent);
docRootContent = new ContentBuilder();
result.addContent(textCleanup(text.substring(3), isLast(node)));
result.addContent(textCleanup(text.substring(3), isLastNode));
} else {
if (!docRootContent.isEmpty()) {
docRootContent = copyDocRootContent(docRootContent);
} else {
text = redirectRelativeLinks(element, (TextTree) dt);
}
result.addContent(textCleanup(text, isLast(node)));
result.addContent(textCleanup(text, isLastNode));
}
} else {
docRootContent = copyDocRootContent(docRootContent);
@ -1868,10 +1876,6 @@ public class HtmlDocletWriter extends HtmlDocWriter {
@Override
public Boolean visitComment(CommentTree node, Content c) {
if (isFirstSentence && isFirst(node)) {
commentRemoved = true;
return this.visit(iterator.next(), c);
}
result.addContent(new RawHtml(node.getBody()));
return false;
}
@ -1996,8 +2000,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
@Override
public Boolean visitText(TextTree node, Content c) {
String text = node.getBody();
result.addContent(new RawHtml(textCleanup(text, isLast(node), commentRemoved)));
commentRemoved = false;
result.addContent(new RawHtml(textCleanup(text, isLastNode, commentRemoved)));
return false;
}
@ -2013,6 +2016,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
}
}.visit(tag, null);
commentRemoved = false;
if (allDone)
break;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017, 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
@ -23,8 +23,8 @@
/*
* @test
* @bug 8150096
* @summary Make sure package.html is recognized by doclint
* @bug 8150096 8179704
* @summary test package.html handling
* @library ../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build JavadocTester
@ -37,12 +37,36 @@ public class TestPackageHtml extends JavadocTester {
tester.runTests();
}
// Make sure package.html is recognized by doclint
@Test
void testPackageHtml() {
javadoc("-d", "out-pkg-html",
javadoc("-d", "out-pkg-html-1",
"-sourcepath", testSrc,
"pkg1");
checkExit(Exit.ERROR);
checkOutput(Output.OUT, true, "package.html:10: error: bad use of '>'");
}
// Doclet must handle empty body in package.html, must
// ignore html comment in the first sentence and must
// ignore trailing whitespace in a first sentence.
@Test
void testPackageHtmlWithEmptyBody() {
javadoc("-d", "out-pkg-html-2",
"-sourcepath", testSrc,
"pkg2", "pkg3", "pkg4");
checkExit(Exit.OK);
checkOutput("index-all.html", true,
"<dl>\n"
+ "<dt><a href=\"pkg2/package-summary.html\">pkg2</a> - package pkg2</dt>\n"
+ "<dt><a href=\"pkg3/package-summary.html\">pkg3</a> - package pkg3</dt>\n"
+ "<dd>\n"
+ "<div class=\"block\">This is a documentation for <a href=\"pkg3/package-summary.html\"><code>pkg3</code></a></div>\n"
+ "</dd>\n"
+ "<dt><a href=\"pkg4/package-summary.html\">pkg4</a> - package pkg4</dt>\n"
+ "<dd>\n"
+ "<div class=\"block\">This is a documentation for <a href=\"pkg4/package-summary.html\"><code>pkg4</code></a></div>\n"
+ "</dd>\n"
+ "</dl>\n");
}
}

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2017, 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 pkg2;
/**
* An empty class.
*/
public class X {}

View File

@ -0,0 +1,6 @@
<HTML>
<BODY>
<!-- an empty package.html -->
</BODY>
</HTML>

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2017, 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 pkg3;
/**
* An empty class.
*/
public class X {}

View File

@ -0,0 +1,9 @@
<HTML>
<BODY>
<!-- a HTML comment -->
This is a documentation for {@link pkg3}
<p>Next para</p>
</BODY>
</HTML>

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2017, 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 pkg4;
/**
* An empty class.
*/
public class X {}

View File

@ -0,0 +1,9 @@
<HTML>
<BODY>
<!-- a HTML comment --> <!--another comment -->
This is a documentation for {@link pkg4}
<p>Next para</p>
</BODY>
</HTML>