StackMapTable format error: bad type array size in method
Rafael Winterhalter
rafael.wth at gmail.com
Mon Aug 19 20:22:46 UTC 2024
Hello,
when testing some of the corner cases within the unit tests of Byte Buddy,
I found some further errors when it comes to dead code and using
ClassWriter. All those cases work when using ASM. As a reproducer, consider
the following:
ClassFile classFile =
ClassFile.of(ClassFile.StackMapsOption.DROP_STACK_MAPS);
byte[] bytes = classFile.build(ClassDesc.of("foo.Bar"),
classBuilder -> classBuilder.withMethod(
"foo",
MethodTypeDesc.ofDescriptor("()J"),
0,
methodBuilder -> {
methodBuilder.withCode(codeBuilder -> {
codeBuilder.new_(ClassDesc.of(RuntimeException.class.getName()));
codeBuilder.dup();
codeBuilder.invokespecial(ClassDesc.of(RuntimeException.class.getName()),
"<init>",
MethodTypeDesc.ofDescriptor("()V"));
codeBuilder.athrow();
Label f2 = codeBuilder.newBoundLabel();
codeBuilder.lstore(1);
Label f3 = codeBuilder.newBoundLabel();
codeBuilder.lload(1);
codeBuilder.lreturn();
codeBuilder.with(StackMapTableAttribute.of(List.of(
StackMapFrameInfo.of(f2,
List.of(StackMapFrameInfo.ObjectVerificationTypeInfo.of(ClassDesc.of("foo.Bar"))),
List.of(StackMapFrameInfo.SimpleVerificationTypeInfo.ITEM_LONG)),
StackMapFrameInfo.of(f3,
List.of(StackMapFrameInfo.ObjectVerificationTypeInfo.of(ClassDesc.of("foo.Bar")),
StackMapFrameInfo.SimpleVerificationTypeInfo.ITEM_LONG),
List.of())
)));
});
}));
new ClassLoader() {
@Override
protected Class<?> findClass(String name) throws
ClassNotFoundException {
if (name.equals("foo.Bar")) {
return defineClass(name, bytes, 0, bytes.length);
} else {
return super.findClass(name);
}
}
}.findClass("foo.Bar").getMethods();
It gives a class format error. Java agents sometimes have to process all
kinds of strange byte code, so ideally these cases should be supported. Is
this a bug in the stack map frame attribute writer?
Thanks! Rafael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20240819/a8dcaa0f/attachment-0001.htm>
More information about the classfile-api-dev
mailing list