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