Wed, 24 Jun 2015 15:43:06 -0700
Merge
jjg@660 | 1 | /* |
jjg@660 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
jjg@660 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@660 | 4 | * |
jjg@660 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@660 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@660 | 7 | * published by the Free Software Foundation. |
jjg@660 | 8 | * |
jjg@660 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@660 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@660 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@660 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@660 | 13 | * accompanied this code). |
jjg@660 | 14 | * |
jjg@660 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@660 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@660 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@660 | 18 | * |
jjg@660 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@660 | 20 | * or visit www.oracle.com if you need additional information or have any |
jjg@660 | 21 | * questions. |
jjg@660 | 22 | */ |
jjg@660 | 23 | |
jjg@660 | 24 | /* |
jjg@660 | 25 | * @test |
jjg@660 | 26 | * @bug 6980017 |
jjg@660 | 27 | * @summary javap -XDdetail:source behaves badly if source not available. |
jjg@660 | 28 | */ |
jjg@660 | 29 | |
jjg@660 | 30 | import java.io.*; |
jjg@660 | 31 | |
jjg@660 | 32 | public class T6980017 { |
jjg@660 | 33 | public static void main(String... args) throws Exception { |
jjg@660 | 34 | new T6980017().run(); |
jjg@660 | 35 | } |
jjg@660 | 36 | |
jjg@660 | 37 | void run() throws Exception { |
jjg@660 | 38 | |
jjg@660 | 39 | String[] args = { |
jjg@660 | 40 | "-v", |
jjg@660 | 41 | "-XDdetails:source", |
jjg@683 | 42 | "java.lang.Object" |
jjg@660 | 43 | }; |
jjg@660 | 44 | |
jjg@660 | 45 | StringWriter sw = new StringWriter(); |
jjg@660 | 46 | PrintWriter pw = new PrintWriter(sw); |
jjg@660 | 47 | int rc = com.sun.tools.javap.Main.run(args, pw); |
jjg@660 | 48 | pw.close(); |
jjg@660 | 49 | if (rc != 0) |
jjg@660 | 50 | error("Unexpected exit code: " + rc); |
jjg@660 | 51 | |
jjg@660 | 52 | boolean foundBlankSourceLine = false; |
jjg@660 | 53 | boolean foundNoSourceLine = false; |
jjg@660 | 54 | for (String line: sw.toString().split("[\r\n]+")) { |
jjg@660 | 55 | System.err.println(line); |
jjg@660 | 56 | if (line.contains("Source code not available")) |
jjg@660 | 57 | foundNoSourceLine = true; |
jjg@660 | 58 | if (line.matches("\\s*\\( *[0-9]+\\)\\s*")) |
jjg@660 | 59 | foundBlankSourceLine = true; |
jjg@660 | 60 | } |
jjg@660 | 61 | |
jjg@660 | 62 | if (foundBlankSourceLine) |
jjg@660 | 63 | error("found blank source lines"); |
jjg@660 | 64 | |
jjg@660 | 65 | if (!foundNoSourceLine) |
jjg@660 | 66 | error("did not find \"Source code not available\" message"); |
jjg@660 | 67 | |
jjg@660 | 68 | if (errors > 0) |
jjg@660 | 69 | throw new Exception(errors + " errors occurred"); |
jjg@660 | 70 | } |
jjg@660 | 71 | |
jjg@660 | 72 | void error(String msg) { |
jjg@660 | 73 | System.err.println(msg); |
jjg@660 | 74 | errors++; |
jjg@660 | 75 | } |
jjg@660 | 76 | |
jjg@660 | 77 | int errors; |
jjg@660 | 78 | } |