Skip to content

Commit

Permalink
JDK-8332039: Cannot invoke "com.sun.source.util.DocTreePath.getTreePa…
Browse files Browse the repository at this point in the history
…th()" because "path" is null
  • Loading branch information
hns committed May 23, 2024
1 parent c2180d1 commit a9297ee
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -500,31 +500,36 @@ public ReferenceTree getType(DocTree dtree) {
}

public DocTreePath getDocTreePath(DocTree dtree) {
if (dcTree == null && element instanceof ExecutableElement ee) {
return getInheritedDocTreePath(dtree, ee);
if (dcTree == null) {
// Element does not have a doc comment.
return getInheritedDocTreePath(dtree);
}
if (path == null || dcTree == null || dtree == null) {
if (path == null || dtree == null) {
return null;
}
DocTreePath dtPath = DocTreePath.getPath(path, dcTree, dtree);
if (dtPath == null && element instanceof ExecutableElement ee) {
// The overriding element has a doc tree, but it doesn't contain what we're looking for.
return getInheritedDocTreePath(dtree, ee);
}
return dtPath;
// Doc tree isn't in current element's comment, it must be inherited.
return dtPath == null ? getInheritedDocTreePath(dtree) : dtPath;
}

private DocTreePath getInheritedDocTreePath(DocTree dtree, ExecutableElement ee) {
private DocTreePath getInheritedDocTreePath(DocTree dtree) {
Utils utils = configuration.utils;
var docFinder = utils.docFinder();
Optional<ExecutableElement> inheritedDoc = docFinder.search(ee,
(m -> {
Optional<ExecutableElement> optional = utils.getFullBody(m).isEmpty() ? Optional.empty() : Optional.of(m);
return Result.fromOptional(optional);
})).toOptional();
return inheritedDoc.isEmpty() || inheritedDoc.get().equals(ee)
? null
: utils.getCommentHelper(inheritedDoc.get()).getDocTreePath(dtree);
if (element instanceof ExecutableElement ee) {
var docFinder = utils.docFinder();
Optional<ExecutableElement> inheritedDoc = docFinder.search(ee,
(m -> {
Optional<ExecutableElement> optional = utils.getFullBody(m).isEmpty() ? Optional.empty() : Optional.of(m);
return Result.fromOptional(optional);
})).toOptional();
return inheritedDoc.isEmpty() || inheritedDoc.get().equals(ee)
? null
: utils.getCommentHelper(inheritedDoc.get()).getDocTreePath(dtree);
} else if (element instanceof TypeElement te
&& te.getEnclosingElement() instanceof TypeElement enclType) {
// Block tags can be inherited from enclosing types.
return utils.getCommentHelper(enclType).getDocTreePath(dtree);
}
return null;
}

/**
Expand Down
43 changes: 42 additions & 1 deletion test/langtools/jdk/javadoc/doclet/testSinceTag/TestSinceTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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

}

@Test
public void testSinceDefault_NestedTag(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src, """
package p;
/**
* Class C.
* @since 99 {@link C}
*/
public class C {
public static class Nested1 {
/** Class Nested, with no explicit at-since. */
public static class Nested { }
}
}""");
javadoc("-d", base.resolve("api").toString(),
"-Xdoclint:none",
"-sourcepath", src.toString(),
"p");
checkExit(Exit.OK);

checkOutput("p/C.html", true,
"""
<dl class="notes">
<dt>Since:</dt>
<dd>99 <a href="C.html" title="class in p"><code>C</code></a></dd>""");

checkOutput("p/C.Nested1.html", true,
"""
<dl class="notes">
<dt>Since:</dt>
<dd>99 <a href="C.html" title="class in p"><code>C</code></a></dd>""");

checkOutput("p/C.Nested1.Nested.html", true,
"""
<dl class="notes">
<dt>Since:</dt>
<dd>99 <a href="C.html" title="class in p"><code>C</code></a></dd>""");

}
}

0 comments on commit a9297ee

Please sign in to comment.