Skip to content

Commit a706e35

Browse files
committed
8332039: Cannot invoke "com.sun.source.util.DocTreePath.getTreePath()" because "path" is null
Reviewed-by: jjg
1 parent 612b689 commit a706e35

File tree

2 files changed

+65
-19
lines changed

2 files changed

+65
-19
lines changed

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -500,31 +500,36 @@ public ReferenceTree getType(DocTree dtree) {
500500
}
501501

502502
public DocTreePath getDocTreePath(DocTree dtree) {
503-
if (dcTree == null && element instanceof ExecutableElement ee) {
504-
return getInheritedDocTreePath(dtree, ee);
503+
if (dcTree == null) {
504+
// Element does not have a doc comment.
505+
return getInheritedDocTreePath(dtree);
505506
}
506-
if (path == null || dcTree == null || dtree == null) {
507+
if (path == null || dtree == null) {
507508
return null;
508509
}
509510
DocTreePath dtPath = DocTreePath.getPath(path, dcTree, dtree);
510-
if (dtPath == null && element instanceof ExecutableElement ee) {
511-
// The overriding element has a doc tree, but it doesn't contain what we're looking for.
512-
return getInheritedDocTreePath(dtree, ee);
513-
}
514-
return dtPath;
511+
// Doc tree isn't in current element's comment, it must be inherited.
512+
return dtPath == null ? getInheritedDocTreePath(dtree) : dtPath;
515513
}
516514

517-
private DocTreePath getInheritedDocTreePath(DocTree dtree, ExecutableElement ee) {
515+
private DocTreePath getInheritedDocTreePath(DocTree dtree) {
518516
Utils utils = configuration.utils;
519-
var docFinder = utils.docFinder();
520-
Optional<ExecutableElement> inheritedDoc = docFinder.search(ee,
521-
(m -> {
522-
Optional<ExecutableElement> optional = utils.getFullBody(m).isEmpty() ? Optional.empty() : Optional.of(m);
523-
return Result.fromOptional(optional);
524-
})).toOptional();
525-
return inheritedDoc.isEmpty() || inheritedDoc.get().equals(ee)
526-
? null
527-
: utils.getCommentHelper(inheritedDoc.get()).getDocTreePath(dtree);
517+
if (element instanceof ExecutableElement ee) {
518+
var docFinder = utils.docFinder();
519+
Optional<ExecutableElement> inheritedDoc = docFinder.search(ee,
520+
(m -> {
521+
Optional<ExecutableElement> optional = utils.getFullBody(m).isEmpty() ? Optional.empty() : Optional.of(m);
522+
return Result.fromOptional(optional);
523+
})).toOptional();
524+
return inheritedDoc.isEmpty() || inheritedDoc.get().equals(ee)
525+
? null
526+
: utils.getCommentHelper(inheritedDoc.get()).getDocTreePath(dtree);
527+
} else if (element instanceof TypeElement te
528+
&& te.getEnclosingElement() instanceof TypeElement enclType) {
529+
// Block tags can be inherited from enclosing types.
530+
return utils.getCommentHelper(enclType).getDocTreePath(dtree);
531+
}
532+
return null;
528533
}
529534

530535
/**

test/langtools/jdk/javadoc/doclet/testSinceTag/TestSinceTag.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 7180906 8026567 8239804 8324342
26+
* @bug 7180906 8026567 8239804 8324342 8332039
2727
* @summary Test to make sure that the since tag works correctly
2828
* @library /tools/lib ../../lib
2929
* @modules jdk.javadoc/jdk.javadoc.internal.tool
@@ -146,4 +146,45 @@ public class Nested { }
146146
<dd>99</dd>""");
147147

148148
}
149+
150+
@Test
151+
public void testSinceDefault_NestedTag(Path base) throws Exception {
152+
Path src = base.resolve("src");
153+
tb.writeJavaFiles(src, """
154+
package p;
155+
/**
156+
* Class C.
157+
* @since 99 {@link C}
158+
*/
159+
public class C {
160+
public static class Nested1 {
161+
/** Class Nested, with no explicit at-since. */
162+
public static class Nested { }
163+
}
164+
}""");
165+
javadoc("-d", base.resolve("api").toString(),
166+
"-Xdoclint:none",
167+
"-sourcepath", src.toString(),
168+
"p");
169+
checkExit(Exit.OK);
170+
171+
checkOutput("p/C.html", true,
172+
"""
173+
<dl class="notes">
174+
<dt>Since:</dt>
175+
<dd>99 <a href="C.html" title="class in p"><code>C</code></a></dd>""");
176+
177+
checkOutput("p/C.Nested1.html", true,
178+
"""
179+
<dl class="notes">
180+
<dt>Since:</dt>
181+
<dd>99 <a href="C.html" title="class in p"><code>C</code></a></dd>""");
182+
183+
checkOutput("p/C.Nested1.Nested.html", true,
184+
"""
185+
<dl class="notes">
186+
<dt>Since:</dt>
187+
<dd>99 <a href="C.html" title="class in p"><code>C</code></a></dd>""");
188+
189+
}
149190
}

0 commit comments

Comments
 (0)