jjg@12: /* jjg@12: * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. jjg@12: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@12: * jjg@12: * This code is free software; you can redistribute it and/or modify it jjg@12: * under the terms of the GNU General Public License version 2 only, as jjg@12: * published by the Free Software Foundation. Sun designates this jjg@12: * particular file as subject to the "Classpath" exception as provided jjg@12: * by Sun in the LICENSE file that accompanied this code. jjg@12: * jjg@12: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@12: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@12: * version 2 for more details (a copy is included in the LICENSE file that jjg@12: * accompanied this code). jjg@12: * jjg@12: * You should have received a copy of the GNU General Public License version jjg@12: * 2 along with this work; if not, write to the Free Software Foundation, jjg@12: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@12: * jjg@12: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, jjg@12: * CA 95054 USA or visit www.sun.com if you need additional information or jjg@12: * have any questions. jjg@12: */ jjg@12: jjg@12: /* jjg@12: * @test jjg@12: * @bug 6668794 6668796 jjg@12: * @summary javac puts localized text in raw diagnostics jjg@12: * bad diagnostic "bad class file" given for source files jjg@12: */ jjg@12: jjg@12: import java.io.*; jjg@12: import java.util.*; jjg@12: import javax.tools.*; jjg@12: jjg@12: public class Test { jjg@12: public static void main(String[] args) throws Exception { jjg@12: new Test().run(); jjg@12: } jjg@12: jjg@12: void run() throws Exception { jjg@12: jjg@12: // compile q.A then move it to p.A jjg@12: compile("A.java"); jjg@12: jjg@12: File p = new File("p"); jjg@12: p.mkdirs(); jjg@12: new File("q/A.class").renameTo(new File("p/A.class")); jjg@12: jjg@12: // compile B against p.A jjg@12: String[] out = compile("B.java"); jjg@12: if (out.length == 0) jjg@12: throw new Error("no diagnostics generated"); jjg@12: jjg@12: String expected = "B.java:6:6: compiler.err.cant.access: p.A, " + jjg@12: "(- compiler.misc.bad.class.file.header: A.class, " + jjg@12: "(- compiler.misc.class.file.wrong.class: q.A))"; jjg@12: jjg@12: if (!out[0].equals(expected)) { jjg@12: System.err.println("expected: " + expected); jjg@12: System.err.println(" found: " + out[0]); jjg@12: throw new Error("test failed"); jjg@12: } jjg@12: } jjg@12: jjg@12: String[] compile(String file) { jjg@12: String[] options = { jjg@12: "-XDrawDiagnostics", jjg@12: "-d", ".", jjg@12: "-classpath", ".", jjg@12: new File(testSrc, file).getPath() jjg@12: }; jjg@12: jjg@12: System.err.println("compile: " + Arrays.asList(options)); jjg@12: StringWriter sw = new StringWriter(); jjg@12: PrintWriter out = new PrintWriter(sw); jjg@12: int rc = com.sun.tools.javac.Main.compile(options, out); jjg@12: out.close(); jjg@12: jjg@12: String outText = sw.toString(); jjg@12: System.err.println(outText); jjg@12: jjg@12: return sw.toString().split("[\\r\\n]+"); jjg@12: } jjg@12: jjg@12: File testSrc = new File(System.getProperty("test.src", ".")); jjg@12: }