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