Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/4111861/T4111861.java
32285 views
/*1* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.*;2425/*26* @test27* @bug 411186128* @summary static final field contents are not displayed29*/30public class T4111861 {31public static void main(String... args) throws Exception {32new T4111861().run();33}3435void run() throws Exception {36File testSrc = new File(System.getProperty("test.src", "."));37File a_java = new File(testSrc, "A.java");38javac("-d", ".", a_java.getPath());3940String out = javap("-classpath", ".", "-constants", "A");4142String a = read(a_java);4344if (!filter(out).equals(filter(read(a_java)))) {45System.out.println(out);46throw new Exception("unexpected output");47}48}4950String javac(String... args) throws Exception {51StringWriter sw = new StringWriter();52PrintWriter pw = new PrintWriter(sw);53int rc = com.sun.tools.javac.Main.compile(args, pw);54if (rc != 0)55throw new Exception("javac failed, rc=" + rc);56return sw.toString();57}5859String javap(String... args) throws Exception {60StringWriter sw = new StringWriter();61PrintWriter pw = new PrintWriter(sw);62int rc = com.sun.tools.javap.Main.run(args, pw);63if (rc != 0)64throw new Exception("javap failed, rc=" + rc);65return sw.toString();66}6768String read(File f) throws IOException {69StringBuilder sb = new StringBuilder();70BufferedReader in = new BufferedReader(new FileReader(f));71try {72String line;73while ((line = in.readLine()) != null) {74sb.append(line);75sb.append('\n');76}77} finally {78in.close();79}80return sb.toString();81}8283// return those lines beginning "public static final"84String filter(String s) throws IOException {85StringBuilder sb = new StringBuilder();86BufferedReader in = new BufferedReader(new StringReader(s));87try {88String line;89while ((line = in.readLine()) != null) {90if (line.indexOf("public static final") > 0) {91sb.append(line.trim());92sb.append('\n');93}94}95} finally {96in.close();97}98return sb.toString();99}100}101102103