langtools/test/tools/javac/classfiles/InnerClasses/SyntheticClasses.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 24073 e6d5236551d2
child 30846 2b3f379840f0
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23392
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 24073
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
23392
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
     4
 *
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
     8
 *
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    14
 *
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    18
 *
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    21
 * questions.
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    22
 */
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    23
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    24
/** @test
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    25
 *  @bug 8034854
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    26
 *  @summary Verify that the InnerClasses attribute has outer_class_info_index zero if it has
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    27
 *           inner_name_index zero (for synthetic classes)
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 24073
diff changeset
    28
 *  @modules jdk.compiler/com.sun.tools.classfile
23392
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    29
 *  @compile SyntheticClasses.java
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    30
 *  @run main SyntheticClasses
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    31
 */
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    32
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    33
import java.io.*;
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    34
import java.util.*;
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    35
import com.sun.tools.classfile.*;
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    36
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    37
public class SyntheticClasses {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    38
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    39
    public static void main(String[] args) throws IOException, ConstantPoolException {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    40
        new SyntheticClasses().run();
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    41
    }
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    42
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    43
    private void run() throws IOException, ConstantPoolException {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    44
        File testClasses = new File(System.getProperty("test.classes"));
24073
e6d5236551d2 8039250: Test tools/javac/classfiles/InnerClasses/SyntheticClasses.java fails
jlahoda
parents: 23392
diff changeset
    45
        for (File classFile : testClasses.listFiles(f -> f.getName().endsWith(".class"))) {
23392
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    46
            ClassFile cf = ClassFile.read(classFile);
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    47
            if (cf.getName().matches(".*\\$[0-9]+")) {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    48
                EnclosingMethod_attribute encl =
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    49
                        (EnclosingMethod_attribute) cf.getAttribute(Attribute.EnclosingMethod);
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    50
                if (encl != null) {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    51
                    if (encl.method_index != 0)
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    52
                        throw new IllegalStateException("Invalid EnclosingMethod.method_index: " +
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    53
                                                        encl.method_index + ".");
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    54
                }
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    55
            }
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    56
            InnerClasses_attribute attr =
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    57
                    (InnerClasses_attribute) cf.getAttribute(Attribute.InnerClasses);
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    58
            if (attr != null) {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    59
                for (InnerClasses_attribute.Info info : attr.classes) {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    60
                    if (cf.major_version < 51)
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    61
                        throw new IllegalStateException();
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    62
                    if (info.inner_name_index == 0 && info.outer_class_info_index != 0)
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    63
                        throw new IllegalStateException("Invalid outer_class_info_index=" +
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    64
                                                        info.outer_class_info_index +
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    65
                                                        "; inner_name_index=" +
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    66
                                                        info.inner_name_index + ".");
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    67
                }
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    68
            }
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    69
        }
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    70
    }
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    71
}
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    72
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    73
class SyntheticConstructorAccessTag {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    74
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    75
    private static class A {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    76
        private A(){}
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    77
    }
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    78
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    79
    public void test() {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    80
        new A();
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    81
    }
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    82
}
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    83
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    84
class SyntheticEnumMapping {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    85
    private int convert(E e) {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    86
        switch (e) {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    87
            case A: return 0;
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    88
            default: return -1;
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    89
        }
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    90
    }
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    91
    enum E { A }
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    92
}
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    93
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    94
interface SyntheticAssertionsDisabled {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    95
    public default void test() {
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    96
        assert false;
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    97
    }
869ad7bdc595 8034854: outer_class_info_index of synthetic class is not zero
jlahoda
parents:
diff changeset
    98
}