33 * java.base/jdk.internal.classfile.impl
34 * @compile SyntheticClasses.java
35 * @run main SyntheticClasses
36 */
37
38 import java.io.*;
39 import java.util.*;
40 import jdk.internal.classfile.*;
41 import jdk.internal.classfile.attribute.*;
42
43 public class SyntheticClasses {
44
45 public static void main(String[] args) throws IOException {
46 new SyntheticClasses().run();
47 }
48
49 private void run() throws IOException {
50 File testClasses = new File(System.getProperty("test.classes"));
51 for (File classFile : Objects.requireNonNull(testClasses.listFiles(f -> f.getName().endsWith(".class")))) {
52 ClassModel cf = Classfile.of().parse(classFile.toPath());
53 if (cf.thisClass().asInternalName().matches(".*\\$[0-9]+")) {
54 EnclosingMethodAttribute encl = cf.findAttribute(Attributes.ENCLOSING_METHOD).orElse(null);
55 if (encl != null) {
56 if (encl.enclosingMethodName().isPresent())
57 throw new IllegalStateException("Invalid EnclosingMethod.method: " +
58 encl.enclosingMethodName().get().stringValue() + ".");
59 }
60 }
61 InnerClassesAttribute attr = cf.findAttribute(Attributes.INNER_CLASSES).orElse(null);
62 if (attr != null) {
63 for (InnerClassInfo info : attr.classes()) {
64 if (cf.majorVersion() < 51)
65 throw new IllegalStateException();
66 if (info.innerName().isEmpty() && info.outerClass().isPresent() )
67 throw new IllegalStateException("Invalid outer_class_info: " +
68 info.outerClass().get().asInternalName() +
69 "; inner_name is empty");
70 }
71 }
72 }
|
33 * java.base/jdk.internal.classfile.impl
34 * @compile SyntheticClasses.java
35 * @run main SyntheticClasses
36 */
37
38 import java.io.*;
39 import java.util.*;
40 import jdk.internal.classfile.*;
41 import jdk.internal.classfile.attribute.*;
42
43 public class SyntheticClasses {
44
45 public static void main(String[] args) throws IOException {
46 new SyntheticClasses().run();
47 }
48
49 private void run() throws IOException {
50 File testClasses = new File(System.getProperty("test.classes"));
51 for (File classFile : Objects.requireNonNull(testClasses.listFiles(f -> f.getName().endsWith(".class")))) {
52 ClassModel cf = Classfile.of().parse(classFile.toPath());
53 if ((cf.flags().flagsMask() & (Classfile.ACC_SYNTHETIC | Classfile.ACC_VALUE | Classfile.ACC_ABSTRACT)) == Classfile.ACC_SYNTHETIC) {
54 if ((cf.flags().flagsMask() & Classfile.ACC_IDENTITY) == 0) {
55 throw new IllegalStateException("Missing ACC_IDENTITY on synthetic concrete identity class: " + cf.thisClass().asInternalName());
56 }
57 }
58 if (cf.thisClass().asInternalName().matches(".*\\$[0-9]+")) {
59 EnclosingMethodAttribute encl = cf.findAttribute(Attributes.ENCLOSING_METHOD).orElse(null);
60 if (encl != null) {
61 if (encl.enclosingMethodName().isPresent())
62 throw new IllegalStateException("Invalid EnclosingMethod.method: " +
63 encl.enclosingMethodName().get().stringValue() + ".");
64 }
65 }
66 InnerClassesAttribute attr = cf.findAttribute(Attributes.INNER_CLASSES).orElse(null);
67 if (attr != null) {
68 for (InnerClassInfo info : attr.classes()) {
69 if (cf.majorVersion() < 51)
70 throw new IllegalStateException();
71 if (info.innerName().isEmpty() && info.outerClass().isPresent() )
72 throw new IllegalStateException("Invalid outer_class_info: " +
73 info.outerClass().get().asInternalName() +
74 "; inner_name is empty");
75 }
76 }
77 }
|