Skip to content

Commit 6401633

Browse files
committedJul 8, 2021
8269722: NPE in HtmlDocletWriter
Reviewed-by: hannesw
1 parent 9acb2a6 commit 6401633

File tree

5 files changed

+113
-6
lines changed

5 files changed

+113
-6
lines changed
 

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import com.sun.source.doctree.SummaryTree;
7676
import com.sun.source.doctree.SystemPropertyTree;
7777
import com.sun.source.doctree.TextTree;
78+
import com.sun.source.util.DocTreePath;
7879
import com.sun.source.util.SimpleDocTreeVisitor;
7980

8081
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
@@ -1515,9 +1516,16 @@ public Boolean visitEntity(EntityTree node, Content c) {
15151516

15161517
@Override
15171518
public Boolean visitErroneous(ErroneousTree node, Content c) {
1518-
messages.warning(ch.getDocTreePath(node),
1519-
"doclet.tag.invalid_usage", node);
1520-
result.add(new RawHtml(node.toString()));
1519+
DocTreePath dtp = ch.getDocTreePath(node);
1520+
if (dtp != null) {
1521+
String body = node.getBody();
1522+
if (body.matches("(?i)\\{@[a-z]+.*")) {
1523+
messages.warning(dtp,"doclet.tag.invalid_usage", body);
1524+
} else {
1525+
messages.warning(dtp, "doclet.tag.invalid_input", body);
1526+
}
1527+
}
1528+
result.add(Text.of(node.toString()));
15211529
return false;
15221530
}
15231531

@@ -1542,7 +1550,10 @@ public Boolean visitIndex(IndexTree node, Content p) {
15421550
public Boolean visitLink(LinkTree node, Content c) {
15431551
var inTags = context.inTags;
15441552
if (inTags.contains(LINK) || inTags.contains(LINK_PLAIN) || inTags.contains(SEE)) {
1545-
messages.warning(ch.getDocTreePath(node), "doclet.see.nested_link", "{@" + node.getTagName() + "}");
1553+
DocTreePath dtp = ch.getDocTreePath(node);
1554+
if (dtp != null) {
1555+
messages.warning(dtp, "doclet.see.nested_link", "{@" + node.getTagName() + "}");
1556+
}
15461557
Content label = commentTagsToContent(node, element, node.getLabel(), context);
15471558
if (label.isEmpty()) {
15481559
label = Text.of(node.getReference().getSignature());

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/standard.properties

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ doclet.see.class_or_package_not_found=Tag {0}: reference not found: {1}
104104
doclet.see.class_or_package_not_accessible=Tag {0}: reference not accessible: {1}
105105
doclet.see.nested_link=Tag {0}: nested link
106106
doclet.tag.invalid_usage=invalid usage of tag {0}
107+
doclet.tag.invalid_input=invalid input: ''{0}''
107108
doclet.Deprecated_API=Deprecated API
108109
doclet.Deprecated_Elements=Deprecated {0}
109110
doclet.Deprecated_In_Release=Deprecated in {0}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8269722
27+
* @summary NPE in HtmlDocletWriter, reporting errors on inherited tags
28+
* @library /tools/lib ../../lib
29+
* @modules jdk.javadoc/jdk.javadoc.internal.tool
30+
* @build toolbox.ToolBox javadoc.tester.*
31+
* @run main TestInherited
32+
*/
33+
34+
import java.nio.file.Path;
35+
36+
import javadoc.tester.JavadocTester;
37+
import toolbox.ToolBox;
38+
39+
public class TestInherited extends JavadocTester {
40+
41+
public static void main(String... args) throws Exception {
42+
TestInherited tester = new TestInherited();
43+
tester.runTests(m -> new Object[] { Path.of(m.getName())});
44+
}
45+
46+
private final ToolBox tb = new ToolBox();
47+
48+
@Test
49+
public void testBadInheritedParam(Path base) throws Exception {
50+
Path src = base.resolve("src");
51+
tb.writeJavaFiles(src, """
52+
public class BadParam {
53+
public static class Base {
54+
/**
55+
* @param i a < b
56+
*/
57+
public void m(int i) { }
58+
}
59+
60+
public static class Sub extends Base {
61+
public void m(int i) { }
62+
}
63+
}
64+
""");
65+
66+
javadoc("-d", base.resolve("out").toString(),
67+
"-Xdoclint:-missing", "-XDdoe",
68+
src.resolve("BadParam.java").toString());
69+
checkExit(Exit.OK);
70+
}
71+
72+
@Test
73+
public void testBadInheritedReturn(Path base) throws Exception {
74+
Path src = base.resolve("src");
75+
tb.writeJavaFiles(src, """
76+
public class BadReturn {
77+
public static class Base {
78+
/**
79+
* @return a < b
80+
*/
81+
public int m() { }
82+
}
83+
84+
public static class Sub extends Base {
85+
public int m() { }
86+
}
87+
}
88+
""");
89+
90+
javadoc("-d", base.resolve("out").toString(),
91+
"-Xdoclint:-missing",
92+
src.resolve("BadReturn.java").toString());
93+
checkExit(Exit.OK);
94+
}
95+
}

‎test/langtools/jdk/javadoc/doclet/testJavaFX/TestJavaFX.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public void test4() {
374374
checkExit(Exit.OK);
375375

376376
// make sure the doclet indeed emits the warning
377-
checkOutput(Output.OUT, true, "C.java:31: warning: invalid usage of tag <");
377+
checkOutput(Output.OUT, true, "C.java:31: warning: invalid input: '<'");
378378
}
379379

380380
/*

‎test/langtools/jdk/javadoc/doclet/testNonInlineHtmlTagRemoval/TestNonInlineHtmlTagRemoval.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ public void testNegative() {
8585

8686
checkOutput("Negative.html", true,
8787
"""
88-
<div class="block">case1: A hanging &lt; : xx<</div>""");
88+
<div class="block">case1: A hanging &lt; : xx&lt;</div>""");
8989
}
9090
}

0 commit comments

Comments
 (0)
Failed to load comments.