Path: blob/master/test/langtools/tools/javac/6668794/badClass/Test.java
41153 views
/*1* Copyright (c) 2008, 2015, 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 6668794 666879626* @summary javac puts localized text in raw diagnostics27* bad diagnostic "bad class file" given for source files28* @modules jdk.compiler29*/3031import java.io.*;32import java.util.*;33import javax.tools.*;3435public class Test {36public static void main(String[] args) throws Exception {37new Test().run();38}3940void run() throws Exception {4142// compile q.A then move it to p.A43compile("A.java");4445File p = new File("p");46p.mkdirs();47new File("q/A.class").renameTo(new File("p/A.class"));4849// compile B against p.A50String[] out = compile("B.java");51if (out.length == 0)52throw new Error("no diagnostics generated");5354String expected = "B.java:6:6: compiler.err.cant.access: p.A, " +55"(compiler.misc.bad.class.file.header: A.class, " +56"(compiler.misc.class.file.wrong.class: q.A))";5758if (!out[0].equals(expected)) {59System.err.println("expected: " + expected);60System.err.println(" found: " + out[0]);61throw new Error("test failed");62}63}6465String[] compile(String file) {66String[] options = {67"-XDrawDiagnostics",68"-d", ".",69"-classpath", ".",70new File(testSrc, file).getPath()71};7273System.err.println("compile: " + Arrays.asList(options));74StringWriter sw = new StringWriter();75PrintWriter out = new PrintWriter(sw);76int rc = com.sun.tools.javac.Main.compile(options, out);77out.close();7879String outText = sw.toString();80System.err.println(outText);8182return sw.toString().split("[\\r\\n]+");83}8485File testSrc = new File(System.getProperty("test.src", "."));86}878889