Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javadoc/8025693/Test.java
38813 views
/*1* Copyright (c) 2013, 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*/2829import java.io.*;3031public class Test {32public static void main(String[] args) throws Exception {33new Test().run();34}3536final File baseFile = new File("src/Base.java");37final String baseText =38"package p;\n" +39"public class Base { static { } }\n";4041final File srcFile = new File("src/C.java");42final String srcText =43"package p;\n" +44"/** comment */\n" +45"public abstract class C extends Base { }\n";4647void run() throws Exception {48File classesDir = new File("classes");49classesDir.mkdirs();50writeFile(baseFile, baseText);51String[] javacArgs = {52"-d", classesDir.getPath(),53baseFile.getPath()54};55com.sun.tools.javac.Main.compile(javacArgs);5657writeFile(srcFile, srcText);58String[] args = {59"-d", "api",60"-classpath", classesDir.getPath(),61"-package", "p",62srcFile.getPath()63};6465ByteArrayOutputStream baos = new ByteArrayOutputStream();66PrintStream ps = new PrintStream(baos);67PrintStream prev = System.err;68System.setErr(ps);69try {70int rc = com.sun.tools.javadoc.Main.execute(args);71} finally {72System.err.flush();73System.setErr(prev);74}75String out = baos.toString();76System.out.println(out);7778String errorMessage = "java.lang.IllegalArgumentException: <clinit>";79if (out.contains(errorMessage))80throw new Exception("error message found: " + errorMessage);81}8283void writeFile(File file, String body) throws IOException {84file.getParentFile().mkdirs();85try (FileWriter out = new FileWriter(file)) {86out.write(body);87}88}89}90919293