1 /*
2 * Copyright (c) 2018, 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 8199307
27 * @summary NPE in jdk.javadoc.internal.doclets.toolkit.util.Utils.getLineNumber
28 * @library /tools/lib ../../lib
29 * @modules
30 * jdk.javadoc/jdk.javadoc.internal.tool
31 * jdk.compiler/com.sun.tools.javac.api
32 * jdk.compiler/com.sun.tools.javac.main
33 * @build javadoc.tester.*
34 * @run main TestSerializedFormWithClassFile
35 */
36
37 import builder.ClassBuilder;
38
39 import java.nio.file.Path;
40 import java.nio.file.Paths;
41
42 import builder.ClassBuilder.MethodBuilder;
43 import toolbox.ToolBox;
44 import toolbox.JavacTask;
45
46 import javadoc.tester.JavadocTester;
47
48 public class TestSerializedFormWithClassFile extends JavadocTester {
49
50 final ToolBox tb;
51
52 public static void main(String... args) throws Exception {
53 TestSerializedFormWithClassFile tester = new TestSerializedFormWithClassFile();
54 tester.runTests(m -> new Object[]{Paths.get(m.getName())});
55 }
56
57 TestSerializedFormWithClassFile() {
58 tb = new ToolBox();
59 }
60
61 @Test
62 public void test(Path base) throws Exception {
63 Path srcDir = base.resolve("src");
64 createTestClass(base, srcDir);
65
66 Path outDir = base.resolve("out");
67 javadoc("-d", outDir.toString(),
68 "-linksource",
69 "-classpath", base.resolve("classes").toString(),
70 "-sourcepath", "",
71 srcDir.resolve("B.java").toString());
72
73 checkExit(Exit.OK);
74
75 checkOutput("serialized-form.html", true,
76 "<pre>public void readObject"
77 + "(java.io.ObjectInputStream arg0)\n"
78 + " throws java.lang.ClassNotFoundException,\n"
79 + " java.io.IOException</pre>\n");
80 }
81
82 void createTestClass(Path base, Path srcDir) throws Exception {
83 //create A.java , compile the class in classes dir
84 Path classes = base.resolve("classes");
85 tb.createDirectories(classes);
86
87 MethodBuilder method = MethodBuilder
88 .parse("public void readObject(ObjectInputStream s)"
89 + "throws ClassNotFoundException, IOException {}")
90 .setComments(
91 "@param s a serialization stream",
92 "@throws ClassNotFoundException if class not found",
93 "@throws java.io.IOException if an IO error",
94 "@serial");
95
96 new ClassBuilder(tb, "A")
97 .setModifiers("public", "abstract", "class")
98 .addImplements("Serializable")
99 .addImports("java.io.*")
100 .addMembers(method)
101 .write(srcDir);
102 new JavacTask(tb).files(srcDir.resolve("A.java")).outdir(classes).run();
103
104 new ClassBuilder(tb, "B")
105 .setExtends("A")
106 .setModifiers("public", "class")
107 .write(srcDir);
108 }
109 }
--- EOF ---