8270866: NPE in DocTreePath.getTreePath()
Reviewed-by: jjg
This commit is contained in:
parent
f662127390
commit
fbe28e4ee1
@ -335,7 +335,7 @@ public abstract class AbstractMemberWriter implements MemberSummaryWriter, Membe
|
|||||||
: HtmlLinkInfo.Kind.MEMBER,
|
: HtmlLinkInfo.Kind.MEMBER,
|
||||||
te, element, typeContent);
|
te, element, typeContent);
|
||||||
Content desc = new ContentBuilder();
|
Content desc = new ContentBuilder();
|
||||||
writer.addSummaryLinkComment(this, element, desc);
|
writer.addSummaryLinkComment(element, desc);
|
||||||
useTable.addRow(summaryType, typeContent, desc);
|
useTable.addRow(summaryType, typeContent, desc);
|
||||||
}
|
}
|
||||||
contentTree.add(useTable);
|
contentTree.add(useTable);
|
||||||
@ -363,7 +363,7 @@ public abstract class AbstractMemberWriter implements MemberSummaryWriter, Membe
|
|||||||
addSummaryLink(tElement, member, summaryLink);
|
addSummaryLink(tElement, member, summaryLink);
|
||||||
rowContents.add(summaryLink);
|
rowContents.add(summaryLink);
|
||||||
Content desc = new ContentBuilder();
|
Content desc = new ContentBuilder();
|
||||||
writer.addSummaryLinkComment(this, member, firstSentenceTrees, desc);
|
writer.addSummaryLinkComment(member, firstSentenceTrees, desc);
|
||||||
rowContents.add(desc);
|
rowContents.add(desc);
|
||||||
table.addRow(member, rowContents);
|
table.addRow(member, rowContents);
|
||||||
}
|
}
|
||||||
|
@ -1162,7 +1162,7 @@ public class HtmlDocletWriter {
|
|||||||
public void addInlineComment(Element element, DocTree tag, Content htmltree) {
|
public void addInlineComment(Element element, DocTree tag, Content htmltree) {
|
||||||
CommentHelper ch = utils.getCommentHelper(element);
|
CommentHelper ch = utils.getCommentHelper(element);
|
||||||
List<? extends DocTree> description = ch.getDescription(tag);
|
List<? extends DocTree> description = ch.getDescription(tag);
|
||||||
addCommentTags(element, tag, description, false, false, false, htmltree);
|
addCommentTags(element, description, false, false, false, htmltree);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1249,22 +1249,6 @@ public class HtmlDocletWriter {
|
|||||||
*/
|
*/
|
||||||
private void addCommentTags(Element element, List<? extends DocTree> tags, boolean depr,
|
private void addCommentTags(Element element, List<? extends DocTree> tags, boolean depr,
|
||||||
boolean first, boolean inSummary, Content htmltree) {
|
boolean first, boolean inSummary, Content htmltree) {
|
||||||
addCommentTags(element, null, tags, depr, first, inSummary, htmltree);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the comment tags.
|
|
||||||
*
|
|
||||||
* @param element for which the comment tags will be generated
|
|
||||||
* @param holderTag the block tag context for the inline tags
|
|
||||||
* @param tags the first sentence tags for the doc
|
|
||||||
* @param depr true if it is deprecated
|
|
||||||
* @param first true if the first sentence tags should be added
|
|
||||||
* @param inSummary true if the comment tags are added into the summary section
|
|
||||||
* @param htmltree the documentation tree to which the comment tags will be added
|
|
||||||
*/
|
|
||||||
private void addCommentTags(Element element, DocTree holderTag, List<? extends DocTree> tags, boolean depr,
|
|
||||||
boolean first, boolean inSummary, Content htmltree) {
|
|
||||||
if (options.noComment()) {
|
if (options.noComment()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,6 @@ import jdk.javadoc.internal.doclets.formats.html.markup.HtmlId;
|
|||||||
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
|
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
|
||||||
import jdk.javadoc.internal.doclets.formats.html.markup.TagName;
|
import jdk.javadoc.internal.doclets.formats.html.markup.TagName;
|
||||||
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
|
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
|
||||||
import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
|
|
||||||
import jdk.javadoc.internal.doclets.toolkit.Content;
|
import jdk.javadoc.internal.doclets.toolkit.Content;
|
||||||
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
|
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
|
||||||
|
|
||||||
@ -136,25 +135,22 @@ public abstract class SubWriterHolderWriter extends HtmlDocletWriter {
|
|||||||
/**
|
/**
|
||||||
* Add the summary link for the member.
|
* Add the summary link for the member.
|
||||||
*
|
*
|
||||||
* @param mw the writer for the member being documented
|
|
||||||
* @param member the member to be documented
|
* @param member the member to be documented
|
||||||
* @param contentTree the content tree to which the link will be added
|
* @param contentTree the content tree to which the link will be added
|
||||||
*/
|
*/
|
||||||
public void addSummaryLinkComment(AbstractMemberWriter mw, Element member, Content contentTree) {
|
public void addSummaryLinkComment(Element member, Content contentTree) {
|
||||||
List<? extends DocTree> tags = utils.getFirstSentenceTrees(member);
|
List<? extends DocTree> tags = utils.getFirstSentenceTrees(member);
|
||||||
addSummaryLinkComment(mw, member, tags, contentTree);
|
addSummaryLinkComment(member, tags, contentTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the summary link comment.
|
* Add the summary link comment.
|
||||||
*
|
*
|
||||||
* @param mw the writer for the member being documented
|
|
||||||
* @param member the member being documented
|
* @param member the member being documented
|
||||||
* @param firstSentenceTags the first sentence tags for the member to be documented
|
* @param firstSentenceTags the first sentence tags for the member to be documented
|
||||||
* @param tdSummary the content tree to which the comment will be added
|
* @param tdSummary the content tree to which the comment will be added
|
||||||
*/
|
*/
|
||||||
public void addSummaryLinkComment(AbstractMemberWriter mw,
|
public void addSummaryLinkComment(Element member, List<? extends DocTree> firstSentenceTags, Content tdSummary) {
|
||||||
Element member, List<? extends DocTree> firstSentenceTags, Content tdSummary) {
|
|
||||||
addIndexComment(member, firstSentenceTags, tdSummary);
|
addIndexComment(member, firstSentenceTags, tdSummary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,6 @@ public class InheritDocTaglet extends BaseTaglet {
|
|||||||
if (!inheritedDoc.inlineTags.isEmpty()) {
|
if (!inheritedDoc.inlineTags.isEmpty()) {
|
||||||
replacement = writer.commentTagsToOutput(inheritedDoc.holder, inheritedDoc.holderTag,
|
replacement = writer.commentTagsToOutput(inheritedDoc.holder, inheritedDoc.holderTag,
|
||||||
inheritedDoc.inlineTags, isFirstSentence);
|
inheritedDoc.inlineTags, isFirstSentence);
|
||||||
ch.setOverrideElement(inheritedDoc.holder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -206,9 +206,7 @@ public class ParamTaglet extends BaseTaglet implements InheritableTaglet {
|
|||||||
String lname = kind != ParamKind.TYPE_PARAMETER
|
String lname = kind != ParamKind.TYPE_PARAMETER
|
||||||
? utils.getSimpleName(e)
|
? utils.getSimpleName(e)
|
||||||
: utils.getTypeName(e.asType(), false);
|
: utils.getTypeName(e.asType(), false);
|
||||||
CommentHelper ch = utils.getCommentHelper(holder);
|
Content content = processParamTag(inheritedDoc.holder, kind, writer,
|
||||||
ch.setOverrideElement(inheritedDoc.holder);
|
|
||||||
Content content = processParamTag(holder, kind, writer,
|
|
||||||
(ParamTree) inheritedDoc.holderTag,
|
(ParamTree) inheritedDoc.holderTag,
|
||||||
lname,
|
lname,
|
||||||
alreadyDocumented.isEmpty());
|
alreadyDocumented.isEmpty());
|
||||||
|
@ -121,9 +121,7 @@ public class ReturnTaglet extends BaseTaglet implements InheritableTaglet {
|
|||||||
Input input = new DocFinder.Input(utils, holder, this);
|
Input input = new DocFinder.Input(utils, holder, this);
|
||||||
DocFinder.Output inheritedDoc = DocFinder.search(writer.configuration(), input);
|
DocFinder.Output inheritedDoc = DocFinder.search(writer.configuration(), input);
|
||||||
if (inheritedDoc.holderTag != null) {
|
if (inheritedDoc.holderTag != null) {
|
||||||
CommentHelper ch = utils.getCommentHelper(input.element);
|
return writer.returnTagOutput(inheritedDoc.holder, (ReturnTree) inheritedDoc.holderTag, false);
|
||||||
ch.setOverrideElement(inheritedDoc.holder);
|
|
||||||
return writer.returnTagOutput(holder, (ReturnTree) inheritedDoc.holderTag, false);
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -165,26 +165,8 @@ public class CommentHelper {
|
|||||||
}
|
}
|
||||||
return configuration.docEnv.getTypeUtils().asElement(symbol);
|
return configuration.docEnv.getTypeUtils().asElement(symbol);
|
||||||
}
|
}
|
||||||
// case A: the element contains no comments associated and
|
DocTreePath docTreePath = getDocTreePath(rtree);
|
||||||
// the comments need to be copied from ancestor
|
|
||||||
// case B: the element has @inheritDoc, then the ancestral comment
|
|
||||||
// as appropriate has to be copied over.
|
|
||||||
|
|
||||||
// Case A.
|
|
||||||
if (dcTree == null && overriddenElement != null) {
|
|
||||||
CommentHelper ovch = utils.getCommentHelper(overriddenElement);
|
|
||||||
return ovch.getElement(rtree);
|
|
||||||
}
|
|
||||||
if (dcTree == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
DocTreePath docTreePath = DocTreePath.getPath(path, dcTree, rtree);
|
|
||||||
if (docTreePath == null) {
|
if (docTreePath == null) {
|
||||||
// Case B.
|
|
||||||
if (overriddenElement != null) {
|
|
||||||
CommentHelper ovch = utils.getCommentHelper(overriddenElement);
|
|
||||||
return ovch.getElement(rtree);
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
DocTrees doctrees = configuration.docEnv.getDocTrees();
|
DocTrees doctrees = configuration.docEnv.getDocTrees();
|
||||||
@ -192,10 +174,7 @@ public class CommentHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TypeMirror getType(ReferenceTree rtree) {
|
public TypeMirror getType(ReferenceTree rtree) {
|
||||||
// Workaround for JDK-8269706
|
DocTreePath docTreePath = getDocTreePath(rtree);
|
||||||
if (path == null || dcTree == null || rtree == null)
|
|
||||||
return null;
|
|
||||||
DocTreePath docTreePath = DocTreePath.getPath(path, dcTree, rtree);
|
|
||||||
if (docTreePath != null) {
|
if (docTreePath != null) {
|
||||||
DocTrees doctrees = configuration.docEnv.getDocTrees();
|
DocTrees doctrees = configuration.docEnv.getDocTrees();
|
||||||
return doctrees.getType(docTreePath);
|
return doctrees.getType(docTreePath);
|
||||||
@ -700,9 +679,18 @@ public class CommentHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DocTreePath getDocTreePath(DocTree dtree) {
|
public DocTreePath getDocTreePath(DocTree dtree) {
|
||||||
if (path == null || dcTree == null || dtree == null)
|
if (dcTree == null && overriddenElement != null) {
|
||||||
|
// This is an inherited comment, return path from ancestor.
|
||||||
|
return configuration.utils.getCommentHelper(overriddenElement).getDocTreePath(dtree);
|
||||||
|
} else if (path == null || dcTree == null || dtree == null) {
|
||||||
return null;
|
return null;
|
||||||
return DocTreePath.getPath(path, dcTree, dtree);
|
}
|
||||||
|
DocTreePath dtPath = DocTreePath.getPath(path, dcTree, dtree);
|
||||||
|
if (dtPath == null && overriddenElement != null) {
|
||||||
|
// The overriding element has a doc tree, but it doesn't contain what we're looking for.
|
||||||
|
return configuration.utils.getCommentHelper(overriddenElement).getDocTreePath(dtree);
|
||||||
|
}
|
||||||
|
return dtPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Element getOverriddenElement() {
|
public Element getOverriddenElement() {
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8269722
|
* @bug 8269722 8270866
|
||||||
* @summary NPE in HtmlDocletWriter, reporting errors on inherited tags
|
* @summary NPE in HtmlDocletWriter, reporting errors on inherited tags
|
||||||
* @library /tools/lib ../../lib
|
* @library /tools/lib ../../lib
|
||||||
* @modules jdk.javadoc/jdk.javadoc.internal.tool
|
* @modules jdk.javadoc/jdk.javadoc.internal.tool
|
||||||
@ -67,6 +67,14 @@ public class TestInherited extends JavadocTester {
|
|||||||
"-Xdoclint:-missing", "-XDdoe",
|
"-Xdoclint:-missing", "-XDdoe",
|
||||||
src.resolve("BadParam.java").toString());
|
src.resolve("BadParam.java").toString());
|
||||||
checkExit(Exit.OK);
|
checkExit(Exit.OK);
|
||||||
|
checkOutput("BadParam.Base.html", true, """
|
||||||
|
<dt>Parameters:</dt>
|
||||||
|
<dd><code>i</code> - a < b</dd>
|
||||||
|
""");
|
||||||
|
checkOutput("BadParam.Sub.html", true, """
|
||||||
|
<dt>Parameters:</dt>
|
||||||
|
<dd><code>i</code> - a < b</dd>
|
||||||
|
""");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -91,5 +99,64 @@ public class TestInherited extends JavadocTester {
|
|||||||
"-Xdoclint:-missing",
|
"-Xdoclint:-missing",
|
||||||
src.resolve("BadReturn.java").toString());
|
src.resolve("BadReturn.java").toString());
|
||||||
checkExit(Exit.OK);
|
checkExit(Exit.OK);
|
||||||
|
checkOutput("BadReturn.Base.html", true, """
|
||||||
|
<dt>Returns:</dt>
|
||||||
|
<dd>a < b</dd>
|
||||||
|
""");
|
||||||
|
checkOutput("BadReturn.Sub.html", true, """
|
||||||
|
<dt>Returns:</dt>
|
||||||
|
<dd>a < b</dd>
|
||||||
|
""");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
|
public void testBadInheritedReference(Path base) throws Exception {
|
||||||
|
Path src = base.resolve("src");
|
||||||
|
tb.writeJavaFiles(src, """
|
||||||
|
public class BadReference {
|
||||||
|
public interface Intf {
|
||||||
|
/**
|
||||||
|
* {@link NonExistingClass}
|
||||||
|
*/
|
||||||
|
public void m();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Impl1 implements Intf {
|
||||||
|
public void m() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Impl2 implements Intf {
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public void m() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
// subclass has doc comment but inherits main description
|
||||||
|
public static class Impl3 implements Intf {
|
||||||
|
/**
|
||||||
|
* @since 1
|
||||||
|
*/
|
||||||
|
public void m() { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
|
||||||
|
javadoc("-d", base.resolve("out").toString(),
|
||||||
|
"-Xdoclint:-reference",
|
||||||
|
src.resolve("BadReference.java").toString());
|
||||||
|
checkExit(Exit.OK);
|
||||||
|
checkOutput("BadReference.Intf.html", true, """
|
||||||
|
<div class="block"><code>NonExistingClass</code></div>
|
||||||
|
""");
|
||||||
|
checkOutput("BadReference.Impl1.html", true, """
|
||||||
|
<div class="block"><code>NonExistingClass</code></div>
|
||||||
|
""");
|
||||||
|
checkOutput("BadReference.Impl2.html", true, """
|
||||||
|
<div class="block"><code>NonExistingClass</code></div>
|
||||||
|
""");
|
||||||
|
checkOutput("BadReference.Impl3.html", true, """
|
||||||
|
<div class="block"><code>NonExistingClass</code></div>
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user