Skip to content

Commit

Permalink
8313258: RuntimeInvisibleTypeAnnotationsAttribute.annotations() API I…
Browse files Browse the repository at this point in the history
…ndex out of Bound error

Reviewed-by: briangoetz
  • Loading branch information
asotona committed Sep 14, 2023
1 parent c7d306c commit 6d47fc6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public void setLabelTarget(Label label, int bci) {

@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];
Expand Down
10 changes: 10 additions & 0 deletions test/jdk/jdk/classfile/LimitsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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.*;

Expand Down Expand Up @@ -69,4 +70,13 @@ void testEmptyCode() {
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));
}
}

1 comment on commit 6d47fc6

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.