8313422: test/langtools/tools/javac 144 test classes uses com.sun.tools.classfile library

Reviewed-by: asotona
This commit is contained in:
Qing Xiao 2023-09-07 15:37:25 +00:00 committed by Adam Sotona
parent 8557205a82
commit 8f7e29b2cd
144 changed files with 2743 additions and 2762 deletions

View file

@ -25,45 +25,48 @@
* @bug 8034854
* @summary Verify that the InnerClasses attribute has outer_class_info_index zero if it has
* inner_name_index zero (for synthetic classes)
* @modules jdk.jdeps/com.sun.tools.classfile
* @modules java.base/jdk.internal.classfile
* java.base/jdk.internal.classfile.attribute
* java.base/jdk.internal.classfile.constantpool
* java.base/jdk.internal.classfile.instruction
* java.base/jdk.internal.classfile.components
* java.base/jdk.internal.classfile.impl
* @compile SyntheticClasses.java
* @run main SyntheticClasses
*/
import java.io.*;
import java.util.*;
import com.sun.tools.classfile.*;
import jdk.internal.classfile.*;
import jdk.internal.classfile.attribute.*;
public class SyntheticClasses {
public static void main(String[] args) throws IOException, ConstantPoolException {
public static void main(String[] args) throws IOException {
new SyntheticClasses().run();
}
private void run() throws IOException, ConstantPoolException {
private void run() throws IOException {
File testClasses = new File(System.getProperty("test.classes"));
for (File classFile : testClasses.listFiles(f -> f.getName().endsWith(".class"))) {
ClassFile cf = ClassFile.read(classFile);
if (cf.getName().matches(".*\\$[0-9]+")) {
EnclosingMethod_attribute encl =
(EnclosingMethod_attribute) cf.getAttribute(Attribute.EnclosingMethod);
for (File classFile : Objects.requireNonNull(testClasses.listFiles(f -> f.getName().endsWith(".class")))) {
ClassModel cf = Classfile.of().parse(classFile.toPath());
if (cf.thisClass().asInternalName().matches(".*\\$[0-9]+")) {
EnclosingMethodAttribute encl = cf.findAttribute(Attributes.ENCLOSING_METHOD).orElse(null);
if (encl != null) {
if (encl.method_index != 0)
throw new IllegalStateException("Invalid EnclosingMethod.method_index: " +
encl.method_index + ".");
if (encl.enclosingMethodName().isPresent())
throw new IllegalStateException("Invalid EnclosingMethod.method: " +
encl.enclosingMethodName().get().stringValue() + ".");
}
}
InnerClasses_attribute attr =
(InnerClasses_attribute) cf.getAttribute(Attribute.InnerClasses);
InnerClassesAttribute attr = cf.findAttribute(Attributes.INNER_CLASSES).orElse(null);
if (attr != null) {
for (InnerClasses_attribute.Info info : attr.classes) {
if (cf.major_version < 51)
for (InnerClassInfo info : attr.classes()) {
if (cf.majorVersion() < 51)
throw new IllegalStateException();
if (info.inner_name_index == 0 && info.outer_class_info_index != 0)
throw new IllegalStateException("Invalid outer_class_info_index=" +
info.outer_class_info_index +
"; inner_name_index=" +
info.inner_name_index + ".");
if (info.innerName().isEmpty() && info.outerClass().isPresent() )
throw new IllegalStateException("Invalid outer_class_info: " +
info.outerClass().get().asInternalName() +
"; inner_name is empty");
}
}
}