T6868539.java revision 3231:50467a1cf5b1
11573Srgrimes/*
21573Srgrimes * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
31573Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41573Srgrimes *
51573Srgrimes * This code is free software; you can redistribute it and/or modify it
61573Srgrimes * under the terms of the GNU General Public License version 2 only, as
71573Srgrimes * published by the Free Software Foundation.
81573Srgrimes *
91573Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
101573Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
111573Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
121573Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
131573Srgrimes * accompanied this code).
141573Srgrimes *
151573Srgrimes * You should have received a copy of the GNU General Public License version
161573Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
171573Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
181573Srgrimes *
191573Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
201573Srgrimes * or visit www.oracle.com if you need additional information or have any
211573Srgrimes * questions.
221573Srgrimes */
231573Srgrimes
241573Srgrimes/*
251573Srgrimes * @test
261573Srgrimes * @bug 6868539 6868548 8035364
271573Srgrimes * @summary javap should use current names for constant pool entries,
281573Srgrimes *              remove spurious ';' from constant pool entries
291573Srgrimes * @modules jdk.jdeps
301573Srgrimes */
311573Srgrimes
321573Srgrimesimport java.io.*;
331573Srgrimesimport java.util.*;
341573Srgrimes
351573Srgrimespublic class T6868539
361573Srgrimes
371573Srgrimes{
381573Srgrimes    public static void main(String... args) {
391573Srgrimes        new T6868539().run();
401573Srgrimes    }
411573Srgrimes
421573Srgrimes    void run() {
431573Srgrimes        String output = javap("T6868539");
441573Srgrimes        verify(output, "Utf8 +java/lang/String");                                   // 1: Utf8
451573Srgrimes                                                                                    // 2: currently unused
461573Srgrimes        verify(output, "Integer +123456");                                          // 3: Integer
471573Srgrimes        verify(output, "Float +123456.0f");                                         // 4: Float
481573Srgrimes        verify(output, "Long +123456l");                                            // 5: Long
491573Srgrimes        verify(output, "Double +123456.0d");                                        // 6: Double
501573Srgrimes        verify(output, "Class +#[0-9]+ +// +T6868539");                             // 7: Class
511573Srgrimes        verify(output, "String +#[0-9]+ +// +not found");                           // 8: String
521573Srgrimes        verify(output, "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I");       // 9: Fieldref
531573Srgrimes        verify(output, "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V");   // 10: Methodref
541573Srgrimes        verify(output, "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V");
551573Srgrimes                                                                                    // 11: InterfaceMethodref
561573Srgrimes        verify(output, "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V");            // 12: NameAndType
571573Srgrimes        if (errors > 0)
581573Srgrimes            throw new Error(errors + " found.");
59    }
60
61    String notFound = " not found";
62
63    void verify(String output, String... expects) {
64        for (String expect: expects) {
65            if (!output.matches("(?s).*" + expect + ".*"))
66                error(expect + notFound);
67        }
68    }
69
70    void error(String msg) {
71        System.err.println(msg);
72        errors++;
73    }
74
75    int errors;
76
77    String javap(String className) {
78        String testClasses = System.getProperty("test.classes", ".");
79        StringWriter sw = new StringWriter();
80        PrintWriter out = new PrintWriter(sw);
81        String[] args = { "-v", "-classpath", testClasses, className };
82        int rc = com.sun.tools.javap.Main.run(args, out);
83        if (rc != 0)
84            throw new Error("javap failed. rc=" + rc);
85        out.close();
86        String output = sw.toString();
87        System.out.println("class " + className);
88        System.out.println(output);
89        return output;
90    }
91
92    int i = 123456;
93    float f = 123456.f;
94    double d = 123456.;
95    long l = 123456L;
96
97    void m(Runnable r) { r.run(); }
98}
99
100