langtools/test/tools/javap/T4880672.java
author robm
Tue, 13 Sep 2016 14:47:29 +0100
changeset 40938 5b0977acc842
parent 36526 3b41f1c69604
permissions -rw-r--r--
6947916: JarURLConnection does not handle useCaches correctly Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3544
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     1
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
     2
 * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
3544
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     4
 *
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     8
 *
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    13
 * accompanied this code).
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    14
 *
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3544
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3544
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3544
diff changeset
    21
 * questions.
3544
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    22
 */
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    23
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    24
/*
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    25
 * @test
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 5520
diff changeset
    26
 * @bug 4880672 7031005
3544
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    27
 * @summary javap does not output inner interfaces of an interface
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    28
 * @modules jdk.jdeps/com.sun.tools.javap
3544
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    29
 */
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    30
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    31
import java.io.*;
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    32
import java.util.*;
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    33
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    34
public class T4880672
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    35
{
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    36
    public static void main(String... args) {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    37
        new T4880672().run();
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    38
    }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    39
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    40
    void run() {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    41
        verify("java.util.Map", "public interface java.util.Map$Entry");
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 5520
diff changeset
    42
        verify("T4880672", "class T4880672$A$B");
3544
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    43
        verify("C", ""); // must not give error if no InnerClasses attribute
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    44
        if (errors > 0)
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    45
            throw new Error(errors + " found.");
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    46
    }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    47
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    48
    void verify(String className, String... expects) {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    49
        String output = javap(className);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    50
        for (String expect: expects) {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    51
            if (output.indexOf(expect)< 0)
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    52
                error(expect + " not found");
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    53
        }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    54
    }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    55
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    56
    void error(String msg) {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    57
        System.err.println(msg);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    58
        errors++;
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    59
    }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    60
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    61
    int errors;
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    62
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    63
    String javap(String className) {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    64
        String testClasses = System.getProperty("test.classes", ".");
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    65
        StringWriter sw = new StringWriter();
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    66
        PrintWriter out = new PrintWriter(sw);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    67
        String[] args = { "-XDinner", "-classpath", testClasses, className };
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    68
        int rc = com.sun.tools.javap.Main.run(args, out);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    69
        out.close();
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    70
        String output = sw.toString();
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    71
        System.out.println("class " + className);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    72
        System.out.println(output);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    73
        if (rc != 0)
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    74
            throw new Error("javap failed. rc=" + rc);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    75
        if (output.indexOf("Error:") != -1)
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    76
            throw new Error("javap reported error.");
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    77
        return output;
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    78
    }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    79
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    80
    class A {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    81
        class B { }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    82
    }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    83
}
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    84
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    85
class C { }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    86