-
Bug
-
Resolution: Fixed
-
P4
-
None
-
b12
-
generic
-
generic
-
Verified
If a class contains dead code, and if the dead code contains stack map frames, the written attribute ends up invalid, causing a class format error.
A reproducer:
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();
A reproducer:
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();
- links to
-
Commit(master) openjdk/jdk/e88a3b05
-
Review(master) openjdk/jdk/20644