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
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