1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
23
23
24
24
/*
25
25
* @test
26
+ * @bug 8361615
26
27
* @summary Testing ClassFile builder parameters.
27
28
* @run junit BuilderParamTest
28
29
*/
@@ -46,19 +47,26 @@ void testDirectBuilder() {
46
47
cc .build (ClassDesc .of ("Foo" ), cb -> {
47
48
cb .withMethod ("foo" , MethodTypeDesc .ofDescriptor ("(IJI)V" ), 0 ,
48
49
mb -> mb .withCode (xb -> {
50
+ assertThrows (IndexOutOfBoundsException .class , () -> xb .parameterSlot (-1 ));
49
51
assertEquals (xb .receiverSlot (), 0 );
50
52
assertEquals (xb .parameterSlot (0 ), 1 );
51
53
assertEquals (xb .parameterSlot (1 ), 2 );
52
54
assertEquals (xb .parameterSlot (2 ), 4 );
55
+ assertThrows (IndexOutOfBoundsException .class , () -> xb .parameterSlot (3 ));
56
+ assertThrows (IndexOutOfBoundsException .class , () -> xb .parameterSlot (Integer .MAX_VALUE ));
53
57
xb .return_ ();
54
58
}));
55
59
});
56
60
cc .build (ClassDesc .of ("Foo" ), cb -> {
57
61
cb .withMethod ("foo" , MethodTypeDesc .ofDescriptor ("(IJI)V" ), ACC_STATIC ,
58
62
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 ());
59
66
assertEquals (xb .parameterSlot (0 ), 0 );
60
67
assertEquals (xb .parameterSlot (1 ), 1 );
61
68
assertEquals (xb .parameterSlot (2 ), 3 );
69
+ assertThrows (IndexOutOfBoundsException .class , () -> xb .parameterSlot (3 ));
62
70
xb .return_ ();
63
71
}));
64
72
});
0 commit comments