Mon, 03 May 2010 17:12:59 -0700
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
Reviewed-by: jjg, darcy
jjg@87 | 1 | /* |
jjg@87 | 2 | * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
jjg@87 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@87 | 4 | * |
jjg@87 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@87 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@87 | 7 | * published by the Free Software Foundation. |
jjg@87 | 8 | * |
jjg@87 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@87 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@87 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@87 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@87 | 13 | * accompanied this code). |
jjg@87 | 14 | * |
jjg@87 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@87 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@87 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@87 | 18 | * |
jjg@87 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
jjg@87 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
jjg@87 | 21 | * have any questions. |
jjg@87 | 22 | */ |
jjg@87 | 23 | |
jjg@87 | 24 | import java.io.*; |
jjg@87 | 25 | |
jjg@87 | 26 | /* |
jjg@87 | 27 | * @test |
jjg@87 | 28 | * @bug 4111861 |
jjg@87 | 29 | * @summary static final field contents are not displayed |
jjg@87 | 30 | */ |
jjg@87 | 31 | public class T4111861 { |
jjg@87 | 32 | public static void main(String... args) throws Exception { |
jjg@87 | 33 | new T4111861().run(); |
jjg@87 | 34 | } |
jjg@87 | 35 | |
jjg@87 | 36 | void run() throws Exception { |
jjg@87 | 37 | File testSrc = new File(System.getProperty("test.src", ".")); |
jjg@87 | 38 | File a_java = new File(testSrc, "A.java"); |
jjg@87 | 39 | javac("-d", ".", a_java.getPath()); |
jjg@87 | 40 | |
jjg@87 | 41 | String out = javap("-classpath", ".", "-constants", "A"); |
jjg@87 | 42 | |
jjg@87 | 43 | String a = read(a_java); |
jjg@87 | 44 | |
jjg@87 | 45 | if (!filter(out).equals(filter(read(a_java)))) { |
jjg@87 | 46 | System.out.println(out); |
jjg@87 | 47 | throw new Exception("unexpected output"); |
jjg@87 | 48 | } |
jjg@87 | 49 | } |
jjg@87 | 50 | |
jjg@87 | 51 | String javac(String... args) throws Exception { |
jjg@87 | 52 | StringWriter sw = new StringWriter(); |
jjg@87 | 53 | PrintWriter pw = new PrintWriter(sw); |
jjg@87 | 54 | int rc = com.sun.tools.javac.Main.compile(args, pw); |
jjg@87 | 55 | if (rc != 0) |
jjg@87 | 56 | throw new Exception("javac failed, rc=" + rc); |
jjg@87 | 57 | return sw.toString(); |
jjg@87 | 58 | } |
jjg@87 | 59 | |
jjg@87 | 60 | String javap(String... args) throws Exception { |
jjg@87 | 61 | StringWriter sw = new StringWriter(); |
jjg@87 | 62 | PrintWriter pw = new PrintWriter(sw); |
jjg@87 | 63 | int rc = com.sun.tools.javap.Main.run(args, pw); |
jjg@87 | 64 | if (rc != 0) |
jjg@87 | 65 | throw new Exception("javap failed, rc=" + rc); |
jjg@87 | 66 | return sw.toString(); |
jjg@87 | 67 | } |
jjg@87 | 68 | |
jjg@87 | 69 | String read(File f) throws IOException { |
jjg@87 | 70 | StringBuilder sb = new StringBuilder(); |
jjg@87 | 71 | BufferedReader in = new BufferedReader(new FileReader(f)); |
jjg@87 | 72 | try { |
jjg@87 | 73 | String line; |
jjg@87 | 74 | while ((line = in.readLine()) != null) { |
jjg@87 | 75 | sb.append(line); |
jjg@87 | 76 | sb.append('\n'); |
jjg@87 | 77 | } |
jjg@87 | 78 | } finally { |
jjg@87 | 79 | in.close(); |
jjg@87 | 80 | } |
jjg@87 | 81 | return sb.toString(); |
jjg@87 | 82 | } |
jjg@87 | 83 | |
jjg@87 | 84 | // return those lines beginning "public static final" |
jjg@87 | 85 | String filter(String s) throws IOException { |
jjg@87 | 86 | StringBuilder sb = new StringBuilder(); |
jjg@87 | 87 | BufferedReader in = new BufferedReader(new StringReader(s)); |
jjg@87 | 88 | try { |
jjg@87 | 89 | String line; |
jjg@87 | 90 | while ((line = in.readLine()) != null) { |
jjg@87 | 91 | if (line.indexOf("public static final") > 0) { |
jjg@349 | 92 | sb.append(line.trim()); |
jjg@87 | 93 | sb.append('\n'); |
jjg@87 | 94 | } |
jjg@87 | 95 | } |
jjg@87 | 96 | } finally { |
jjg@87 | 97 | in.close(); |
jjg@87 | 98 | } |
jjg@87 | 99 | return sb.toString(); |
jjg@87 | 100 | } |
jjg@87 | 101 | } |