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 "<div class=\"memberSignature\"><span class=\"modifiers\">public</span> " 77 + "<span class=\"returnType\">void</span> <span class=\"memberName\">readObject</span>" 78 + "(<span class=\"arguments\">java.io.ObjectInputStream arg0)</span>\n" 79 + " throws <span class=\"exceptions\">java.lang.ClassNotFoundException,\n" 80 + "java.io.IOException</span></div>\n"); 81 } 82 83 void createTestClass(Path base, Path srcDir) throws Exception { 84 //create A.java , compile the class in classes dir 85 Path classes = base.resolve("classes"); 86 tb.createDirectories(classes); 87 88 MethodBuilder method = MethodBuilder 89 .parse("public void readObject(ObjectInputStream s)" 90 + "throws ClassNotFoundException, IOException {}") 91 .setComments( 92 "@param s a serialization stream", 93 "@throws ClassNotFoundException if class not found", 94 "@throws java.io.IOException if an IO error", 95 "@serial"); 96 97 new ClassBuilder(tb, "A") 98 .setModifiers("public", "abstract", "class") 99 .addImplements("Serializable") 100 .addImports("java.io.*") 101 .addMembers(method) 102 .write(srcDir); 103 new JavacTask(tb).files(srcDir.resolve("A.java")).outdir(classes).run(); 104 105 new ClassBuilder(tb, "B") 106 .setExtends("A") 107 .setModifiers("public", "class") 108 .write(srcDir); 109 } 110 } --- EOF ---