< prev index next >

test/langtools/tools/javac/classfiles/InnerClasses/SyntheticClasses.java

Print this page

 27  *           inner_name_index zero (for synthetic classes)
 28  *  @modules jdk.jdeps/com.sun.tools.classfile
 29  *  @compile SyntheticClasses.java
 30  *  @run main SyntheticClasses
 31  */
 32 
 33 import java.io.*;
 34 import java.util.*;
 35 import com.sun.tools.classfile.*;
 36 
 37 public class SyntheticClasses {
 38 
 39     public static void main(String[] args) throws IOException, ConstantPoolException {
 40         new SyntheticClasses().run();
 41     }
 42 
 43     private void run() throws IOException, ConstantPoolException {
 44         File testClasses = new File(System.getProperty("test.classes"));
 45         for (File classFile : testClasses.listFiles(f -> f.getName().endsWith(".class"))) {
 46             ClassFile cf = ClassFile.read(classFile);





 47             if (cf.getName().matches(".*\\$[0-9]+")) {
 48                 EnclosingMethod_attribute encl =
 49                         (EnclosingMethod_attribute) cf.getAttribute(Attribute.EnclosingMethod);
 50                 if (encl != null) {
 51                     if (encl.method_index != 0)
 52                         throw new IllegalStateException("Invalid EnclosingMethod.method_index: " +
 53                                                         encl.method_index + ".");
 54                 }
 55             }
 56             InnerClasses_attribute attr =
 57                     (InnerClasses_attribute) cf.getAttribute(Attribute.InnerClasses);
 58             if (attr != null) {
 59                 for (InnerClasses_attribute.Info info : attr.classes) {
 60                     if (cf.major_version < 51)
 61                         throw new IllegalStateException();
 62                     if (info.inner_name_index == 0 && info.outer_class_info_index != 0)
 63                         throw new IllegalStateException("Invalid outer_class_info_index=" +
 64                                                         info.outer_class_info_index +
 65                                                         "; inner_name_index=" +
 66                                                         info.inner_name_index + ".");

 27  *           inner_name_index zero (for synthetic classes)
 28  *  @modules jdk.jdeps/com.sun.tools.classfile
 29  *  @compile SyntheticClasses.java
 30  *  @run main SyntheticClasses
 31  */
 32 
 33 import java.io.*;
 34 import java.util.*;
 35 import com.sun.tools.classfile.*;
 36 
 37 public class SyntheticClasses {
 38 
 39     public static void main(String[] args) throws IOException, ConstantPoolException {
 40         new SyntheticClasses().run();
 41     }
 42 
 43     private void run() throws IOException, ConstantPoolException {
 44         File testClasses = new File(System.getProperty("test.classes"));
 45         for (File classFile : testClasses.listFiles(f -> f.getName().endsWith(".class"))) {
 46             ClassFile cf = ClassFile.read(classFile);
 47             if ((cf.access_flags.flags & (AccessFlags.ACC_SYNTHETIC | AccessFlags.ACC_VALUE | AccessFlags.ACC_ABSTRACT)) == AccessFlags.ACC_SYNTHETIC) {
 48                 if ((cf.access_flags.flags & AccessFlags.ACC_IDENTITY) == 0) {
 49                     throw new IllegalStateException("Missing ACC_IDENTITY on synthetic concrete identity class: " + cf.getName());
 50                 }
 51             }
 52             if (cf.getName().matches(".*\\$[0-9]+")) {
 53                 EnclosingMethod_attribute encl =
 54                         (EnclosingMethod_attribute) cf.getAttribute(Attribute.EnclosingMethod);
 55                 if (encl != null) {
 56                     if (encl.method_index != 0)
 57                         throw new IllegalStateException("Invalid EnclosingMethod.method_index: " +
 58                                                         encl.method_index + ".");
 59                 }
 60             }
 61             InnerClasses_attribute attr =
 62                     (InnerClasses_attribute) cf.getAttribute(Attribute.InnerClasses);
 63             if (attr != null) {
 64                 for (InnerClasses_attribute.Info info : attr.classes) {
 65                     if (cf.major_version < 51)
 66                         throw new IllegalStateException();
 67                     if (info.inner_name_index == 0 && info.outer_class_info_index != 0)
 68                         throw new IllegalStateException("Invalid outer_class_info_index=" +
 69                                                         info.outer_class_info_index +
 70                                                         "; inner_name_index=" +
 71                                                         info.inner_name_index + ".");
< prev index next >