8313258: RuntimeInvisibleTypeAnnotationsAttribute.annotations() API Index out of Bound error
Reviewed-by: briangoetz
This commit is contained in:
parent
c7d306c65c
commit
6d47fc6d5b
src/java.base/share/classes/jdk/internal/classfile/impl
test/jdk/jdk/classfile
@ -97,6 +97,9 @@ public final class CodeImpl
|
||||
|
||||
@Override
|
||||
public Label getLabel(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 == null)
|
||||
labels = new LabelImpl[codeLength + 1];
|
||||
LabelImpl l = labels[bci];
|
||||
|
@ -30,6 +30,7 @@ import java.lang.constant.ClassDesc;
|
||||
import java.lang.constant.ConstantDescs;
|
||||
import java.lang.constant.MethodTypeDesc;
|
||||
import jdk.internal.classfile.Classfile;
|
||||
import jdk.internal.classfile.impl.LabelContext;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@ -69,4 +70,13 @@ class LimitsTest {
|
||||
assertThrows(IllegalArgumentException.class, () -> Classfile.of().build(ClassDesc.of("EmptyClass"), cb -> cb.withMethodBody(
|
||||
"emptyMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, cob -> {})));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCodeRange() {
|
||||
var cf = Classfile.of();
|
||||
var lc = (LabelContext)cf.parse(cf.build(ClassDesc.of("EmptyClass"), cb -> cb.withMethodBody(
|
||||
"aMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, cob -> cob.return_()))).methods().get(0).code().get();
|
||||
assertThrows(IllegalArgumentException.class, () -> lc.getLabel(-1));
|
||||
assertThrows(IllegalArgumentException.class, () -> lc.getLabel(10));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user