jjg@355: /* ohair@798: * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. jjg@355: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@355: * jjg@355: * This code is free software; you can redistribute it and/or modify it jjg@355: * under the terms of the GNU General Public License version 2 only, as jjg@355: * published by the Free Software Foundation. jjg@355: * jjg@355: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@355: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@355: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@355: * version 2 for more details (a copy is included in the LICENSE file that jjg@355: * accompanied this code). jjg@355: * jjg@355: * You should have received a copy of the GNU General Public License version jjg@355: * 2 along with this work; if not, write to the Free Software Foundation, jjg@355: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@355: * 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@355: */ jjg@355: jjg@355: /* jjg@355: * @test jjg@355: * @bug 6868539 6868548 jjg@355: * @summary javap should use current names for constant pool entries, jjg@355: * remove spurious ';' from constant pool entries jjg@355: */ jjg@355: jjg@355: import java.io.*; jjg@355: import java.util.*; jjg@355: jjg@355: public class T6868539 jjg@355: jjg@355: { jjg@355: public static void main(String... args) { jjg@355: new T6868539().run(); jjg@355: } jjg@355: jjg@355: void run() { jjg@683: String output = javap("T6868539"); jjg@683: verify(output, "Utf8 +java/lang/String"); // 1: Utf8 jjg@355: // 2: currently unused jjg@683: verify(output, "Integer +123456"); // 3: Integer jjg@683: verify(output, "Float +123456.0f"); // 4: Float jjg@683: verify(output, "Long +123456l"); // 5: Long jjg@683: verify(output, "Double +123456.0d"); // 6: Double jjg@683: verify(output, "Class +#[0-9]+ +// + T6868539"); // 7: Class jjg@683: verify(output, "String +#[0-9]+ +// + not found"); // 8: String jjg@683: verify(output, "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I"); // 9: Fieldref jjg@683: verify(output, "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V"); // 10: Methodref jjg@683: verify(output, "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V"); jjg@355: // 11: InterfaceMethodref jjg@683: verify(output, "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V"); // 12: NameAndType jjg@355: if (errors > 0) jjg@355: throw new Error(errors + " found."); jjg@355: } jjg@355: jjg@683: void verify(String output, String... expects) { jjg@355: for (String expect: expects) { jjg@355: if (!output.matches("(?s).*" + expect + ".*")) jjg@355: error(expect + " not found"); jjg@355: } jjg@355: } jjg@355: jjg@355: void error(String msg) { jjg@355: System.err.println(msg); jjg@355: errors++; jjg@355: } jjg@355: jjg@355: int errors; jjg@355: jjg@355: String javap(String className) { jjg@355: String testClasses = System.getProperty("test.classes", "."); jjg@355: StringWriter sw = new StringWriter(); jjg@355: PrintWriter out = new PrintWriter(sw); jjg@355: String[] args = { "-v", "-classpath", testClasses, className }; jjg@355: int rc = com.sun.tools.javap.Main.run(args, out); jjg@355: if (rc != 0) jjg@355: throw new Error("javap failed. rc=" + rc); jjg@355: out.close(); jjg@355: String output = sw.toString(); jjg@355: System.out.println("class " + className); jjg@355: System.out.println(output); jjg@355: return output; jjg@355: } jjg@355: jjg@355: int i = 123456; jjg@355: float f = 123456.f; jjg@355: double d = 123456.; jjg@355: long l = 123456L; jjg@355: jjg@355: void m(Runnable r) { r.run(); } jjg@355: } jjg@355: