1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javap/4111861/T4111861.java Mon Aug 04 15:09:02 2008 -0700 1.3 @@ -0,0 +1,101 @@ 1.4 +/* 1.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + */ 1.26 + 1.27 +import java.io.*; 1.28 + 1.29 +/* 1.30 + * @test 1.31 + * @bug 4111861 1.32 + * @summary static final field contents are not displayed 1.33 + */ 1.34 +public class T4111861 { 1.35 + public static void main(String... args) throws Exception { 1.36 + new T4111861().run(); 1.37 + } 1.38 + 1.39 + void run() throws Exception { 1.40 + File testSrc = new File(System.getProperty("test.src", ".")); 1.41 + File a_java = new File(testSrc, "A.java"); 1.42 + javac("-d", ".", a_java.getPath()); 1.43 + 1.44 + String out = javap("-classpath", ".", "-constants", "A"); 1.45 + 1.46 + String a = read(a_java); 1.47 + 1.48 + if (!filter(out).equals(filter(read(a_java)))) { 1.49 + System.out.println(out); 1.50 + throw new Exception("unexpected output"); 1.51 + } 1.52 + } 1.53 + 1.54 + String javac(String... args) throws Exception { 1.55 + StringWriter sw = new StringWriter(); 1.56 + PrintWriter pw = new PrintWriter(sw); 1.57 + int rc = com.sun.tools.javac.Main.compile(args, pw); 1.58 + if (rc != 0) 1.59 + throw new Exception("javac failed, rc=" + rc); 1.60 + return sw.toString(); 1.61 + } 1.62 + 1.63 + String javap(String... args) throws Exception { 1.64 + StringWriter sw = new StringWriter(); 1.65 + PrintWriter pw = new PrintWriter(sw); 1.66 + int rc = com.sun.tools.javap.Main.run(args, pw); 1.67 + if (rc != 0) 1.68 + throw new Exception("javap failed, rc=" + rc); 1.69 + return sw.toString(); 1.70 + } 1.71 + 1.72 + String read(File f) throws IOException { 1.73 + StringBuilder sb = new StringBuilder(); 1.74 + BufferedReader in = new BufferedReader(new FileReader(f)); 1.75 + try { 1.76 + String line; 1.77 + while ((line = in.readLine()) != null) { 1.78 + sb.append(line); 1.79 + sb.append('\n'); 1.80 + } 1.81 + } finally { 1.82 + in.close(); 1.83 + } 1.84 + return sb.toString(); 1.85 + } 1.86 + 1.87 + // return those lines beginning "public static final" 1.88 + String filter(String s) throws IOException { 1.89 + StringBuilder sb = new StringBuilder(); 1.90 + BufferedReader in = new BufferedReader(new StringReader(s)); 1.91 + try { 1.92 + String line; 1.93 + while ((line = in.readLine()) != null) { 1.94 + if (line.indexOf("public static final") > 0) { 1.95 + sb.append(line); 1.96 + sb.append('\n'); 1.97 + } 1.98 + } 1.99 + } finally { 1.100 + in.close(); 1.101 + } 1.102 + return sb.toString(); 1.103 + } 1.104 +}