Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwen5 committed Oct 9, 2023
1 parent d6a1f2e commit 1223557
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/test/javassist/JvstTest5.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package javassist;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.TypeVariable;

Expand All @@ -9,6 +12,8 @@
import javassist.bytecode.ClassFile;
import javassist.bytecode.ConstPool;
import javassist.bytecode.InnerClassesAttribute;
import javassist.bytecode.MethodInfo;
import javassist.bytecode.MethodParametersAttribute;
import javassist.bytecode.NestHostAttribute;
import javassist.bytecode.NestMembersAttribute;
import javassist.expr.ExprEditor;
Expand Down Expand Up @@ -593,4 +598,32 @@ public void testTooManyConstPoolItems() throws Exception {
}
catch (CannotCompileException e) {}
}

public void testGithubIssue462Java21WithoutParameters() throws IOException {

//This is a class file compiled by Java-21
//javac Java21InnerClassWithoutParameters.java
//public class Java21InnerClassWithoutParameters {
// class InnerClass implements Runnable {
// public void run() {
// }
// }
//}
String classFileName = "./Java21InnerClassWithoutParameters$InnerClass.class";
ClassLoader classLoader = getClass().getClassLoader();
File classFile = new File(classLoader.getResource(classFileName).getFile());

CtClass cc = sloader.makeClass(new FileInputStream(classFile));
cc.getClassFile().compact();

ClassFile cf = cc.getClassFile2();
ConstPool cp = cf.getConstPool();

MethodInfo minfo = cf.getMethod("<init>");
MethodParametersAttribute attr
= (MethodParametersAttribute)minfo.getAttribute(MethodParametersAttribute.tag);
assertEquals(1, attr.size());
assertNull(cp.getUtf8Info(attr.name(0)));
assertNull(attr.parameterName(0));
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 1223557

Please sign in to comment.