T6622216.java revision 2942:08092deced3f
1230557Sjimharris/*
2230557Sjimharris * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
3230557Sjimharris * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4230557Sjimharris *
5230557Sjimharris * This code is free software; you can redistribute it and/or modify it
6230557Sjimharris * under the terms of the GNU General Public License version 2 only, as
7230557Sjimharris * published by the Free Software Foundation.
8230557Sjimharris *
9230557Sjimharris * This code is distributed in the hope that it will be useful, but WITHOUT
10230557Sjimharris * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11230557Sjimharris * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12230557Sjimharris * version 2 for more details (a copy is included in the LICENSE file that
13230557Sjimharris * accompanied this code).
14230557Sjimharris *
15230557Sjimharris * You should have received a copy of the GNU General Public License version
16230557Sjimharris * 2 along with this work; if not, write to the Free Software Foundation,
17230557Sjimharris * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18230557Sjimharris *
19230557Sjimharris * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20230557Sjimharris * or visit www.oracle.com if you need additional information or have any
21230557Sjimharris * questions.
22230557Sjimharris */
23230557Sjimharris
24230557Sjimharris/*
25230557Sjimharris * @test
26230557Sjimharris * @bug 6622216
27230557Sjimharris * @summary javap names some attributes incorrectly
28230557Sjimharris * @modules jdk.jdeps
29230557Sjimharris */
30230557Sjimharris
31230557Sjimharrisimport java.io.*;
32230557Sjimharris
33230557Sjimharrispublic class T6622216 {
34230557Sjimharris    public static void main(String[] args) throws Exception {
35230557Sjimharris        new T6622216().run();
36230557Sjimharris    }
37230557Sjimharris
38230557Sjimharris    public void run() throws IOException {
39230557Sjimharris        File javaFile = writeTestFile();
40230557Sjimharris        File classFile = compileTestFile(javaFile);
41230557Sjimharris        String output = javap(classFile);
42230557Sjimharris        verify(output);
43230557Sjimharris    }
44230557Sjimharris
45230557Sjimharris    File writeTestFile() throws IOException {
46230557Sjimharris        File f = new File("Outer.java");
47230557Sjimharris        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
48230557Sjimharris        out.println("class Outer {");
49230557Sjimharris        out.println("    class Inner { }");
50230557Sjimharris        out.println("}");
51230557Sjimharris        out.close();
52230557Sjimharris        return f;
53230557Sjimharris    }
54230557Sjimharris
55230557Sjimharris    File compileTestFile(File f) {
56230557Sjimharris        int rc = com.sun.tools.javac.Main.compile(new String[] { f.getPath() });
57230557Sjimharris        if (rc != 0)
58230557Sjimharris            throw new Error("compilation failed. rc=" + rc);
59230557Sjimharris        String path = f.getPath();
60230557Sjimharris        return new File(path.substring(0, path.length() - 5) + ".class");
61230557Sjimharris    }
62230557Sjimharris
63230557Sjimharris    String javap(File f) {
64230557Sjimharris        StringWriter sw = new StringWriter();
65230557Sjimharris        PrintWriter out = new PrintWriter(sw);
66230557Sjimharris        int rc = com.sun.tools.javap.Main.run(new String[] { "-v", f.getPath() }, out);
67230557Sjimharris        if (rc != 0)
68230557Sjimharris            throw new Error("javap failed. rc=" + rc);
69230557Sjimharris        out.close();
70230557Sjimharris        return sw.toString();
71230557Sjimharris    }
72230557Sjimharris
73230557Sjimharris    void verify(String output) {
74230557Sjimharris        System.out.println(output);
75230557Sjimharris        if (output.indexOf("InnerClasses") == -1)
76230557Sjimharris            throw new Error("InnerClasses not found in output");
77230557Sjimharris    }
78230557Sjimharris}
79230557Sjimharris