Copilot commented on code in PR #517: URL: https://github.com/apache/commons-bcel/pull/517#discussion_r3529416585
########## src/test/java/org/apache/bcel/classfile/LocalVariableTableTest.java: ########## @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.bcel.classfile; + +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; + +import org.junit.jupiter.api.Test; + +/** + * Tests {@link LocalVariableTable#getLocalVariable(int, int)}. + */ +class LocalVariableTableTest { + + /** + * The live range of a local variable is the half-open interval {@code [start_pc, start_pc + length)} per JVMS 4.7.13, so a + * pc equal to {@code start_pc + length} is out of scope and must not match. + */ + @Test + void testGetLocalVariableLiveRangeEndIsExclusive() { + final ConstantPool constantPool = new ConstantPool(new Constant[1]); + // Variable in slot 1, live at pcs 2, 3, 4 (start 2, length 3). + final LocalVariable variable = new LocalVariable(2, 3, 0, 0, 1, constantPool); + final LocalVariableTable table = new LocalVariableTable(0, 0, new LocalVariable[] {variable}, constantPool); Review Comment: The test constructs a LocalVariable with nameIndex/signatureIndex = 0 and a ConstantPool of size 1. If this test fails (e.g., on the pre-fix behavior), JUnit will stringify the non-null LocalVariable and LocalVariable.toString() calls getName()/getSignature(), which will throw ClassFormatException due to the invalid constant-pool indices (index < 1). Use a minimal but valid constant pool (UTF8 entries at indices 1 and 2) and point the LocalVariable at those indices so failures remain assertion-based and debuggable. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
