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