Path: blob/master/test/langtools/tools/javap/4111861/T4111861.java
41149 views
/*1* Copyright (c) 2008, 2016, 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* @modules jdk.jdeps/com.sun.tools.javap30*/31public class T4111861 {32public static void main(String... args) throws Exception {33new T4111861().run();34}3536void run() throws Exception {37File testSrc = new File(System.getProperty("test.src", "."));38File a_java = new File(testSrc, "A.java");39javac("-d", ".", a_java.getPath());4041String out = javap("-classpath", ".", "-constants", "A");4243String a = read(a_java);4445if (!filter(out).equals(filter(read(a_java)))) {46System.out.println(out);47throw new Exception("unexpected output");48}49}5051String javac(String... args) throws Exception {52StringWriter sw = new StringWriter();53PrintWriter pw = new PrintWriter(sw);54int rc = com.sun.tools.javac.Main.compile(args, pw);55if (rc != 0)56throw new Exception("javac failed, rc=" + rc);57return sw.toString();58}5960String javap(String... args) throws Exception {61StringWriter sw = new StringWriter();62PrintWriter pw = new PrintWriter(sw);63int rc = com.sun.tools.javap.Main.run(args, pw);64if (rc != 0)65throw new Exception("javap failed, rc=" + rc);66return sw.toString();67}6869String read(File f) throws IOException {70StringBuilder sb = new StringBuilder();71BufferedReader in = new BufferedReader(new FileReader(f));72try {73String line;74while ((line = in.readLine()) != null) {75sb.append(line);76sb.append('\n');77}78} finally {79in.close();80}81return sb.toString();82}8384// return those lines beginning "public static final"85String filter(String s) throws IOException {86StringBuilder sb = new StringBuilder();87BufferedReader in = new BufferedReader(new StringReader(s));88try {89String line;90while ((line = in.readLine()) != null) {91if (line.indexOf("public static final") > 0) {92sb.append(line.trim());93sb.append('\n');94}95}96} finally {97in.close();98}99return sb.toString();100}101}102103104