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