Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit fbe28e4

Browse files
committed
8270866: NPE in DocTreePath.getTreePath()
Reviewed-by: jjg
1 parent f662127 commit fbe28e4

File tree

8 files changed

+90
-60
lines changed

8 files changed

+90
-60
lines changed

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractMemberWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ protected void addUseInfo(List<? extends Element> members, Content heading, Cont
335335
: HtmlLinkInfo.Kind.MEMBER,
336336
te, element, typeContent);
337337
Content desc = new ContentBuilder();
338-
writer.addSummaryLinkComment(this, element, desc);
338+
writer.addSummaryLinkComment(element, desc);
339339
useTable.addRow(summaryType, typeContent, desc);
340340
}
341341
contentTree.add(useTable);
@@ -363,7 +363,7 @@ public void addMemberSummary(TypeElement tElement, Element member,
363363
addSummaryLink(tElement, member, summaryLink);
364364
rowContents.add(summaryLink);
365365
Content desc = new ContentBuilder();
366-
writer.addSummaryLinkComment(this, member, firstSentenceTrees, desc);
366+
writer.addSummaryLinkComment(member, firstSentenceTrees, desc);
367367
rowContents.add(desc);
368368
table.addRow(member, rowContents);
369369
}

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ private Content plainOrCode(boolean plain, Content body) {
11621162
public void addInlineComment(Element element, DocTree tag, Content htmltree) {
11631163
CommentHelper ch = utils.getCommentHelper(element);
11641164
List<? extends DocTree> description = ch.getDescription(tag);
1165-
addCommentTags(element, tag, description, false, false, false, htmltree);
1165+
addCommentTags(element, description, false, false, false, htmltree);
11661166
}
11671167

11681168
/**
@@ -1249,22 +1249,6 @@ public void addInlineComment(Element element, Content htmltree) {
12491249
*/
12501250
private void addCommentTags(Element element, List<? extends DocTree> tags, boolean depr,
12511251
boolean first, boolean inSummary, Content htmltree) {
1252-
addCommentTags(element, null, tags, depr, first, inSummary, htmltree);
1253-
}
1254-
1255-
/**
1256-
* Adds the comment tags.
1257-
*
1258-
* @param element for which the comment tags will be generated
1259-
* @param holderTag the block tag context for the inline tags
1260-
* @param tags the first sentence tags for the doc
1261-
* @param depr true if it is deprecated
1262-
* @param first true if the first sentence tags should be added
1263-
* @param inSummary true if the comment tags are added into the summary section
1264-
* @param htmltree the documentation tree to which the comment tags will be added
1265-
*/
1266-
private void addCommentTags(Element element, DocTree holderTag, List<? extends DocTree> tags, boolean depr,
1267-
boolean first, boolean inSummary, Content htmltree) {
12681252
if (options.noComment()) {
12691253
return;
12701254
}

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SubWriterHolderWriter.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
3939
import jdk.javadoc.internal.doclets.formats.html.markup.TagName;
4040
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
41-
import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
4241
import jdk.javadoc.internal.doclets.toolkit.Content;
4342
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
4443

@@ -136,25 +135,22 @@ protected void addIndexComment(Element member, List<? extends DocTree> firstSent
136135
/**
137136
* Add the summary link for the member.
138137
*
139-
* @param mw the writer for the member being documented
140138
* @param member the member to be documented
141139
* @param contentTree the content tree to which the link will be added
142140
*/
143-
public void addSummaryLinkComment(AbstractMemberWriter mw, Element member, Content contentTree) {
141+
public void addSummaryLinkComment(Element member, Content contentTree) {
144142
List<? extends DocTree> tags = utils.getFirstSentenceTrees(member);
145-
addSummaryLinkComment(mw, member, tags, contentTree);
143+
addSummaryLinkComment(member, tags, contentTree);
146144
}
147145

148146
/**
149147
* Add the summary link comment.
150148
*
151-
* @param mw the writer for the member being documented
152149
* @param member the member being documented
153150
* @param firstSentenceTags the first sentence tags for the member to be documented
154151
* @param tdSummary the content tree to which the comment will be added
155152
*/
156-
public void addSummaryLinkComment(AbstractMemberWriter mw,
157-
Element member, List<? extends DocTree> firstSentenceTags, Content tdSummary) {
153+
public void addSummaryLinkComment(Element member, List<? extends DocTree> firstSentenceTags, Content tdSummary) {
158154
addIndexComment(member, firstSentenceTags, tdSummary);
159155
}
160156

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/InheritDocTaglet.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ private Content retrieveInheritedDocumentation(TagletWriter writer,
9797
if (!inheritedDoc.inlineTags.isEmpty()) {
9898
replacement = writer.commentTagsToOutput(inheritedDoc.holder, inheritedDoc.holderTag,
9999
inheritedDoc.inlineTags, isFirstSentence);
100-
ch.setOverrideElement(inheritedDoc.holder);
101100
}
102101

103102
} else {

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ParamTaglet.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ private Content getInheritedTagletOutput(ParamKind kind, Element holder,
206206
String lname = kind != ParamKind.TYPE_PARAMETER
207207
? utils.getSimpleName(e)
208208
: utils.getTypeName(e.asType(), false);
209-
CommentHelper ch = utils.getCommentHelper(holder);
210-
ch.setOverrideElement(inheritedDoc.holder);
211-
Content content = processParamTag(holder, kind, writer,
209+
Content content = processParamTag(inheritedDoc.holder, kind, writer,
212210
(ParamTree) inheritedDoc.holderTag,
213211
lname,
214212
alreadyDocumented.isEmpty());

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ReturnTaglet.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ public Content getAllBlockTagOutput(Element holder, TagletWriter writer) {
121121
Input input = new DocFinder.Input(utils, holder, this);
122122
DocFinder.Output inheritedDoc = DocFinder.search(writer.configuration(), input);
123123
if (inheritedDoc.holderTag != null) {
124-
CommentHelper ch = utils.getCommentHelper(input.element);
125-
ch.setOverrideElement(inheritedDoc.holder);
126-
return writer.returnTagOutput(holder, (ReturnTree) inheritedDoc.holderTag, false);
124+
return writer.returnTagOutput(inheritedDoc.holder, (ReturnTree) inheritedDoc.holderTag, false);
127125
}
128126
return null;
129127
}

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/CommentHelper.java

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -165,37 +165,16 @@ Element getElement(ReferenceTree rtree) {
165165
}
166166
return configuration.docEnv.getTypeUtils().asElement(symbol);
167167
}
168-
// case A: the element contains no comments associated and
169-
// the comments need to be copied from ancestor
170-
// case B: the element has @inheritDoc, then the ancestral comment
171-
// as appropriate has to be copied over.
172-
173-
// Case A.
174-
if (dcTree == null && overriddenElement != null) {
175-
CommentHelper ovch = utils.getCommentHelper(overriddenElement);
176-
return ovch.getElement(rtree);
177-
}
178-
if (dcTree == null) {
179-
return null;
180-
}
181-
DocTreePath docTreePath = DocTreePath.getPath(path, dcTree, rtree);
168+
DocTreePath docTreePath = getDocTreePath(rtree);
182169
if (docTreePath == null) {
183-
// Case B.
184-
if (overriddenElement != null) {
185-
CommentHelper ovch = utils.getCommentHelper(overriddenElement);
186-
return ovch.getElement(rtree);
187-
}
188170
return null;
189171
}
190172
DocTrees doctrees = configuration.docEnv.getDocTrees();
191173
return doctrees.getElement(docTreePath);
192174
}
193175

194176
public TypeMirror getType(ReferenceTree rtree) {
195-
// Workaround for JDK-8269706
196-
if (path == null || dcTree == null || rtree == null)
197-
return null;
198-
DocTreePath docTreePath = DocTreePath.getPath(path, dcTree, rtree);
177+
DocTreePath docTreePath = getDocTreePath(rtree);
199178
if (docTreePath != null) {
200179
DocTrees doctrees = configuration.docEnv.getDocTrees();
201180
return doctrees.getType(docTreePath);
@@ -700,9 +679,18 @@ public ReferenceTree getType(DocTree dtree) {
700679
}
701680

702681
public DocTreePath getDocTreePath(DocTree dtree) {
703-
if (path == null || dcTree == null || dtree == null)
682+
if (dcTree == null && overriddenElement != null) {
683+
// This is an inherited comment, return path from ancestor.
684+
return configuration.utils.getCommentHelper(overriddenElement).getDocTreePath(dtree);
685+
} else if (path == null || dcTree == null || dtree == null) {
704686
return null;
705-
return DocTreePath.getPath(path, dcTree, dtree);
687+
}
688+
DocTreePath dtPath = DocTreePath.getPath(path, dcTree, dtree);
689+
if (dtPath == null && overriddenElement != null) {
690+
// The overriding element has a doc tree, but it doesn't contain what we're looking for.
691+
return configuration.utils.getCommentHelper(overriddenElement).getDocTreePath(dtree);
692+
}
693+
return dtPath;
706694
}
707695

708696
public Element getOverriddenElement() {

test/langtools/jdk/javadoc/doclet/testInherited/TestInherited.java

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8269722
26+
* @bug 8269722 8270866
2727
* @summary NPE in HtmlDocletWriter, reporting errors on inherited tags
2828
* @library /tools/lib ../../lib
2929
* @modules jdk.javadoc/jdk.javadoc.internal.tool
@@ -67,6 +67,14 @@ public void m(int i) { }
6767
"-Xdoclint:-missing", "-XDdoe",
6868
src.resolve("BadParam.java").toString());
6969
checkExit(Exit.OK);
70+
checkOutput("BadParam.Base.html", true, """
71+
<dt>Parameters:</dt>
72+
<dd><code>i</code> - a &lt; b</dd>
73+
""");
74+
checkOutput("BadParam.Sub.html", true, """
75+
<dt>Parameters:</dt>
76+
<dd><code>i</code> - a &lt; b</dd>
77+
""");
7078
}
7179

7280
@Test
@@ -91,5 +99,64 @@ public int m() { }
9199
"-Xdoclint:-missing",
92100
src.resolve("BadReturn.java").toString());
93101
checkExit(Exit.OK);
102+
checkOutput("BadReturn.Base.html", true, """
103+
<dt>Returns:</dt>
104+
<dd>a &lt; b</dd>
105+
""");
106+
checkOutput("BadReturn.Sub.html", true, """
107+
<dt>Returns:</dt>
108+
<dd>a &lt; b</dd>
109+
""");
110+
}
111+
112+
@Test
113+
public void testBadInheritedReference(Path base) throws Exception {
114+
Path src = base.resolve("src");
115+
tb.writeJavaFiles(src, """
116+
public class BadReference {
117+
public interface Intf {
118+
/**
119+
* {@link NonExistingClass}
120+
*/
121+
public void m();
122+
}
123+
124+
public static class Impl1 implements Intf {
125+
public void m() { }
126+
}
127+
128+
public static class Impl2 implements Intf {
129+
/**
130+
* {@inheritDoc}
131+
*/
132+
public void m() { }
133+
}
134+
135+
// subclass has doc comment but inherits main description
136+
public static class Impl3 implements Intf {
137+
/**
138+
* @since 1
139+
*/
140+
public void m() { }
141+
}
142+
}
143+
""");
144+
145+
javadoc("-d", base.resolve("out").toString(),
146+
"-Xdoclint:-reference",
147+
src.resolve("BadReference.java").toString());
148+
checkExit(Exit.OK);
149+
checkOutput("BadReference.Intf.html", true, """
150+
<div class="block"><code>NonExistingClass</code></div>
151+
""");
152+
checkOutput("BadReference.Impl1.html", true, """
153+
<div class="block"><code>NonExistingClass</code></div>
154+
""");
155+
checkOutput("BadReference.Impl2.html", true, """
156+
<div class="block"><code>NonExistingClass</code></div>
157+
""");
158+
checkOutput("BadReference.Impl3.html", true, """
159+
<div class="block"><code>NonExistingClass</code></div>
160+
""");
94161
}
95-
}
162+
}

0 commit comments

Comments
 (0)