jjg@10: /* jjg@10: * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. jjg@10: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@10: * jjg@10: * This code is free software; you can redistribute it and/or modify it jjg@10: * under the terms of the GNU General Public License version 2 only, as jjg@10: * published by the Free Software Foundation. Sun designates this jjg@10: * particular file as subject to the "Classpath" exception as provided jjg@10: * by Sun in the LICENSE file that accompanied this code. jjg@10: * jjg@10: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@10: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@10: * version 2 for more details (a copy is included in the LICENSE file that jjg@10: * accompanied this code). jjg@10: * jjg@10: * You should have received a copy of the GNU General Public License version jjg@10: * 2 along with this work; if not, write to the Free Software Foundation, jjg@10: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@10: * jjg@10: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, jjg@10: * CA 95054 USA or visit www.sun.com if you need additional information or jjg@10: * have any questions. jjg@10: */ jjg@10: jjg@10: /* jjg@10: * @test jjg@10: * @bug 6668802 jjg@10: * @summary javac handles diagnostics for last line badly, if line not terminated by newline jjg@10: */ jjg@10: jjg@10: import java.io.*; jjg@10: import java.util.*; jjg@10: jjg@10: public class T6668802 jjg@10: { jjg@10: public static void main(String[] args) throws Exception { jjg@10: new T6668802().run(); jjg@10: } jjg@10: jjg@10: void run() throws Exception { jjg@10: String test = "public class Test {"; jjg@10: File f = writeTestFile("Test.java", test); jjg@10: String[] out = compileBadFile(f); jjg@10: for (String line: out) jjg@10: System.err.println(">>>" + line + "<<<"); jjg@10: if (!out[1].equals(test)) { jjg@10: show("expected", test); jjg@10: show(" actual", out[1]); jjg@10: throw new Error("test failed"); jjg@10: } jjg@10: } jjg@10: jjg@10: File writeTestFile(String path, String contents) throws IOException { jjg@10: File f = new File(path); jjg@10: FileWriter out = new FileWriter(f); jjg@10: out.write(contents); jjg@10: out.close(); jjg@10: return f; jjg@10: } jjg@10: jjg@10: String[] compileBadFile(File file) throws IOException { jjg@10: List options = new ArrayList(); jjg@10: options.add(file.getPath()); jjg@10: System.err.println("compile: " + options); jjg@10: String[] opts = options.toArray(new String[options.size()]); jjg@10: StringWriter sw = new StringWriter(); jjg@10: PrintWriter out = new PrintWriter(sw); jjg@10: int rc = com.sun.tools.javac.Main.compile(opts, out); jjg@10: if (rc == 0) jjg@10: throw new Error("compilation succeeded unexpectedly"); jjg@10: out.close(); jjg@10: return sw.toString().split("[\n\r]+"); jjg@10: } jjg@10: jjg@10: void show(String prefix, String text) { jjg@10: System.err.println(prefix + ": (" + text.length() + ") " + text); jjg@10: } jjg@10: }