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