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