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