Skip to content

Commit e383d26

Browse files
committedNov 8, 2021
8275199: Bogus warning generated for serializable records
Reviewed-by: hannesw
1 parent 7e73bca commit e383d26

File tree

3 files changed

+81
-48
lines changed

3 files changed

+81
-48
lines changed
 

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ClassBuilder.java

+15-29
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,8 @@ private ClassBuilder(Context context, TypeElement typeElement, ClassWriter write
8686
this.writer = writer;
8787
this.utils = configuration.utils;
8888
switch (typeElement.getKind()) {
89-
case ENUM:
90-
setEnumDocumentation(typeElement);
91-
break;
92-
93-
case RECORD:
94-
setRecordDocumentation(typeElement);
95-
break;
89+
case ENUM -> setEnumDocumentation(typeElement);
90+
case RECORD -> setRecordDocumentation(typeElement);
9691
}
9792
}
9893

@@ -119,27 +114,15 @@ public void build() throws DocletException {
119114
* @throws DocletException if there is a problem while building the documentation
120115
*/
121116
protected void buildClassDoc() throws DocletException {
122-
String key;
123-
switch (typeElement.getKind()) {
124-
case INTERFACE:
125-
key = "doclet.Interface";
126-
break;
127-
case ENUM:
128-
key = "doclet.Enum";
129-
break;
130-
case RECORD:
131-
key = "doclet.RecordClass";
132-
break;
133-
case ANNOTATION_TYPE:
134-
key = "doclet.AnnotationType";
135-
break;
136-
case CLASS:
137-
key = "doclet.Class";
138-
break;
139-
default:
140-
throw new IllegalStateException(typeElement.getKind() + " " + typeElement);
141-
}
142-
Content contentTree = writer.getHeader(resources.getText(key) + " "
117+
String key = switch (typeElement.getKind()) {
118+
case INTERFACE -> "doclet.Interface";
119+
case ENUM -> "doclet.Enum";
120+
case RECORD -> "doclet.RecordClass";
121+
case ANNOTATION_TYPE -> "doclet.AnnotationType";
122+
case CLASS -> "doclet.Class";
123+
default -> throw new IllegalStateException(typeElement.getKind() + " " + typeElement);
124+
};
125+
Content contentTree = writer.getHeader(resources.getText(key) + " "
143126
+ utils.getSimpleName(typeElement));
144127
Content classContentTree = writer.getClassContentHeader();
145128

@@ -467,7 +450,10 @@ private void setRecordDocumentation(TypeElement elem) {
467450
}
468451
}
469452

470-
for (VariableElement ve : utils.getFields(elem)) {
453+
var fields = utils.isSerializable(elem)
454+
? utils.getFieldsUnfiltered(elem)
455+
: utils.getFields(elem);
456+
for (VariableElement ve : fields) {
471457
// The fields for the record component cannot be declared by the
472458
// user and so cannot have any pre-existing comment.
473459
Name name = ve.getSimpleName();

‎test/langtools/jdk/javadoc/doclet/testRecordTypes/TestRecordTypes.java

+54-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8225055 8239804 8246774 8258338 8261976
26+
* @bug 8225055 8239804 8246774 8258338 8261976 8275199
2727
* @summary Record types
2828
* @library /tools/lib ../../lib
2929
* @modules jdk.javadoc/jdk.javadoc.internal.tool
@@ -51,13 +51,11 @@ public static void main(String... args) throws Exception {
5151

5252
private final ToolBox tb = new ToolBox();
5353

54-
// The following constants are set up for use with -linkoffline
55-
// (but note: JDK 11 does not include java.lang.Record, so expect
56-
// some 404 broken links until we can update this to a stable version.)
54+
// The following constants are set up for use with -linkoffline.
5755
private static final String externalDocs =
58-
"https://docs.oracle.com/en/java/javase/11/docs/api";
56+
"https://docs.oracle.com/en/java/javase/17/docs/api";
5957
private static final String localDocs =
60-
Path.of(testSrc).resolve("jdk11").toUri().toString();
58+
Path.of(testSrc).resolve("jdk17").toUri().toString();
6159

6260
@Test
6361
public void testRecordKeywordUnnamedPackage(Path base) throws IOException {
@@ -391,17 +389,17 @@ public record R(int r1) {
391389
}
392390

393391
@Test
394-
public void testExamples(Path base) throws IOException {
392+
public void testExamples(Path base) {
395393
javadoc("-d", base.resolve("out-no-link").toString(),
396394
"-quiet", "-noindex",
397-
"-sourcepath", testSrc.toString(),
395+
"-sourcepath", testSrc,
398396
"-linksource",
399397
"examples");
400398

401399
checkExit(Exit.OK);
402400
javadoc("-d", base.resolve("out-with-link").toString(),
403401
"-quiet", "-noindex",
404-
"-sourcepath", testSrc.toString(),
402+
"-sourcepath", testSrc,
405403
"-linksource",
406404
"-linkoffline", externalDocs, localDocs,
407405
"examples");
@@ -560,4 +558,51 @@ public record R(@Deprecated int r1) { }""");
560558
<div class="col-last even-row-color"></div>
561559
</div>""");
562560
}
561+
562+
@Test
563+
public void testSerializableType(Path base) throws IOException {
564+
Path src = base.resolve("src");
565+
tb.writeJavaFiles(src,
566+
"""
567+
/**
568+
* A point,
569+
* @param x the x coord
570+
* @param y the y coord
571+
*/
572+
public record Point(int x, int y) implements java.io.Serializable { }""");
573+
574+
javadoc("-d", base.resolve("out").toString(),
575+
"-quiet", "-noindex", "--no-platform-links",
576+
src.resolve("Point.java").toString());
577+
checkExit(Exit.OK);
578+
579+
checkOutput(Output.OUT, false,
580+
"warning: no comment");
581+
582+
checkOutput("serialized-form.html", true,
583+
"""
584+
<section class="serialized-class-details" id="Point">
585+
<h3>Record Class&nbsp;<a href="Point.html" title="class in Unnamed Package">Point</a></h3>
586+
<div class="type-signature">class Point extends java.lang.Record implements java.io.Serializable</div>
587+
<ul class="block-list">
588+
<li>
589+
<section class="detail">
590+
<h4>Serialized Fields</h4>
591+
<ul class="block-list">
592+
<li class="block-list">
593+
<h5>x</h5>
594+
<pre>int x</pre>
595+
<div class="block">The field for the <a href="./Point.html#param-x"><code>x</code></a> record component.</div>
596+
</li>
597+
<li class="block-list">
598+
<h5>y</h5>
599+
<pre>int y</pre>
600+
<div class="block">The field for the <a href="./Point.html#param-y"><code>y</code></a> record component.</div>
601+
</li>
602+
</ul>
603+
</section>
604+
</li>
605+
</ul>
606+
</section>""");
607+
}
563608
}

‎test/langtools/jdk/javadoc/doclet/testRecordTypes/jdk11/element-list ‎test/langtools/jdk/javadoc/doclet/testRecordTypes/jdk17/element-list

+12-10
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ module:java.base
22
java.io
33
java.lang
44
java.lang.annotation
5+
java.lang.constant
56
java.lang.invoke
67
java.lang.module
78
java.lang.ref
89
java.lang.reflect
10+
java.lang.runtime
911
java.math
1012
java.net
1113
java.net.spi
@@ -18,7 +20,6 @@ java.nio.file
1820
java.nio.file.attribute
1921
java.nio.file.spi
2022
java.security
21-
java.security.acl
2223
java.security.cert
2324
java.security.interfaces
2425
java.security.spec
@@ -35,6 +36,7 @@ java.util.concurrent.atomic
3536
java.util.concurrent.locks
3637
java.util.function
3738
java.util.jar
39+
java.util.random
3840
java.util.regex
3941
java.util.spi
4042
java.util.stream
@@ -131,14 +133,14 @@ javax.naming
131133
javax.naming.directory
132134
javax.naming.event
133135
javax.naming.ldap
136+
javax.naming.ldap.spi
134137
javax.naming.spi
135138
module:java.net.http
136139
java.net.http
137140
module:java.prefs
138141
java.util.prefs
139142
module:java.rmi
140143
java.rmi
141-
java.rmi.activation
142144
java.rmi.dgc
143145
java.rmi.registry
144146
java.rmi.server
@@ -219,12 +221,14 @@ module:jdk.hotspot.agent
219221
module:jdk.httpserver
220222
com.sun.net.httpserver
221223
com.sun.net.httpserver.spi
224+
module:jdk.incubator.foreign
225+
jdk.incubator.foreign
226+
module:jdk.incubator.vector
227+
jdk.incubator.vector
222228
module:jdk.jartool
223229
com.sun.jarsigner
224230
jdk.security.jarsigner
225231
module:jdk.javadoc
226-
com.sun.javadoc
227-
com.sun.tools.javadoc
228232
jdk.javadoc.doclet
229233
module:jdk.jcmd
230234
module:jdk.jconsole
@@ -241,6 +245,7 @@ module:jdk.jfr
241245
jdk.jfr
242246
jdk.jfr.consumer
243247
module:jdk.jlink
248+
module:jdk.jpackage
244249
module:jdk.jshell
245250
jdk.jshell
246251
jdk.jshell.execution
@@ -260,10 +265,8 @@ module:jdk.naming.rmi
260265
module:jdk.net
261266
jdk.net
262267
jdk.nio
263-
module:jdk.pack
264-
module:jdk.scripting.nashorn
265-
jdk.nashorn.api.scripting
266-
jdk.nashorn.api.tree
268+
module:jdk.nio.mapmode
269+
jdk.nio.mapmode
267270
module:jdk.sctp
268271
com.sun.nio.sctp
269272
module:jdk.security.auth
@@ -278,5 +281,4 @@ org.w3c.dom.css
278281
org.w3c.dom.html
279282
org.w3c.dom.stylesheets
280283
org.w3c.dom.xpath
281-
module:jdk.zipfs
282-
284+
module:jdk.zipfs

0 commit comments

Comments
 (0)
Please sign in to comment.