Path: blob/master/test/langtools/tools/javap/T6868539.java
41144 views
/*1* Copyright (c) 2009, 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*/2223/*24* @test25* @bug 6868539 6868548 803536426* @summary javap should use current names for constant pool entries,27* remove spurious ';' from constant pool entries28* @modules jdk.jdeps/com.sun.tools.javap29*/3031import java.io.*;32import java.util.*;3334public class T68685393536{37public static void main(String... args) {38new T6868539().run();39}4041void run() {42String output = javap("T6868539");43verify(output, "Utf8 +java/lang/String"); // 1: Utf844// 2: currently unused45verify(output, "Integer +123456"); // 3: Integer46verify(output, "Float +123456.0f"); // 4: Float47verify(output, "Long +123456l"); // 5: Long48verify(output, "Double +123456.0d"); // 6: Double49verify(output, "Class +#[0-9]+ +// +T6868539"); // 7: Class50verify(output, "String +#[0-9]+ +// +not found"); // 8: String51verify(output, "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I"); // 9: Fieldref52verify(output, "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V"); // 10: Methodref53verify(output, "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V");54// 11: InterfaceMethodref55verify(output, "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V"); // 12: NameAndType56if (errors > 0)57throw new Error(errors + " found.");58}5960String notFound = " not found";6162void verify(String output, String... expects) {63for (String expect: expects) {64if (!output.matches("(?s).*" + expect + ".*"))65error(expect + notFound);66}67}6869void error(String msg) {70System.err.println(msg);71errors++;72}7374int errors;7576String javap(String className) {77String testClasses = System.getProperty("test.classes", ".");78StringWriter sw = new StringWriter();79PrintWriter out = new PrintWriter(sw);80String[] args = { "-v", "-classpath", testClasses, className };81int rc = com.sun.tools.javap.Main.run(args, out);82if (rc != 0)83throw new Error("javap failed. rc=" + rc);84out.close();85String output = sw.toString();86System.out.println("class " + className);87System.out.println(output);88return output;89}9091int i = 123456;92float f = 123456.f;93double d = 123456.;94long l = 123456L;9596void m(Runnable r) { r.run(); }97}9899100101