mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8332486: ClassFile API ArrayIndexOutOfBoundsException with label metadata
Reviewed-by: psandoz
This commit is contained in:
parent
5f2b8d0224
commit
451cc23905
2 changed files with 19 additions and 1 deletions
|
@ -221,6 +221,9 @@ public final class CodeImpl
|
|||
}
|
||||
|
||||
private void inflateLabel(int bci) {
|
||||
if (bci < 0 || bci > codeLength)
|
||||
throw new IllegalArgumentException(String.format("Bytecode offset out of range; bci=%d, codeLength=%d",
|
||||
bci, codeLength));
|
||||
if (labels[bci] == null)
|
||||
labels[bci] = new LabelImpl(this, bci);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8320360 8330684 8331320 8331655 8331940
|
||||
* @bug 8320360 8330684 8331320 8331655 8331940 8332486
|
||||
* @summary Testing ClassFile limits.
|
||||
* @run junit LimitsTest
|
||||
*/
|
||||
|
@ -37,8 +37,11 @@ import java.lang.classfile.Opcode;
|
|||
import java.lang.classfile.attribute.CodeAttribute;
|
||||
import java.lang.classfile.attribute.LineNumberInfo;
|
||||
import java.lang.classfile.attribute.LineNumberTableAttribute;
|
||||
import java.lang.classfile.attribute.LocalVariableInfo;
|
||||
import java.lang.classfile.attribute.LocalVariableTableAttribute;
|
||||
import java.lang.classfile.constantpool.ConstantPoolException;
|
||||
import java.lang.classfile.constantpool.IntegerEntry;
|
||||
import java.lang.classfile.instruction.LocalVariable;
|
||||
import java.util.List;
|
||||
import jdk.internal.classfile.impl.DirectCodeBuilder;
|
||||
import jdk.internal.classfile.impl.DirectMethodBuilder;
|
||||
|
@ -175,4 +178,16 @@ class LimitsTest {
|
|||
.writeAttribute(LineNumberTableAttribute.of(List.of(LineNumberInfo.of(500, 0))))
|
||||
))).methods().get(0).code().get().elementList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLocalVariableOutOfBounds() {
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
ClassFile.of().parse(ClassFile.of().build(ClassDesc.of("LocalVariableClass"), cb -> cb.withMethodBody(
|
||||
"localVariableMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, cob -> ((DirectCodeBuilder)cob
|
||||
.return_())
|
||||
.writeAttribute(LocalVariableTableAttribute.of(List.of(
|
||||
new UnboundAttribute.UnboundLocalVariableInfo(0, 200,
|
||||
cob.constantPool().utf8Entry("a"), cob.constantPool().utf8Entry("A"), 0))))
|
||||
))).methods().get(0).code().get().elementList());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue