659N/A/*
659N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
659N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
659N/A *
659N/A * This code is free software; you can redistribute it and/or modify it
659N/A * under the terms of the GNU General Public License version 2 only, as
659N/A * published by the Free Software Foundation.
659N/A *
659N/A * This code is distributed in the hope that it will be useful, but WITHOUT
659N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
659N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
659N/A * version 2 for more details (a copy is included in the LICENSE file that
659N/A * accompanied this code).
659N/A *
659N/A * You should have received a copy of the GNU General Public License version
659N/A * 2 along with this work; if not, write to the Free Software Foundation,
659N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
659N/A *
659N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
659N/A * or visit www.oracle.com if you need additional information or have any
659N/A * questions.
659N/A */
659N/A
659N/A/*
659N/A * @test
659N/A * @bug 6980017
659N/A * @summary javap -XDdetail:source behaves badly if source not available.
659N/A */
659N/A
659N/Aimport java.io.*;
659N/A
659N/Apublic class T6980017 {
659N/A public static void main(String... args) throws Exception {
659N/A new T6980017().run();
659N/A }
659N/A
659N/A void run() throws Exception {
659N/A
659N/A String[] args = {
659N/A "-v",
659N/A "-XDdetails:source",
682N/A "java.lang.Object"
659N/A };
659N/A
659N/A StringWriter sw = new StringWriter();
659N/A PrintWriter pw = new PrintWriter(sw);
659N/A int rc = com.sun.tools.javap.Main.run(args, pw);
659N/A pw.close();
659N/A if (rc != 0)
659N/A error("Unexpected exit code: " + rc);
659N/A
659N/A boolean foundBlankSourceLine = false;
659N/A boolean foundNoSourceLine = false;
659N/A for (String line: sw.toString().split("[\r\n]+")) {
659N/A System.err.println(line);
659N/A if (line.contains("Source code not available"))
659N/A foundNoSourceLine = true;
659N/A if (line.matches("\\s*\\( *[0-9]+\\)\\s*"))
659N/A foundBlankSourceLine = true;
659N/A }
659N/A
659N/A if (foundBlankSourceLine)
659N/A error("found blank source lines");
659N/A
659N/A if (!foundNoSourceLine)
659N/A error("did not find \"Source code not available\" message");
659N/A
659N/A if (errors > 0)
659N/A throw new Exception(errors + " errors occurred");
659N/A }
659N/A
659N/A void error(String msg) {
659N/A System.err.println(msg);
659N/A errors++;
659N/A }
659N/A
659N/A int errors;
659N/A}