This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git


The following commit(s) were added to refs/heads/master by this push:
     new 6ff4bad5 Make compiler-sensitive test fixtures reproducible
6ff4bad5 is described below

commit 6ff4bad50a0318ba1df131429da4c1437b66f2ab
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Nov 20 09:25:26 2026 -0500

    Make compiler-sensitive test fixtures reproducible
    
    Select PLSE methods and local variables by name. Generate and parse
    the enum array-clone fixture, and add explicit unsigned line-number
    boundary cases.
    
    Preserve the original deeply nested try/finally source and compiled
    class under test resources. Store the class in a reproducible archive
    and verify its large constructor, exception handlers, branches, and
    line-number metadata.
    
    Qualify the nested type annotation for ECJ compatibility. Add Javadocs
    explaining regression coverage and document fixture regeneration and
    coordination of IDE and Maven builds.
---
 src/test/README.md                                 | 114 ++++++++++
 src/test/java/org/apache/bcel/PLSETest.java        | 234 +++++++++++++++++----
 .../apache/bcel/classfile/TypeAnnotationsTest.java |  28 ++-
 .../java/org/apache/bcel/data/PLSETestEnum.java    |  24 ---
 src/test/resources/issue361/LargeMethod.jar        | Bin 0 -> 157133 bytes
 .../data => resources/issue361}/LargeMethod.java   |   0
 .../resources/typeannotations/TypeAnnotated.java   |   2 +-
 7 files changed, 334 insertions(+), 68 deletions(-)

diff --git a/src/test/README.md b/src/test/README.md
new file mode 100644
index 00000000..357e49c4
--- /dev/null
+++ b/src/test/README.md
@@ -0,0 +1,114 @@
+<!---
+ 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.
+-->
+# Test fixtures and local builds
+
+Run the default Maven verification from the project root:
+
+```sh
+mvn -B -ntp
+```
+
+Use a JDK, and set `JAVA_HOME` and `PATH` to the same JDK so subprocess tests 
use
+matching `java`, `javac`, and `javap` executables. The Maven build targets 
Java 8
+class files; its compiler configuration includes debug information needed by
+local-variable and line-number tests.
+
+## IDE and Maven output directories
+
+Eclipse and Maven can both write to `target/classes` and `target/test-classes`.
+Stop Eclipse auto-build and wait for an active build to finish before running
+Maven in the same checkout, or use a separate checkout or output directories.
+After switching compilers, use a clean Maven build rather than mixing classes
+from both builds.
+
+Keep `src/test/resources` out of Java source compilation. The checked-in 
Eclipse
+`.classpath` already excludes it with `excluding="**"`. Do not add the `.java`
+files in that directory to an IDE source folder: some are reference sources for
+compiled fixtures, not sources that should be rebuilt during ordinary tests.
+The Eclipse project also compiles `src/examples`; avoid concurrent writes from
+that source folder while Maven runs.
+
+## Source fixtures
+
+Prefer assertions about the behavior being tested over assumptions about a
+compiler's method order, bytecode offsets, or local-variable slots. Select
+methods and variables by name when their layout is incidental to the test.
+Compile source fixtures with debug information (`javac -g` or ECJ `-g`) when a
+test examines local-variable tables.
+
+`PLSETest` constructs and parses an enum class-file fixture containing the 
array
+`clone()` invocation for BCEL-262, so it does not depend on a compiler's
+implementation of enum `values()`. Its BCEL-361 cases serialize and read 
explicit
+line-number records around the signed-short boundary and parse the original
+12-level nested try/finally fixture from a checked-in javac-generated class.
+This preserves its large constructor, branches, exception handlers, and debug
+attributes regardless of the compiler used to build the test suite. The test
+Javadocs show the Java patterns represented by these fixtures. BCEL-295 finds
+the loop variable by name and compares its live range after a `MethodGen` round
+trip.
+
+## Checked-in class files
+
+Treat the `.class` files under `src/test/resources` as test inputs. Maven 
copies
+them as resources; some tests also read them directly from the source tree.
+Do not regenerate all of them with the current compiler. Compiler version,
+options, and bytecode layout can be part of the case a fixture is testing.
+A class file does not contain a standard compiler-identity field.
+
+When intentionally changing a compiled fixture, retain its reference source and
+record the JDK/compiler version and exact command. Compile into a separate
+scratch directory, inspect the result with `javap -v -p`, and copy back only 
the
+intended `.class` files. Run the affected tests and the full Maven 
verification.
+Review `git diff --stat` and `git diff --numstat` for unintended binary 
changes.
+
+For example, the existing `typeannotations/TypeAnnotated.class` fixture can be
+reproduced with OpenJDK `javac 21.0.13.1` using the following commands from 
the project
+root (create a fresh scratch directory first):
+
+```sh
+javac --release 8 -d /path/to/scratch 
src/test/resources/typeannotations/TypeAnnotated.java
+javap -v -p /path/to/scratch/typeannotations/TypeAnnotated.class
+```
+
+Only `TypeAnnotated.class` is consumed by these tests; the generated annotation
+classes do not need to be copied back. Other fixtures can require different
+compiler versions or options. `--release 8` sets the target platform, not a 
fixed
+javac implementation or an identical bytecode layout across compiler versions.
+
+### Deeply nested try/finally fixture
+
+`issue361/LargeMethod.java` retains the original twelve-level nested 
try/finally
+source unchanged. `issue361/LargeMethod.jar` contains its complete class file,
+compiled with OpenJDK `javac 21.0.13.1`. The constructor has 64,507 bytes of 
code,
+8,188 exception handlers, and line-number offsets beyond 32,767. The class also
+retains its local-variable and stack-map tables. Compression keeps this 6.6 MB
+class file in a roughly 157 KB fixture without removing bytecode or attributes.
+
+Reproduce it from the project root with that JDK's `javac` and `jar` (using a
+fresh scratch directory):
+
+```sh
+javac --release 8 -g -d /path/to/scratch 
src/test/resources/issue361/LargeMethod.java
+TZ=UTC jar --create --file /path/to/scratch/LargeMethod.jar --no-manifest 
--date=2000-01-01T00:00:00Z -C /path/to/scratch 
org/apache/bcel/data/LargeMethod.class
+javap -v -p /path/to/scratch/org/apache/bcel/data/LargeMethod.class
+```
+
+The fixed archive timestamp and omitted manifest make the archive reproducible.
+Only replace `src/test/resources/issue361/LargeMethod.jar` after reviewing the
+compiled structure and running `PLSETest`. Its size and handler-count 
assertions
+are intentional: a compiler that simplifies the nested finally blocks must not
+silently reduce this integration test's coverage.
diff --git a/src/test/java/org/apache/bcel/PLSETest.java 
b/src/test/java/org/apache/bcel/PLSETest.java
index afac2d94..94a400ba 100644
--- a/src/test/java/org/apache/bcel/PLSETest.java
+++ b/src/test/java/org/apache/bcel/PLSETest.java
@@ -20,11 +20,19 @@
 package org.apache.bcel;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
 import java.util.stream.Stream;
 
+import org.apache.bcel.classfile.Attribute;
+import org.apache.bcel.classfile.ClassParser;
 import org.apache.bcel.classfile.Code;
 import org.apache.bcel.classfile.JavaClass;
 import org.apache.bcel.classfile.LineNumber;
@@ -33,12 +41,18 @@ import org.apache.bcel.classfile.LocalVariable;
 import org.apache.bcel.classfile.LocalVariableTable;
 import org.apache.bcel.classfile.Method;
 import org.apache.bcel.classfile.Utility;
+import org.apache.bcel.generic.ArrayType;
+import org.apache.bcel.generic.BranchInstruction;
 import org.apache.bcel.generic.ClassGen;
 import org.apache.bcel.generic.ConstantPoolGen;
-import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.FieldGen;
+import org.apache.bcel.generic.INVOKEVIRTUAL;
+import org.apache.bcel.generic.InstructionConst;
+import org.apache.bcel.generic.InstructionFactory;
 import org.apache.bcel.generic.InstructionList;
 import org.apache.bcel.generic.InvokeInstruction;
 import org.apache.bcel.generic.MethodGen;
+import org.apache.bcel.generic.ObjectType;
 import org.apache.bcel.generic.Type;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
@@ -47,90 +61,228 @@ import org.junit.jupiter.params.provider.ValueSource;
 class PLSETest extends AbstractTest {
 
     /**
-     * BCEL-208: A couple of methods in MethodGen.java need to test for an 
empty instruction list.
+     * Checks BCEL-208 by requesting a local-variable table after removing a 
method's instruction list.
+     * <p>
+     * Selects {@code PLSETestClass.meth1(int)} by name, clears its 
instructions, and adds a local variable with null instruction handles.
+     * Building the local-variable table must still succeed. Selecting the 
method by name preserves this case when compilers order methods differently.
+     * </p>
+     *
+     * @throws ClassNotFoundException if the source fixture cannot be loaded.
      */
     @Test
     void testBCEL208() throws ClassNotFoundException {
         final JavaClass clazz = getTestJavaClass(PACKAGE_BASE_NAME + 
".data.PLSETestClass");
         final ClassGen gen = new ClassGen(clazz);
         final ConstantPoolGen pool = gen.getConstantPool();
-        final Method m = gen.getMethodAt(1);
+        final Method m = getMethod(clazz, "meth1");
         final MethodGen mg = new MethodGen(m, gen.getClassName(), pool);
         mg.setInstructionList(null);
         mg.addLocalVariable("local2", Type.INT, null, null);
-        // currently, this will cause null pointer exception
+        // Before BCEL-208, this threw a NullPointerException.
         mg.getLocalVariableTable(pool);
     }
 
     /**
-     * BCEL-262:
+     * Checks BCEL-262 by parsing the array-clone invocation in a generated 
enum {@code values()} method.
+     * <p>
+     * The removed {@code PLSETestEnum.java} fixture contained:
+     * </p>
+     * <pre>{@code
+     * enum PLSETestEnum {
+     *     TEST_VALUE
+     * }
+     * }</pre>
+     * <p>
+     * javac implements the implicit {@code values()} method by cloning a 
backing array, with code equivalent to:
+     * </p>
+     * <pre>{@code
+     * public static PLSETestEnum[] values() {
+     *     return $VALUES.clone();
+     * }
+     * }</pre>
+     * <p>
+     * This test constructs that backing field and method in an enum 
class-file fixture, serializes the class, reads it with {@link ClassParser}, and
+     * decodes the parsed method with {@link MethodGen}. It finds the 
invocation by instruction type and checks that its owner is the enum-array
+     * descriptor. This preserves the original fixture's constant-pool, 
instruction-decoding, and array-owner regression coverage without depending
+     * on a compiler's enum implementation, method order, or instruction 
offsets. Before BCEL-262, the array owner caused an IllegalArgumentException.
+     * </p>
+     *
+     * @throws IOException if the generated class cannot be parsed.
      */
     @Test
-    void testBCEL262() throws ClassNotFoundException {
-        final JavaClass clazz = getTestJavaClass(PACKAGE_BASE_NAME + 
".data.PLSETestEnum");
-        final ClassGen gen = new ClassGen(clazz);
+    void testBCEL262() throws IOException {
+        final String className = PACKAGE_BASE_NAME + ".data.PLSETestEnum";
+        final ClassGen gen = new ClassGen(className, "java.lang.Enum", 
"PLSETestEnum.java",
+            Const.ACC_PUBLIC | Const.ACC_FINAL | Const.ACC_SUPER | 
Const.ACC_ENUM, new String[0]);
+        gen.setMajor(Const.MAJOR_1_8);
+        gen.setMinor(Const.MINOR_1_8);
         final ConstantPoolGen pool = gen.getConstantPool();
-        // get the values() method
-        final Method m = gen.getMethodAt(0);
-        final MethodGen mg = new MethodGen(m, gen.getClassName(), pool);
-        final InstructionList il = mg.getInstructionList();
-        // get the invokevirtual instruction
-        final InstructionHandle ih = il.findHandle(3);
-        final InvokeInstruction ii = (InvokeInstruction) ih.getInstruction();
-        // without fix, the getClassName() will throw:
-        // java.lang.IllegalArgumentException: Cannot be used on an array type
-        final String cn = ii.getClassName(pool);
-        assertEquals("[Lorg.apache.bcel.data.PLSETestEnum;", cn);
+        final ArrayType arrayType = new ArrayType(new ObjectType(className), 
1);
+        gen.addField(new FieldGen(Const.ACC_PRIVATE | Const.ACC_STATIC | 
Const.ACC_FINAL | Const.ACC_SYNTHETIC, arrayType, "$VALUES", pool).getField());
+        final InstructionFactory factory = new InstructionFactory(gen);
+        final InstructionList instructions = new InstructionList();
+        instructions.append(factory.createGetStatic(className, "$VALUES", 
arrayType));
+        instructions.append(new 
INVOKEVIRTUAL(pool.addMethodref(arrayType.getSignature(), "clone", 
"()Ljava/lang/Object;")));
+        instructions.append(factory.createCheckCast(arrayType));
+        instructions.append(InstructionConst.ARETURN);
+        final MethodGen values = new MethodGen(Const.ACC_PUBLIC | 
Const.ACC_STATIC, arrayType, Type.NO_ARGS, new String[0], "values", className,
+            instructions, pool);
+        values.setMaxStack();
+        values.setMaxLocals();
+        gen.addMethod(values.getMethod());
+
+        final JavaClass parsed = new ClassParser(new 
ByteArrayInputStream(gen.getJavaClass().getBytes()), className).parse();
+        final ConstantPoolGen parsedPool = new 
ConstantPoolGen(parsed.getConstantPool());
+        final MethodGen parsedValues = new MethodGen(getMethod(parsed, 
"values"), parsed.getClassName(), parsedPool);
+        final InvokeInstruction invocation = 
Stream.of(parsedValues.getInstructionList().getInstructions()).filter(InvokeInstruction.class::isInstance)
+            
.map(InvokeInstruction.class::cast).findFirst().orElseThrow(AssertionError::new);
+        assertEquals(Const.INVOKEVIRTUAL, invocation.getOpcode());
+        assertEquals("clone", invocation.getMethodName(parsedPool));
+        assertEquals("()Ljava/lang/Object;", 
invocation.getSignature(parsedPool));
+        assertEquals("[Lorg.apache.bcel.data.PLSETestEnum;", 
invocation.getClassName(parsedPool));
     }
 
     /**
-     * BCEL-295:
+     * Checks BCEL-295 by preserving a loop variable's live range through a 
{@link MethodGen} round trip.
+     * <p>
+     * {@code PLSETestClass2.main(String[])} contains:
+     * </p>
+     * <pre>{@code
+     * int t = 0;
+     * for (int i = 0; i < 100; i++) {
+     *     t += i;
+     * }
+     * }</pre>
+     * <p>
+     * Finds {@code main} and {@code i} by name, then compares the original 
local-variable scope length with the reconstructed table. The compiler
+     * may omit {@code t} or assign a different slot or bytecode offset to 
{@code i}; the live range must still be preserved. Before BCEL-295, the
+     * reconstructed range could incorrectly include the instruction 
immediately after the variable's scope.
+     * </p>
+     *
+     * @throws Exception if the source fixture cannot be loaded or converted.
      */
     @Test
     void testBCEL295() throws Exception {
         final JavaClass clazz = getTestJavaClass(PACKAGE_BASE_NAME + 
".data.PLSETestClass2");
         final ClassGen cg = new ClassGen(clazz);
         final ConstantPoolGen pool = cg.getConstantPool();
-        final Method m = cg.getMethodAt(1); // 'main'
+        final Method m = getMethod(clazz, "main");
         final LocalVariableTable lvt = m.getLocalVariableTable();
-        final LocalVariable lv = lvt.getLocalVariable(2, 4); // 'i'
+        final LocalVariable lv = 
Stream.of(lvt.getLocalVariableTable()).filter(variable -> 
"i".equals(variable.getName())).findFirst()
+            .orElseThrow(AssertionError::new);
         // System.out.println(lv);
         final MethodGen mg = new MethodGen(m, cg.getClassName(), pool);
         final LocalVariableTable newLvt = 
mg.getLocalVariableTable(mg.getConstantPool());
-        final LocalVariable newLv = newLvt.getLocalVariable(2, 4); // 'i'
+        final LocalVariable newLv = newLvt.getLocalVariable(lv.getIndex(), 
lv.getStartPC());
+        assertNotNull(newLv, "The loop variable must survive the MethodGen 
round trip");
         // System.out.println(new_lv);
         assertEquals(lv.getLength(), newLv.getLength(), "live range length");
     }
 
     /**
-     * BCEL-361: LineNumber.toString() treats code offset as signed
+     * Checks BCEL-361 at the signed-short boundary and the maximum 
unsigned-short value.
+     * <p>
+     * Serializes and parses a {@link LineNumberTable} with explicitly chosen 
bytecode offsets and source line numbers, checks the unsigned getters,
+     * and verifies formatting after using the setters as well. Values 32767, 
32768, and 65535 exercise both sides of the sign boundary and the upper
+     * limit. The table is tested independently of a method, so the maximum 
unsigned-short value is included even though it cannot index valid code.
+     * </p>
+     * <p>
+     * The deeply nested try/finally fixture {@code LargeMethod.java} is 
preserved as a compiled resource and covered by
+     * {@link #testBCEL361LargeMethod()}.
+     * </p>
+     *
+     * @param value the bytecode offset and source line number to round-trip.
+     * @throws IOException if the line-number attribute cannot be serialized 
or parsed.
+     */
+    @ParameterizedTest
+    @ValueSource(ints = { 32767, 32768, 65535 })
+    void testBCEL361(final int value) throws IOException {
+        final ConstantPoolGen pool = new ConstantPoolGen();
+        final int nameIndex = pool.addUtf8("LineNumberTable");
+        // Explicit values exercise unsigned offsets even when a compiler 
optimizes away a large source fixture.
+        final LineNumberTable table = new LineNumberTable(nameIndex, 6, new 
LineNumber[] { new LineNumber(value, value) }, pool.getConstantPool());
+        final ByteArrayOutputStream output = new ByteArrayOutputStream();
+        try (DataOutputStream data = new DataOutputStream(output)) {
+            table.dump(data);
+        }
+        final LineNumberTable parsed;
+        try (DataInputStream input = new DataInputStream(new 
ByteArrayInputStream(output.toByteArray()))) {
+            parsed = (LineNumberTable) Attribute.readAttribute((DataInput) 
input, pool.getConstantPool());
+        }
+        final LineNumber line = parsed.getLineNumberTable()[0];
+        assertEquals(value, line.getStartPC());
+        assertEquals(value, line.getLineNumber());
+        line.setStartPC(value);
+        line.setLineNumber(value);
+        assertEquals("LineNumber(" + value + ", " + value + ")", 
line.toString());
+    }
+
+    /**
+     * Checks BCEL-361 using the original twelve-level nested try/finally 
fixture and its javac-generated bytecode.
+     * <p>
+     * The unchanged source is retained in {@code 
src/test/resources/issue361/LargeMethod.java}. It repeatedly nests this pattern 
in an instance
+     * initializer, to a depth of twelve try/finally blocks:
+     * </p>
+     * <pre>{@code
+     * int a;
+     * try {
+     *     a = 0;
+     * } finally {
+     *     try {
+     *         a = 0;
+     *     } finally {
+     *         a = 0;
+     *     }
+     * }
+     * }</pre>
+     * <p>
+     * javac expands the full source into a 64507-byte constructor with 8188 
exception handlers. The checked-in {@code LargeMethod.jar} contains
+     * that complete class, including its line-number, local-variable, and 
stack-map tables. Reading this fixed fixture retains the original nesting
+     * and compiler-generated control flow even when the test suite is 
compiled by ECJ. The compiler and reproduction commands are documented in
+     * {@code src/test/README.md}.
+     * </p>
+     * <p>
+     * The test parses the entire class and its Code attributes, asserts the 
constructor size and handler count, decodes its branch instructions,
+     * and checks line-number offsets and exception-handler positions beyond 
32767. It checks every line-number entry's unsigned getters and text.
+     * The fixture is parsed rather than executed, as in the original 
regression test. The independent boundary cases in {@link #testBCEL361(int)}
+     * additionally exercise setters and the maximum unsigned-short value.
+     * </p>
+     *
+     * @throws IOException if the compiled fixture cannot be parsed.
      */
     @Test
-    void testBCEL361() throws Exception {
-        final JavaClass clazz = getTestJavaClass(PACKAGE_BASE_NAME + 
".data.LargeMethod");
-        final Method[] methods = clazz.getMethods();
-        final Method m = methods[0];
-        // System.out.println(m.getName());
-        final Code code = m.getCode();
-        final LineNumberTable lnt = code.getLineNumberTable();
-        final LineNumber[] lineNumbers = lnt.getLineNumberTable();
-        final String data = lineNumbers[lineNumbers.length - 1].toString();
-        // System.out.println(data);
-        // System.out.println(data.contains("-"));
-        assertFalse(data.contains("-"), "code offsets must be positive");
-        Stream.of(lineNumbers).forEach(ln -> assertFalse(ln.getLineNumber() < 
0));
-        Stream.of(lineNumbers).forEach(ln -> assertFalse(ln.getStartPC() < 0));
+    void testBCEL361LargeMethod() throws IOException {
+        final JavaClass parsed = new 
ClassParser("src/test/resources/issue361/LargeMethod.jar", 
"org/apache/bcel/data/LargeMethod.class").parse();
+        final Code code = getMethod(parsed, Const.CONSTRUCTOR_NAME).getCode();
+        assertEquals(64507, code.getCode().length, "Preserve the original 
javac-generated constructor");
+        assertEquals(8188, code.getExceptionTable().length, "Preserve the 
deeply nested finally handlers");
+        assertTrue(Stream.of(code.getExceptionTable()).anyMatch(handler -> 
handler.getHandlerPC() > Short.MAX_VALUE));
+        final InstructionList instructions = new 
InstructionList(code.getCode());
+        
assertTrue(Stream.of(instructions.getInstructions()).anyMatch(BranchInstruction.class::isInstance));
+        final LineNumber[] lines = 
code.getLineNumberTable().getLineNumberTable();
+        assertTrue(Stream.of(lines).anyMatch(line -> line.getStartPC() > 
Short.MAX_VALUE));
+        for (final LineNumber line : lines) {
+            assertTrue(line.getStartPC() >= 0 && line.getStartPC() < 
code.getCode().length, "Line-number offsets must index the code");
+            assertTrue(line.getLineNumber() >= 0, "Source line numbers must be 
unsigned");
+            assertEquals("LineNumber(" + line.getStartPC() + ", " + 
line.getLineNumber() + ")", line.toString());
+        }
     }
 
     /**
-     * BCEL-79:
+     * Checks BCEL-79 by preserving local-variable table entries through a 
{@link MethodGen} round trip.
+     * <p>
+     * Selects {@code PLSETestClass.meth2(int, ArrayList, int)} by name and 
compares the number of local variables before and after reconstruction.
+     * The fixture retains its parameters and local variable; the lookup is 
independent of the compiler's method ordering.
+     * </p>
+     *
+     * @throws ClassNotFoundException if the source fixture cannot be loaded.
      */
     @Test
     void testBCEL79() throws ClassNotFoundException {
         final JavaClass clazz = getTestJavaClass(PACKAGE_BASE_NAME + 
".data.PLSETestClass");
         final ClassGen gen = new ClassGen(clazz);
         final ConstantPoolGen pool = gen.getConstantPool();
-        final Method m = gen.getMethodAt(2);
+        final Method m = getMethod(clazz, "meth2");
         final LocalVariableTable lvt = m.getLocalVariableTable();
         // System.out.println(lvt);
         // System.out.println(lvt.getTableLength());
diff --git a/src/test/java/org/apache/bcel/classfile/TypeAnnotationsTest.java 
b/src/test/java/org/apache/bcel/classfile/TypeAnnotationsTest.java
index c1c857ac..75df5385 100644
--- a/src/test/java/org/apache/bcel/classfile/TypeAnnotationsTest.java
+++ b/src/test/java/org/apache/bcel/classfile/TypeAnnotationsTest.java
@@ -51,12 +51,19 @@ import 
org.apache.bcel.verifier.statics.StringRepresentation;
 import org.junit.jupiter.api.Test;
 
 /**
- * Tests the type annotation attributes, read from {@code TypeAnnotated.class} 
(see {@code TypeAnnotated.java}).
+ * Tests type annotation attributes from the checked-in {@code 
TypeAnnotated.class} fixture and the source fixture {@link AnnotatedTypes}.
  */
 class TypeAnnotationsTest {
 
+    /**
+     * Supplies type-use annotations on enclosing, inner, and static nested 
types, wildcard bounds, array elements, casts, and local variables.
+     * <p>
+     * The explicit {@code TypeAnnotationsTest.} qualifier lets both javac and 
ECJ compile the annotation on {@code Outer}. It preserves the intended
+     * distinction between annotating the enclosing instance type and 
annotating {@code Inner} itself.
+     * </p>
+     */
     static class AnnotatedTypes {
-        @TypeUse Outer.Inner outer;
+        TypeAnnotationsTest.@TypeUse Outer.Inner outer;
         Outer.@TypeUse Inner inner;
         Outer.@TypeUse Nested nested;
         List<? extends @TypeUse Number[]> wildcard;
@@ -142,6 +149,23 @@ class TypeAnnotationsTest {
         assertEquals(original.toString(), copy.toString());
     }
 
+    /**
+     * Distinguishes annotations on an enclosing type, its inner class, and 
its static nested class.
+     * <p>
+     * Parses the compiler-generated class for these declarations:
+     * </p>
+     * <pre>{@code
+     * TypeAnnotationsTest.@TypeUse Outer.Inner outer;
+     * Outer.@TypeUse Inner inner;
+     * Outer.@TypeUse Nested nested;
+     * }</pre>
+     * <p>
+     * An annotation on {@code Outer} has an empty type path, an annotation on 
{@code Inner} has one INNER_TYPE step, and an annotation on the static
+     * {@code Nested} type has an empty path. The explicit qualifier changes 
neither those paths nor the assertions and works with javac and ECJ.
+     * </p>
+     *
+     * @throws IOException if the compiled fixture cannot be parsed.
+     */
     @Test
     void distinguishesInnerClassesFromStaticNestedClasses() throws IOException 
{
         final JavaClass clazz = annotatedTypes();
diff --git a/src/test/java/org/apache/bcel/data/PLSETestEnum.java 
b/src/test/java/org/apache/bcel/data/PLSETestEnum.java
deleted file mode 100644
index 6e7495f8..00000000
--- a/src/test/java/org/apache/bcel/data/PLSETestEnum.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.data;
-
-public enum PLSETestEnum {
-    TEST_VALUE
-}
diff --git a/src/test/resources/issue361/LargeMethod.jar 
b/src/test/resources/issue361/LargeMethod.jar
new file mode 100644
index 00000000..a168573a
Binary files /dev/null and b/src/test/resources/issue361/LargeMethod.jar differ
diff --git a/src/test/java/org/apache/bcel/data/LargeMethod.java 
b/src/test/resources/issue361/LargeMethod.java
similarity index 100%
rename from src/test/java/org/apache/bcel/data/LargeMethod.java
rename to src/test/resources/issue361/LargeMethod.java
diff --git a/src/test/resources/typeannotations/TypeAnnotated.java 
b/src/test/resources/typeannotations/TypeAnnotated.java
index 07c19507..64a5465d 100644
--- a/src/test/resources/typeannotations/TypeAnnotated.java
+++ b/src/test/resources/typeannotations/TypeAnnotated.java
@@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 import java.util.List;
 
-// Compiled with: javac --release 8 -d . TypeAnnotated.java (only 
TypeAnnotated.class is used by the tests)
+// See src/test/README.md for the compiler and command used to reproduce 
TypeAnnotated.class.
 @Target(ElementType.TYPE_USE)
 @Retention(RetentionPolicy.RUNTIME)
 @interface Visible {

Reply via email to