Skip to content

Commit 8cf8e46

Browse files
committedSep 30, 2020
8253700: spurious "extends Throwable" at end of Optional.orElseThrow method declaration
Reviewed-by: prappo
1 parent 8b3d676 commit 8cf8e46

File tree

3 files changed

+111
-17
lines changed

3 files changed

+111
-17
lines changed
 

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

+10-12
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import static jdk.javadoc.internal.doclets.formats.html.LinkInfoImpl.Kind.MEMBER;
5252
import static jdk.javadoc.internal.doclets.formats.html.LinkInfoImpl.Kind.MEMBER_TYPE_PARAMS;
5353
import static jdk.javadoc.internal.doclets.formats.html.LinkInfoImpl.Kind.RECEIVER_TYPE;
54+
import static jdk.javadoc.internal.doclets.formats.html.LinkInfoImpl.Kind.THROWS_TYPE;
5455

5556
/**
5657
* Print method and constructor info.
@@ -254,19 +255,16 @@ protected Content getParameters(ExecutableElement member, boolean includeAnnotat
254255
*/
255256
protected Content getExceptions(ExecutableElement member) {
256257
List<? extends TypeMirror> exceptions = utils.asInstantiatedMethodType(typeElement, member).getThrownTypes();
257-
Content htmltree = new ContentBuilder();
258-
if (!exceptions.isEmpty()) {
259-
Content link = writer.getLink(new LinkInfoImpl(configuration, MEMBER, exceptions.get(0)));
260-
htmltree.add(link);
261-
for (int i = 1; i < exceptions.size(); i++) {
262-
htmltree.add(",");
263-
htmltree.add(DocletConstants.NL);
264-
Content exceptionLink = writer.getLink(new LinkInfoImpl(configuration, MEMBER,
265-
exceptions.get(i)));
266-
htmltree.add(exceptionLink);
258+
Content htmlTree = new ContentBuilder();
259+
for (TypeMirror t : exceptions) {
260+
if (!htmlTree.isEmpty()) {
261+
htmlTree.add(",");
262+
htmlTree.add(DocletConstants.NL);
267263
}
264+
Content link = writer.getLink(new LinkInfoImpl(configuration, THROWS_TYPE, t));
265+
htmlTree.add(link);
268266
}
269-
return htmltree;
267+
return htmlTree;
270268
}
271269

272270
protected TypeElement implementsMethodInIntfac(ExecutableElement method,
@@ -303,7 +301,7 @@ protected String getErasureAnchor(ExecutableElement executableElement) {
303301
buf.append(",");
304302
}
305303
TypeMirror t = parameters.get(i).asType();
306-
SimpleTypeVisitor9<Boolean, Void> stv = new SimpleTypeVisitor9<Boolean, Void>() {
304+
SimpleTypeVisitor9<Boolean, Void> stv = new SimpleTypeVisitor9<>() {
307305
boolean foundTypeVariable = false;
308306

309307
@Override

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,19 @@ public enum Kind {
208208
PROPERTY_COPY,
209209

210210
/**
211-
* A receiver type
211+
* A receiver type.
212212
*/
213213
RECEIVER_TYPE,
214214

215215
/**
216-
* A record component within a class signature
216+
* A record component within a class signature.
217217
*/
218-
RECORD_COMPONENT
218+
RECORD_COMPONENT,
219+
220+
/**
221+
* A type thrown from a method.
222+
*/
223+
THROWS_TYPE
219224
}
220225

221226
public final HtmlConfiguration configuration;
@@ -389,9 +394,8 @@ public final void setContext(Kind c) {
389394

390395
case RETURN_TYPE:
391396
case SUMMARY_RETURN_TYPE:
392-
excludeTypeBounds = true;
393-
break;
394397
case EXECUTABLE_MEMBER_PARAM:
398+
case THROWS_TYPE:
395399
excludeTypeBounds = true;
396400
break;
397401
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) 2002, 2020, 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 8253700
27+
* @summary spurious "extends Throwable" at end of method declaration
28+
* throws section. Make sure that the link is below a Throws heading.
29+
* @library /tools/lib ../../lib
30+
* @modules jdk.javadoc/jdk.javadoc.internal.tool
31+
* @build javadoc.tester.* toolbox.ToolBox
32+
* @run main TestThrows
33+
*/
34+
35+
import java.io.IOException;
36+
import java.nio.file.Path;
37+
38+
import toolbox.ToolBox;
39+
40+
import javadoc.tester.JavadocTester;
41+
42+
public class TestThrows extends JavadocTester {
43+
44+
public static void main(String... args) throws Exception {
45+
TestThrows tester = new TestThrows();
46+
tester.runTests(m -> new Object[] { Path.of(m.getName()) });
47+
}
48+
49+
private final ToolBox tb = new ToolBox();
50+
51+
@Test
52+
public void testThrowsWithBound(Path base) throws IOException {
53+
Path src = base.resolve("src");
54+
tb.writeJavaFiles(src,
55+
"""
56+
/**
57+
* This is interface C.
58+
*/
59+
public interface C {
60+
/**
61+
* Method m.
62+
* @param <T> the throwable
63+
* @throws T if a specific error occurs
64+
* @throws Exception if an exception occurs
65+
*/
66+
<T extends Throwable> void m() throws T, Exception;
67+
}
68+
""");
69+
70+
javadoc("-d", base.resolve("out").toString(),
71+
src.resolve("C.java").toString());
72+
checkExit(Exit.OK);
73+
74+
checkOutput("C.html", true,
75+
"""
76+
<div class="member-signature"><span class="type-parameters">&lt;T extends java\
77+
.lang.Throwable&gt;</span>&nbsp;<span class="return-type">void</span>&nbsp;<sp\
78+
an class="member-name">m</span>()
79+
throws <span class="exceptions">T,
80+
java.lang.Exception</span></div>
81+
""",
82+
"""
83+
<dl class="notes">
84+
<dt>Type Parameters:</dt>
85+
<dd><code>T</code> - the throwable</dd>
86+
<dt>Throws:</dt>
87+
<dd><code>T</code> - if a specific error occurs</dd>
88+
<dd><code>java.lang.Exception</code> - if an exception occurs</dd>
89+
</dl>
90+
""");
91+
}
92+
}

0 commit comments

Comments
 (0)
Please sign in to comment.