Path: blob/master/test/langtools/jdk/javadoc/tool/8025693/Test.java
40971 views
/*1* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 802569326* @summary javadoc should ignore <clinit> methods found in classes on classpath27* @modules jdk.javadoc/jdk.javadoc.internal.tool28*/2930import java.io.*;3132public class Test {33public static void main(String[] args) throws Exception {34new Test().run();35}3637final File baseFile = new File("src/Base.java");38final String baseText =39"""40package p;41public class Base { static { } }42""";4344final File srcFile = new File("src/C.java");45final String srcText =46"""47package p;48/** comment */49public abstract class C extends Base { }50""";5152void run() throws Exception {53File classesDir = new File("classes");54classesDir.mkdirs();55writeFile(baseFile, baseText);56String[] javacArgs = {57"-d", classesDir.getPath(),58baseFile.getPath()59};60com.sun.tools.javac.Main.compile(javacArgs);6162writeFile(srcFile, srcText);63String[] args = {64"-d", "api",65"-classpath", classesDir.getPath(),66"-package", "p",67srcFile.getPath()68};6970ByteArrayOutputStream baos = new ByteArrayOutputStream();71PrintStream ps = new PrintStream(baos);72PrintStream prev = System.err;73System.setErr(ps);74try {75int rc = jdk.javadoc.internal.tool.Main.execute(args);76} finally {77System.err.flush();78System.setErr(prev);79}80String out = baos.toString();81System.out.println(out);8283String errorMessage = "java.lang.IllegalArgumentException: <clinit>";84if (out.contains(errorMessage))85throw new Exception("error message found: " + errorMessage);86}8788void writeFile(File file, String body) throws IOException {89file.getParentFile().mkdirs();90try (FileWriter out = new FileWriter(file)) {91out.write(body);92}93}94}95969798