Skip to content

Commit c9bea77

Browse files
committed
8361615: CodeBuilder::parameterSlot throws undocumented IOOBE
Reviewed-by: asotona
1 parent 6681fc7 commit c9bea77

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/java.base/share/classes/java/lang/classfile/CodeBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public sealed interface CodeBuilder
132132
* values require two slots.
133133
*
134134
* @param paramNo the index of the parameter
135+
* @throws IndexOutOfBoundsException if the parameter index is out of bounds
135136
*/
136137
int parameterSlot(int paramNo);
137138

test/jdk/jdk/classfile/BuilderParamTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,6 +23,7 @@
2323

2424
/*
2525
* @test
26+
* @bug 8361615
2627
* @summary Testing ClassFile builder parameters.
2728
* @run junit BuilderParamTest
2829
*/
@@ -46,19 +47,26 @@ void testDirectBuilder() {
4647
cc.build(ClassDesc.of("Foo"), cb -> {
4748
cb.withMethod("foo", MethodTypeDesc.ofDescriptor("(IJI)V"), 0,
4849
mb -> mb.withCode(xb -> {
50+
assertThrows(IndexOutOfBoundsException.class, () -> xb.parameterSlot(-1));
4951
assertEquals(xb.receiverSlot(), 0);
5052
assertEquals(xb.parameterSlot(0), 1);
5153
assertEquals(xb.parameterSlot(1), 2);
5254
assertEquals(xb.parameterSlot(2), 4);
55+
assertThrows(IndexOutOfBoundsException.class, () -> xb.parameterSlot(3));
56+
assertThrows(IndexOutOfBoundsException.class, () -> xb.parameterSlot(Integer.MAX_VALUE));
5357
xb.return_();
5458
}));
5559
});
5660
cc.build(ClassDesc.of("Foo"), cb -> {
5761
cb.withMethod("foo", MethodTypeDesc.ofDescriptor("(IJI)V"), ACC_STATIC,
5862
mb -> mb.withCode(xb -> {
63+
assertThrows(IndexOutOfBoundsException.class, () -> xb.parameterSlot(Integer.MIN_VALUE));
64+
assertThrows(IndexOutOfBoundsException.class, () -> xb.parameterSlot(-1));
65+
assertThrows(IllegalStateException.class, () -> xb.receiverSlot());
5966
assertEquals(xb.parameterSlot(0), 0);
6067
assertEquals(xb.parameterSlot(1), 1);
6168
assertEquals(xb.parameterSlot(2), 3);
69+
assertThrows(IndexOutOfBoundsException.class, () -> xb.parameterSlot(3));
6270
xb.return_();
6371
}));
6472
});

0 commit comments

Comments
 (0)