jjg@87: /* ohair@554: * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. jjg@87: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@87: * jjg@87: * This code is free software; you can redistribute it and/or modify it jjg@87: * under the terms of the GNU General Public License version 2 only, as jjg@87: * published by the Free Software Foundation. jjg@87: * jjg@87: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@87: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@87: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@87: * version 2 for more details (a copy is included in the LICENSE file that jjg@87: * accompanied this code). jjg@87: * jjg@87: * You should have received a copy of the GNU General Public License version jjg@87: * 2 along with this work; if not, write to the Free Software Foundation, jjg@87: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@87: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. jjg@87: */ jjg@87: jjg@87: import java.io.*; jjg@87: jjg@87: /* jjg@87: * @test jjg@87: * @bug 4111861 jjg@87: * @summary static final field contents are not displayed jjg@87: */ jjg@87: public class T4111861 { jjg@87: public static void main(String... args) throws Exception { jjg@87: new T4111861().run(); jjg@87: } jjg@87: jjg@87: void run() throws Exception { jjg@87: File testSrc = new File(System.getProperty("test.src", ".")); jjg@87: File a_java = new File(testSrc, "A.java"); jjg@87: javac("-d", ".", a_java.getPath()); jjg@87: jjg@87: String out = javap("-classpath", ".", "-constants", "A"); jjg@87: jjg@87: String a = read(a_java); jjg@87: jjg@87: if (!filter(out).equals(filter(read(a_java)))) { jjg@87: System.out.println(out); jjg@87: throw new Exception("unexpected output"); jjg@87: } jjg@87: } jjg@87: jjg@87: String javac(String... args) throws Exception { jjg@87: StringWriter sw = new StringWriter(); jjg@87: PrintWriter pw = new PrintWriter(sw); jjg@87: int rc = com.sun.tools.javac.Main.compile(args, pw); jjg@87: if (rc != 0) jjg@87: throw new Exception("javac failed, rc=" + rc); jjg@87: return sw.toString(); jjg@87: } jjg@87: jjg@87: String javap(String... args) throws Exception { jjg@87: StringWriter sw = new StringWriter(); jjg@87: PrintWriter pw = new PrintWriter(sw); jjg@87: int rc = com.sun.tools.javap.Main.run(args, pw); jjg@87: if (rc != 0) jjg@87: throw new Exception("javap failed, rc=" + rc); jjg@87: return sw.toString(); jjg@87: } jjg@87: jjg@87: String read(File f) throws IOException { jjg@87: StringBuilder sb = new StringBuilder(); jjg@87: BufferedReader in = new BufferedReader(new FileReader(f)); jjg@87: try { jjg@87: String line; jjg@87: while ((line = in.readLine()) != null) { jjg@87: sb.append(line); jjg@87: sb.append('\n'); jjg@87: } jjg@87: } finally { jjg@87: in.close(); jjg@87: } jjg@87: return sb.toString(); jjg@87: } jjg@87: jjg@87: // return those lines beginning "public static final" jjg@87: String filter(String s) throws IOException { jjg@87: StringBuilder sb = new StringBuilder(); jjg@87: BufferedReader in = new BufferedReader(new StringReader(s)); jjg@87: try { jjg@87: String line; jjg@87: while ((line = in.readLine()) != null) { jjg@87: if (line.indexOf("public static final") > 0) { jjg@349: sb.append(line.trim()); jjg@87: sb.append('\n'); jjg@87: } jjg@87: } jjg@87: } finally { jjg@87: in.close(); jjg@87: } jjg@87: return sb.toString(); jjg@87: } jjg@87: }