From 10e7235066a771d342e862ada1ef69c1a8e40776 Mon Sep 17 00:00:00 2001
From: Gary Gregory
From afa15ea4c3f4571204789415745a8db379d10b18 Mon Sep 17 00:00:00 2001
From: "Gary David Gregory (Code signing key)"
| bcel-6.8.1-bin.tar.gz | -sha512 | -pgp | +bcel-6.8.2-bin.tar.gz | +sha512 | +pgp |
| bcel-6.8.1-bin.zip | -sha512 | -pgp | +bcel-6.8.2-bin.zip | +sha512 | +pgp |
| bcel-6.8.1-src.tar.gz | -sha512 | -pgp | +bcel-6.8.2-src.tar.gz | +sha512 | +pgp |
| bcel-6.8.1-src.zip | -sha512 | -pgp | +bcel-6.8.2-src.zip | +sha512 | +pgp |
- The Byte Code Engineering Library (Apache Commons BCEL™) is intended to give users a - convenient way to analyze, create, and manipulate (binary) - Java class files (those ending with .class). Classes are - represented by objects which contain all the symbolic information - of the given class: methods, fields and byte code instructions, in - particular. -
-- Such objects can be read from an existing file, be transformed - by a program (e.g. a class loader at run-time) and written to a file again. - An even more interesting application is the creation of classes from scratch - at run-time. The Byte Code Engineering Library (BCEL) may be also useful - if you want to learn about the Java Virtual Machine (JVM) and the format of - Java .class files. -
-- BCEL contains a byte code verifier named JustIce, which usually - gives you much better information about what's wrong with your - code than the standard JVM message. -
-- BCEL is already being used successfully in several projects such - as compilers, optimizers, obsfuscators, code generators - and analysis tools. Unfortunately there hasn't been much development - going on over the past few years. Feel free to help out or you - might want to have a look into the ASM project at objectweb. -
-- The package descriptions in the Javadoc give an overview of the available features - and various project reports are provided. -
-- The source repository can be - browsed, or you can browse/contribute via GitHub. -
-The latest stable release of BCEL is here, you may:
-- Alternatively, you can pull it from the central Maven repositories through a dependency. -
- -- The commons developer mailing list is the main channel of communication for contributors. Please remember that the lists are shared between all commons components, so prefix your email by [bcel].
-You can also peruse JIRA.
-Alternatively you can go through the Needs Work tags in the TagList report.
-If you'd like to offer up pull requests via GitHub rather than applying patches to JIRA, we have a GitHub mirror.
-+ The Byte Code Engineering Library (Apache Commons BCEL™) is intended to give users a + convenient way to analyze, create, and manipulate (binary) + Java class files (those ending with .class). Classes are + represented by objects which contain all the symbolic information + of the given class: methods, fields and byte code instructions, in + particular. +
++ Such objects can be read from an existing file, be transformed + by a program (e.g. a class loader at run-time) and written to a file again. + An even more interesting application is the creation of classes from scratch + at run-time. The Byte Code Engineering Library (BCEL) may be also useful + if you want to learn about the Java Virtual Machine (JVM) and the format of + Java .class files. +
++ BCEL contains a byte code verifier named JustIce, which usually + gives you much better information about what's wrong with your + code than the standard JVM message. +
++ BCEL is already being used successfully in several projects such + as compilers, optimizers, obsfuscators, code generators + and analysis tools. Unfortunately there hasn't been much development + going on over the past few years. Feel free to help out or you + might want to have a look into the ASM project at objectweb. +
++ The package descriptions in the Javadoc give an overview of the available features + and various project reports are provided. +
++ The source repository can be + browsed, or you can browse/contribute via GitHub. +
+The latest stable release of BCEL is here, you may:
++ Alternatively, you can pull it from the central Maven repositories through a dependency. +
+ ++ The commons developer mailing list is the main channel of communication for contributors. Please remember that the lists are shared between all commons components, so prefix your email by [bcel].
+You can also peruse JIRA.
+Alternatively you can go through the Needs Work tags in the TagList report.
+If you'd like to offer up pull requests via GitHub rather than applying patches to JIRA, we have a GitHub mirror.
+{@code
- * org.apache.bcel.verifier.exc.AssertionViolatedException: INTERNAL ERROR: Some RuntimeException occurred while verify()ing class 'issue369.Test', method 'public void (int arg1)'. Original RuntimeException's stack trace:
+ * org.apache.bcel.verifier.exc.AssertionViolatedException:
+ * INTERNAL ERROR: Some RuntimeException occurred while verify()ing class 'issue369.Test', method 'public void (int arg1)'.
+ * Original RuntimeException's stack trace:
---
org.apache.bcel.verifier.exc.AssertionViolatedException: INTERNAL ERROR: outFrame not set! This:
24: return [InstructionContext]
diff --git a/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java b/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java
index 951c0c8a47..314fb6b6d6 100644
--- a/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java
@@ -133,7 +133,7 @@ public void testDefinitionImpl() throws ClassNotFoundException {
@Test
public void testJvmOpCodes() throws ClassNotFoundException {
- testDefaultMethodValidation("org.apache.bcel.verifier.tests.JvmOpCodes");
+ testDefaultMethodValidation("org.apache.bcel.verifier.tests.JvmOpCodes");
}
@Test
@@ -160,6 +160,6 @@ public void testPackagePrivateStaticField() throws ClassNotFoundException {
@Test
public void testWSDL() throws IOException, URISyntaxException, ClassNotFoundException {
- testJarFile(getJarFile(javax.wsdl.Port.class), "WSDLReaderImpl", "DefinitionImpl");
+ testJarFile(getJarFile(javax.wsdl.Port.class), "WSDLReaderImpl", "DefinitionImpl");
}
}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/JvmOpCodes.java b/src/test/java/org/apache/bcel/verifier/tests/JvmOpCodes.java
index 2d58c43e50..1a6b99fc7c 100644
--- a/src/test/java/org/apache/bcel/verifier/tests/JvmOpCodes.java
+++ b/src/test/java/org/apache/bcel/verifier/tests/JvmOpCodes.java
@@ -41,7 +41,8 @@
*/
public class JvmOpCodes {
- long l1, l2;
+ long l1;
+ long l2;
/**
* Tests {@link DNEG}.
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java
index 097f859eb5..878709d3b8 100644
--- a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java
@@ -39,7 +39,8 @@ public abstract class TestReturn03Creator extends TestCreator {
private final String genClassSuffix;
protected TestReturn03Creator(final Type returnType, final String genClassSuffix) {
- classGen = new ClassGen(TEST_PACKAGE + ".TestReturn03" + genClassSuffix, "java.lang.Object", "TestReturn03.java", Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {});
+ classGen = new ClassGen(TEST_PACKAGE + ".TestReturn03" + genClassSuffix, "java.lang.Object", "TestReturn03.java", Const.ACC_PUBLIC | Const.ACC_SUPER,
+ new String[] {});
constantPoolGen = classGen.getConstantPool();
instructionFactory = new InstructionFactory(classGen, constantPoolGen);
@@ -56,7 +57,8 @@ public void create(final OutputStream out) throws IOException {
private void createMethod_0() {
final InstructionList il = new InstructionList();
- final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] {}, "", TEST_PACKAGE + ".TestReturn03", il, constantPoolGen);
+ final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] {}, "", TEST_PACKAGE + ".TestReturn03", il,
+ constantPoolGen);
final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
assertNotNull(ih_0); // TODO why is this not used
@@ -72,7 +74,7 @@ private void createMethod_0() {
private void createMethod_1() {
final InstructionList il = new InstructionList();
final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.INT, Type.NO_ARGS, new String[] {}, "test3",
- TEST_PACKAGE + ".TestReturn03" + genClassSuffix, il, constantPoolGen);
+ TEST_PACKAGE + ".TestReturn03" + genClassSuffix, il, constantPoolGen);
final InstructionHandle ih_0 = il.append(InstructionConst.ACONST_NULL);
assertNotNull(ih_0); // TODO why is this not used
From 13e7e0fba64de26875df00081cb12cd10c5f96e4 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Thu, 28 Mar 2024 18:51:53 -0400
Subject: [PATCH 061/147] Bump commons-io:commons-io from 2.15.1 to 2.16.0
(#295)
Bumps commons-io:commons-io from 2.15.1 to 2.16.0.
---
updated-dependencies:
- dependency-name: commons-io:commons-io
dependency-type: direct:development
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 48ea3ce461..c7f06ea184 100644
--- a/pom.xml
+++ b/pom.xml
@@ -371,7 +371,7 @@
commons-io
commons-io
- 2.15.1
+ 2.16.0
test
@@ -463,7 +463,7 @@
commons-io
commons-io
- 2.15.1
+ 2.16.0
test
From 35c80a0c254c9de6955d01d1098ec30350467d5b Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Thu, 28 Mar 2024 18:52:44 -0400
Subject: [PATCH 062/147] Bump commons-io:commons-io from 2.15.1 to 2.16.0 #295
---
src/changes/changes.xml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f4f75e9bd2..1895041d09 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -60,8 +60,10 @@ The type attribute can be add,update,fix,remove.
-->
+
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
+ Bump commons-io:commons-io from 2.15.1 to 2.16.0 #295.
From f75f5f980f1dc93cd060ce0d07f9f7ad9e9861fa Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 29 Mar 2024 17:17:30 -0400
Subject: [PATCH 063/147] Bump codecov/codecov-action from 4.1.0 to 4.1.1
(#296)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4.1.0 to 4.1.1.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/54bcd8715eee62d40e33596ef5e8f0f48dbbccab...c16abc29c95fcf9174b58eb7e1abf4c866893bc8)
---
updated-dependencies:
- dependency-name: codecov/codecov-action
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
.github/workflows/coverage.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
index fccacf39ff..763dfa3047 100644
--- a/.github/workflows/coverage.yml
+++ b/.github/workflows/coverage.yml
@@ -47,6 +47,6 @@ jobs:
run: mvn --show-version --batch-mode --no-transfer-progress install jacoco:report -DdataFile=jacoco_jdk${{ matrix.java }}.exec
- name: Upload coverage to Codecov
- uses: codecov/codecov-action@54bcd8715eee62d40e33596ef5e8f0f48dbbccab # v4.1.0
+ uses: codecov/codecov-action@c16abc29c95fcf9174b58eb7e1abf4c866893bc8 # v4.1.1
with:
files: ./target/site/jacoco/jacoco.xml
From 8925b2e323e19f18ee1936c1eefa1a6bb13c5812 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 31 Mar 2024 09:04:43 -0400
Subject: [PATCH 064/147] Don't disable doclint
---
.github/workflows/maven.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 883c21ccee..eb78adb016 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -60,4 +60,4 @@ jobs:
distribution: 'temurin'
java-version: ${{ matrix.java }}
- name: Build with Maven
- run: mvn --show-version --batch-mode --no-transfer-progress -DtrimStackTrace=false -Ddoclint=none
+ run: mvn --show-version --batch-mode --no-transfer-progress -DtrimStackTrace=false
From 1cf711d897d0d7117b4ad4fa2254cfc2fc20aab0 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 31 Mar 2024 14:57:25 -0400
Subject: [PATCH 065/147] Format tweaks
---
src/examples/ListClass.java | 5 -----
1 file changed, 5 deletions(-)
diff --git a/src/examples/ListClass.java b/src/examples/ListClass.java
index 3a7c91d65b..b973fbd7f9 100644
--- a/src/examples/ListClass.java
+++ b/src/examples/ListClass.java
@@ -195,7 +195,6 @@ public static void printClassDependencies(final ConstantPool pool) {
public static void printCode(final Method[] methods, final boolean verbose) {
for (final Method method : methods) {
System.out.println(method);
-
final Code code = method.getCode();
if (code != null) {
System.out.println(code.toString(verbose));
@@ -207,13 +206,9 @@ public static void printCode(final Method[] methods, final boolean verbose) {
boolean constants;
boolean verbose;
boolean classDep;
-
boolean noContents;
-
boolean recurse;
-
Map listedClasses;
-
List excludeName;
public ListClass(final boolean code, final boolean constants, final boolean verbose, final boolean classDep, final boolean noContents,
From 67ba0d82c39ffe19fe88b59155c7f637ca34300f Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 31 Mar 2024 15:01:35 -0400
Subject: [PATCH 066/147] Better parameter name
---
.../java/org/apache/bcel/classfile/ArrayElementValue.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/ArrayElementValue.java b/src/main/java/org/apache/bcel/classfile/ArrayElementValue.java
index 13d4626414..00fdc7af3e 100644
--- a/src/main/java/org/apache/bcel/classfile/ArrayElementValue.java
+++ b/src/main/java/org/apache/bcel/classfile/ArrayElementValue.java
@@ -26,12 +26,12 @@ public class ArrayElementValue extends ElementValue {
// For array types, this is the array
private final ElementValue[] elementValues;
- public ArrayElementValue(final int type, final ElementValue[] datums, final ConstantPool cpool) {
+ public ArrayElementValue(final int type, final ElementValue[] elementValues, final ConstantPool cpool) {
super(type, cpool);
if (type != ARRAY) {
throw new ClassFormatException("Only element values of type array can be built with this ctor - type specified: " + type);
}
- this.elementValues = datums;
+ this.elementValues = elementValues;
}
@Override
From 4cd1637972d15084122abd134a70dbc728a3ec9d Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 31 Mar 2024 15:41:53 -0400
Subject: [PATCH 067/147] Reuse ArrayUtils.nullToEmpty()
---
src/examples/ListClass.java | 5 +++--
.../java/org/apache/bcel/classfile/AnnotationEntry.java | 4 +++-
src/main/java/org/apache/bcel/classfile/Code.java | 6 +++---
src/main/java/org/apache/bcel/classfile/ExceptionTable.java | 4 ++--
src/main/java/org/apache/bcel/classfile/JavaClass.java | 4 +---
src/main/java/org/apache/bcel/classfile/ModulePackages.java | 4 ++--
src/main/java/org/apache/bcel/classfile/NestMembers.java | 4 ++--
7 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/src/examples/ListClass.java b/src/examples/ListClass.java
index b973fbd7f9..442f7ce85f 100644
--- a/src/examples/ListClass.java
+++ b/src/examples/ListClass.java
@@ -31,6 +31,7 @@
import org.apache.bcel.classfile.ConstantUtf8;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
+import org.apache.commons.lang3.stream.Streams;
/**
* Read class file(s) and display its contents. The command line usage is:
@@ -193,13 +194,13 @@ public static void printClassDependencies(final ConstantPool pool) {
* Dump the disassembled code of all methods in the class.
*/
public static void printCode(final Method[] methods, final boolean verbose) {
- for (final Method method : methods) {
+ Streams.of(methods).forEach(method -> {
System.out.println(method);
final Code code = method.getCode();
if (code != null) {
System.out.println(code.toString(verbose));
}
- }
+ });
}
boolean code;
diff --git a/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java b/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java
index b3c2bb22b7..d0b4b045b2 100644
--- a/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java
+++ b/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java
@@ -23,6 +23,8 @@
import java.util.List;
import java.util.stream.Stream;
+import org.apache.commons.lang3.stream.Streams;
+
/**
* Represents one annotation in the annotation table
*
@@ -34,7 +36,7 @@ public class AnnotationEntry implements Node {
public static AnnotationEntry[] createAnnotationEntries(final Attribute[] attrs) {
// Find attributes that contain annotation data
- return Stream.of(attrs).filter(Annotations.class::isInstance).flatMap(e -> Stream.of(((Annotations) e).getAnnotationEntries()))
+ return Streams.of(attrs).filter(Annotations.class::isInstance).flatMap(e -> Stream.of(((Annotations) e).getAnnotationEntries()))
.toArray(AnnotationEntry[]::new);
}
diff --git a/src/main/java/org/apache/bcel/classfile/Code.java b/src/main/java/org/apache/bcel/classfile/Code.java
index 72964af160..13f9dfc417 100644
--- a/src/main/java/org/apache/bcel/classfile/Code.java
+++ b/src/main/java/org/apache/bcel/classfile/Code.java
@@ -127,8 +127,8 @@ public Code(final int nameIndex, final int length, final int maxStack, final int
super(Const.ATTR_CODE, nameIndex, length, constantPool);
this.maxStack = Args.requireU2(maxStack, "maxStack");
this.maxLocals = Args.requireU2(maxLocals, "maxLocals");
- this.code = code != null ? code : ArrayUtils.EMPTY_BYTE_ARRAY;
- this.exceptionTable = exceptionTable != null ? exceptionTable : CodeException.EMPTY_CODE_EXCEPTION_ARRAY;
+ this.code = ArrayUtils.nullToEmpty(code);
+ this.exceptionTable = ArrayUtils.nullToEmpty(exceptionTable, CodeException[].class);
Args.requireU2(this.exceptionTable.length, "exceptionTable.length");
this.attributes = attributes != null ? attributes : EMPTY_ARRAY;
super.setLength(calculateLength()); // Adjust length
@@ -299,7 +299,7 @@ public void setAttributes(final Attribute[] attributes) {
* @param code byte code
*/
public void setCode(final byte[] code) {
- this.code = code != null ? code : ArrayUtils.EMPTY_BYTE_ARRAY;
+ this.code = ArrayUtils.nullToEmpty(code);
super.setLength(calculateLength()); // Adjust length
}
diff --git a/src/main/java/org/apache/bcel/classfile/ExceptionTable.java b/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
index 6e1aaa23ec..3877b2f8e5 100644
--- a/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
+++ b/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
@@ -82,7 +82,7 @@ public ExceptionTable(final ExceptionTable c) {
*/
public ExceptionTable(final int nameIndex, final int length, final int[] exceptionIndexTable, final ConstantPool constantPool) {
super(Const.ATTR_EXCEPTIONS, nameIndex, length, constantPool);
- this.exceptionIndexTable = exceptionIndexTable != null ? exceptionIndexTable : ArrayUtils.EMPTY_INT_ARRAY;
+ this.exceptionIndexTable = ArrayUtils.nullToEmpty(exceptionIndexTable);
Args.requireU2(this.exceptionIndexTable.length, "exceptionIndexTable.length");
}
@@ -153,7 +153,7 @@ public int getNumberOfExceptions() {
* length.
*/
public void setExceptionIndexTable(final int[] exceptionIndexTable) {
- this.exceptionIndexTable = exceptionIndexTable != null ? exceptionIndexTable : ArrayUtils.EMPTY_INT_ARRAY;
+ this.exceptionIndexTable = ArrayUtils.nullToEmpty(exceptionIndexTable);
}
/**
diff --git a/src/main/java/org/apache/bcel/classfile/JavaClass.java b/src/main/java/org/apache/bcel/classfile/JavaClass.java
index 5bcd5c7e2c..b90cfad0e4 100644
--- a/src/main/java/org/apache/bcel/classfile/JavaClass.java
+++ b/src/main/java/org/apache/bcel/classfile/JavaClass.java
@@ -182,9 +182,7 @@ public JavaClass(final int classNameIndex, final int superclassNameIndex, final
public JavaClass(final int classNameIndex, final int superclassNameIndex, final String fileName, final int major, final int minor, final int accessFlags,
final ConstantPool constantPool, int[] interfaces, Field[] fields, Method[] methods, Attribute[] attributes, final byte source) {
super(accessFlags);
- if (interfaces == null) {
- interfaces = ArrayUtils.EMPTY_INT_ARRAY;
- }
+ interfaces = ArrayUtils.nullToEmpty(interfaces);
if (attributes == null) {
attributes = Attribute.EMPTY_ARRAY;
}
diff --git a/src/main/java/org/apache/bcel/classfile/ModulePackages.java b/src/main/java/org/apache/bcel/classfile/ModulePackages.java
index fef3a632ba..ade6cb329f 100644
--- a/src/main/java/org/apache/bcel/classfile/ModulePackages.java
+++ b/src/main/java/org/apache/bcel/classfile/ModulePackages.java
@@ -62,7 +62,7 @@ public final class ModulePackages extends Attribute {
*/
public ModulePackages(final int nameIndex, final int length, final int[] packageIndexTable, final ConstantPool constantPool) {
super(Const.ATTR_MODULE_PACKAGES, nameIndex, length, constantPool);
- this.packageIndexTable = packageIndexTable != null ? packageIndexTable : ArrayUtils.EMPTY_INT_ARRAY;
+ this.packageIndexTable = ArrayUtils.nullToEmpty(packageIndexTable);
Args.requireU2(this.packageIndexTable.length, "packageIndexTable.length");
}
@@ -142,7 +142,7 @@ public String[] getPackageNames() {
* @param packageIndexTable the list of package indexes Also redefines number_of_packages according to table length.
*/
public void setPackageIndexTable(final int[] packageIndexTable) {
- this.packageIndexTable = packageIndexTable != null ? packageIndexTable : ArrayUtils.EMPTY_INT_ARRAY;
+ this.packageIndexTable = ArrayUtils.nullToEmpty(packageIndexTable);
}
/**
diff --git a/src/main/java/org/apache/bcel/classfile/NestMembers.java b/src/main/java/org/apache/bcel/classfile/NestMembers.java
index e9b15593c1..3449148cd0 100644
--- a/src/main/java/org/apache/bcel/classfile/NestMembers.java
+++ b/src/main/java/org/apache/bcel/classfile/NestMembers.java
@@ -63,7 +63,7 @@ public final class NestMembers extends Attribute {
*/
public NestMembers(final int nameIndex, final int length, final int[] classes, final ConstantPool constantPool) {
super(Const.ATTR_NEST_MEMBERS, nameIndex, length, constantPool);
- this.classes = classes != null ? classes : ArrayUtils.EMPTY_INT_ARRAY;
+ this.classes = ArrayUtils.nullToEmpty(classes);
Args.requireU2(this.classes.length, "classes.length");
}
@@ -143,7 +143,7 @@ public int getNumberClasses() {
* @param classes the list of class indexes Also redefines number_of_classes according to table length.
*/
public void setClasses(final int[] classes) {
- this.classes = classes != null ? classes : ArrayUtils.EMPTY_INT_ARRAY;
+ this.classes = ArrayUtils.nullToEmpty(classes);
}
/**
From 34d0a3dd2317bb970cce95c5428c744e99cd6e8b Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 31 Mar 2024 15:50:46 -0400
Subject: [PATCH 068/147] Normalize package private name
---
src/main/java/org/apache/bcel/classfile/Code.java | 2 +-
src/main/java/org/apache/bcel/classfile/CodeException.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/Code.java b/src/main/java/org/apache/bcel/classfile/Code.java
index 13f9dfc417..8ec211fba4 100644
--- a/src/main/java/org/apache/bcel/classfile/Code.java
+++ b/src/main/java/org/apache/bcel/classfile/Code.java
@@ -307,7 +307,7 @@ public void setCode(final byte[] code) {
* @param exceptionTable exception table
*/
public void setExceptionTable(final CodeException[] exceptionTable) {
- this.exceptionTable = exceptionTable != null ? exceptionTable : CodeException.EMPTY_CODE_EXCEPTION_ARRAY;
+ this.exceptionTable = exceptionTable != null ? exceptionTable : CodeException.EMPTY_ARRAY;
super.setLength(calculateLength()); // Adjust length
}
diff --git a/src/main/java/org/apache/bcel/classfile/CodeException.java b/src/main/java/org/apache/bcel/classfile/CodeException.java
index 5171bcacf5..b8d4f0a9a9 100644
--- a/src/main/java/org/apache/bcel/classfile/CodeException.java
+++ b/src/main/java/org/apache/bcel/classfile/CodeException.java
@@ -55,7 +55,7 @@ public final class CodeException implements Cloneable, Node, Constants {
/**
* Empty array.
*/
- static final CodeException[] EMPTY_CODE_EXCEPTION_ARRAY = {};
+ static final CodeException[] EMPTY_ARRAY = {};
/** Range in the code the exception handler. */
private int startPc;
From bf5e78d765009e1ebd3ca1a7a845ea98c557b17d Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 31 Mar 2024 15:52:06 -0400
Subject: [PATCH 069/147] Reuse public constant
---
src/main/java/org/apache/bcel/classfile/Field.java | 5 -----
src/main/java/org/apache/bcel/classfile/JavaClass.java | 2 +-
2 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/Field.java b/src/main/java/org/apache/bcel/classfile/Field.java
index a7f002e0fa..0fd1582cff 100644
--- a/src/main/java/org/apache/bcel/classfile/Field.java
+++ b/src/main/java/org/apache/bcel/classfile/Field.java
@@ -50,11 +50,6 @@ public int hashCode(final Field o) {
}
};
- /**
- * Empty array.
- */
- static final Field[] EMPTY_FIELD_ARRAY = {};
-
/**
* @return Comparison strategy object.
*/
diff --git a/src/main/java/org/apache/bcel/classfile/JavaClass.java b/src/main/java/org/apache/bcel/classfile/JavaClass.java
index b90cfad0e4..1f4a8f051e 100644
--- a/src/main/java/org/apache/bcel/classfile/JavaClass.java
+++ b/src/main/java/org/apache/bcel/classfile/JavaClass.java
@@ -187,7 +187,7 @@ public JavaClass(final int classNameIndex, final int superclassNameIndex, final
attributes = Attribute.EMPTY_ARRAY;
}
if (fields == null) {
- fields = Field.EMPTY_FIELD_ARRAY;
+ fields = Field.EMPTY_ARRAY;
}
if (methods == null) {
methods = Method.EMPTY_METHOD_ARRAY;
From 8ada59f101ff8d6e64a939746fa026f4e5737cc2 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 31 Mar 2024 15:53:05 -0400
Subject: [PATCH 070/147] Normalize package private name
Fix spelling in private name
---
src/main/java/org/apache/bcel/classfile/InnerClasses.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/InnerClasses.java b/src/main/java/org/apache/bcel/classfile/InnerClasses.java
index 30788c404f..53b85b79ed 100644
--- a/src/main/java/org/apache/bcel/classfile/InnerClasses.java
+++ b/src/main/java/org/apache/bcel/classfile/InnerClasses.java
@@ -37,7 +37,7 @@ public final class InnerClasses extends Attribute implements Iterable iterator() {
* @param innerClasses the array of inner classes
*/
public void setInnerClasses(final InnerClass[] innerClasses) {
- this.innerClasses = innerClasses != null ? innerClasses : EMPTY_INNER_CLASSE_ARRAY;
+ this.innerClasses = innerClasses != null ? innerClasses : EMPTY_ARRAY;
}
/**
From 80cc367592a6142981688445a61c63d90191de76 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 31 Mar 2024 15:53:48 -0400
Subject: [PATCH 071/147] Reuse public constant
---
src/main/java/org/apache/bcel/classfile/JavaClass.java | 2 +-
src/main/java/org/apache/bcel/classfile/Method.java | 5 -----
2 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/JavaClass.java b/src/main/java/org/apache/bcel/classfile/JavaClass.java
index 1f4a8f051e..44cd75b1ed 100644
--- a/src/main/java/org/apache/bcel/classfile/JavaClass.java
+++ b/src/main/java/org/apache/bcel/classfile/JavaClass.java
@@ -190,7 +190,7 @@ public JavaClass(final int classNameIndex, final int superclassNameIndex, final
fields = Field.EMPTY_ARRAY;
}
if (methods == null) {
- methods = Method.EMPTY_METHOD_ARRAY;
+ methods = Method.EMPTY_ARRAY;
}
this.classNameIndex = classNameIndex;
this.superclassNameIndex = superclassNameIndex;
diff --git a/src/main/java/org/apache/bcel/classfile/Method.java b/src/main/java/org/apache/bcel/classfile/Method.java
index 84d7e4751d..57a70ff8e7 100644
--- a/src/main/java/org/apache/bcel/classfile/Method.java
+++ b/src/main/java/org/apache/bcel/classfile/Method.java
@@ -49,11 +49,6 @@ public int hashCode(final Method o) {
}
};
- /**
- * Empty array.
- */
- static final Method[] EMPTY_METHOD_ARRAY = {};
-
/**
* @return Comparison strategy object.
*/
From dfa1e7e7ddce740dadf666934d0b1e909eff10f2 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 31 Mar 2024 15:54:23 -0400
Subject: [PATCH 072/147] Normalize package private name
---
src/main/java/org/apache/bcel/classfile/MethodParameters.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/MethodParameters.java b/src/main/java/org/apache/bcel/classfile/MethodParameters.java
index e6152ae69a..3378e204ba 100644
--- a/src/main/java/org/apache/bcel/classfile/MethodParameters.java
+++ b/src/main/java/org/apache/bcel/classfile/MethodParameters.java
@@ -38,9 +38,9 @@ public class MethodParameters extends Attribute implements Iterable
Date: Sun, 31 Mar 2024 16:02:33 -0400
Subject: [PATCH 073/147] Avoid possible NullPointerException in
org.apache.bcel.classfile.DescendingVisitor.accept(E[])
---
src/changes/changes.xml | 1 +
.../java/org/apache/bcel/classfile/DescendingVisitor.java | 4 +++-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1895041d09..58e53dd771 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -60,6 +60,7 @@ The type attribute can be add,update,fix,remove.
-->
+ Avoid possible NullPointerException in org.apache.bcel.classfile.DescendingVisitor.accept(E[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java b/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
index c893a3948a..85de2a2a26 100644
--- a/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
+++ b/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
@@ -20,6 +20,8 @@
import java.util.Stack;
import java.util.stream.Stream;
+import org.apache.commons.lang3.stream.Streams;
+
/**
* Traverses a JavaClass with another Visitor object 'piggy-backed' that is applied to all components of a JavaClass
* object. I.e. this class supplies the traversal strategy, other classes can make use of it.
@@ -41,7 +43,7 @@ public DescendingVisitor(final JavaClass clazz, final Visitor visitor) {
}
private void accept(final E[] node) {
- Stream.of(node).forEach(e -> e.accept(this));
+ Streams.of(node).forEach(e -> e.accept(this));
}
/**
From 18690dedd95d99f6602ff361f8550147b98fdc96 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:06:42 -0400
Subject: [PATCH 074/147] Avoid possible NullPointerException in
AnnotationEntryGen.getAnnotationAttributes(ConstantPoolGen,
AnnotationEntryGen[])
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java | 3 ++-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 58e53dd771..e7472ae4a8 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -61,6 +61,7 @@ The type attribute can be add,update,fix,remove.
Avoid possible NullPointerException in org.apache.bcel.classfile.DescendingVisitor.accept(E[]).
+ Avoid possible NullPointerException in AnnotationEntryGen.getAnnotationAttributes(ConstantPoolGen, AnnotationEntryGen[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java b/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
index 603404a213..de0199c068 100644
--- a/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
+++ b/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
@@ -33,6 +33,7 @@
import org.apache.bcel.classfile.RuntimeInvisibleParameterAnnotations;
import org.apache.bcel.classfile.RuntimeVisibleAnnotations;
import org.apache.bcel.classfile.RuntimeVisibleParameterAnnotations;
+import org.apache.commons.lang3.ArrayUtils;
/**
* @since 6.0
@@ -48,7 +49,7 @@ public class AnnotationEntryGen {
* @param annotationEntryGens An array of AnnotationGen objects
*/
static Attribute[] getAnnotationAttributes(final ConstantPoolGen cp, final AnnotationEntryGen[] annotationEntryGens) {
- if (annotationEntryGens.length == 0) {
+ if (ArrayUtils.isEmpty(annotationEntryGens)) {
return Attribute.EMPTY_ARRAY;
}
From e82c816dea1e7058991272eb0869e090bb60a655 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:11:57 -0400
Subject: [PATCH 075/147] Avoid possible NullPointerException in
AnnotationEntryGen.copyValues(ElementValuePair[], ConstantPoolGen, boolean)
---
src/changes/changes.xml | 1 +
.../java/org/apache/bcel/generic/AnnotationEntryGen.java | 8 +++-----
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index e7472ae4a8..35ab98650a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -62,6 +62,7 @@ The type attribute can be add,update,fix,remove.
Avoid possible NullPointerException in org.apache.bcel.classfile.DescendingVisitor.accept(E[]).
Avoid possible NullPointerException in AnnotationEntryGen.getAnnotationAttributes(ConstantPoolGen, AnnotationEntryGen[]).
+ Avoid possible NullPointerException in AnnotationEntryGen.copyValues(ElementValuePair[], ConstantPoolGen, boolean).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java b/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
index de0199c068..e0e04ec4aa 100644
--- a/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
+++ b/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import org.apache.bcel.classfile.AnnotationEntry;
import org.apache.bcel.classfile.Attribute;
@@ -34,6 +35,7 @@
import org.apache.bcel.classfile.RuntimeVisibleAnnotations;
import org.apache.bcel.classfile.RuntimeVisibleParameterAnnotations;
import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.stream.Streams;
/**
* @since 6.0
@@ -251,11 +253,7 @@ public void addElementNameValuePair(final ElementValuePairGen evp) {
}
private List copyValues(final ElementValuePair[] in, final ConstantPoolGen cpool, final boolean copyPoolEntries) {
- final List out = new ArrayList<>();
- for (final ElementValuePair nvp : in) {
- out.add(new ElementValuePairGen(nvp, cpool, copyPoolEntries));
- }
- return out;
+ return Streams.of(in).map(nvp -> new ElementValuePairGen(nvp, cpool, copyPoolEntries)).collect(Collectors.toList());
}
public void dump(final DataOutputStream dos) throws IOException {
From ff013eb22d748e152a45bc10452bf5888d3cb935 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:12:17 -0400
Subject: [PATCH 076/147] Better local names
---
.../java/org/apache/bcel/generic/ArrayElementValueGen.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java b/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java
index 744a1ce8ae..48aa4bcd5b 100644
--- a/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java
+++ b/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java
@@ -50,14 +50,14 @@ public ArrayElementValueGen(final ConstantPoolGen cp) {
evalues = new ArrayList<>();
}
- public ArrayElementValueGen(final int type, final ElementValue[] datums, final ConstantPoolGen cpool) {
+ public ArrayElementValueGen(final int type, final ElementValue[] elementValues, final ConstantPoolGen cpool) {
super(type, cpool);
if (type != ARRAY) {
throw new IllegalArgumentException("Only element values of type array can be built with this ctor - type specified: " + type);
}
this.evalues = new ArrayList<>();
- for (final ElementValue datum : datums) {
- evalues.add(ElementValueGen.copy(datum, cpool, true));
+ for (final ElementValue elementValue : elementValues) {
+ evalues.add(ElementValueGen.copy(elementValue, cpool, true));
}
}
From 2cbfe92a9e7bc8544768dd83f0783a86a85589af Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:15:23 -0400
Subject: [PATCH 077/147] Avoid possible NullPointerException in
ArrayElementValueGen.ArrayElementValueGen(int, ElementValue[],
ConstantPoolGen)
---
src/changes/changes.xml | 1 +
.../java/org/apache/bcel/generic/ArrayElementValueGen.java | 7 +++----
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 35ab98650a..27d4ca7ba6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -63,6 +63,7 @@ The type attribute can be add,update,fix,remove.
Avoid possible NullPointerException in org.apache.bcel.classfile.DescendingVisitor.accept(E[]).
Avoid possible NullPointerException in AnnotationEntryGen.getAnnotationAttributes(ConstantPoolGen, AnnotationEntryGen[]).
Avoid possible NullPointerException in AnnotationEntryGen.copyValues(ElementValuePair[], ConstantPoolGen, boolean).
+ Avoid possible NullPointerException in ArrayElementValueGen.ArrayElementValueGen(int, ElementValue[], ConstantPoolGen).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java b/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java
index 48aa4bcd5b..21442263d5 100644
--- a/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java
+++ b/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java
@@ -20,9 +20,11 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import org.apache.bcel.classfile.ArrayElementValue;
import org.apache.bcel.classfile.ElementValue;
+import org.apache.commons.lang3.stream.Streams;
/**
* @since 6.0
@@ -55,10 +57,7 @@ public ArrayElementValueGen(final int type, final ElementValue[] elementValues,
if (type != ARRAY) {
throw new IllegalArgumentException("Only element values of type array can be built with this ctor - type specified: " + type);
}
- this.evalues = new ArrayList<>();
- for (final ElementValue elementValue : elementValues) {
- evalues.add(ElementValueGen.copy(elementValue, cpool, true));
- }
+ this.evalues = Streams.of(elementValues).map(e -> ElementValueGen.copy(e, cpool, true)).collect(Collectors.toList());
}
public void addElement(final ElementValueGen gen) {
From 3ba8aa0c24629381140c8159bf854af018f0914d Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:17:31 -0400
Subject: [PATCH 078/147] Avoid possible NullPointerException in
org.apache.bcel.generic.ClassGen.setMethods(Method[])
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/generic/ClassGen.java | 4 +++-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 27d4ca7ba6..919ec56dce 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -64,6 +64,7 @@ The type attribute can be add,update,fix,remove.
Avoid possible NullPointerException in AnnotationEntryGen.getAnnotationAttributes(ConstantPoolGen, AnnotationEntryGen[]).
Avoid possible NullPointerException in AnnotationEntryGen.copyValues(ElementValuePair[], ConstantPoolGen, boolean).
Avoid possible NullPointerException in ArrayElementValueGen.ArrayElementValueGen(int, ElementValue[], ConstantPoolGen).
+ Avoid possible NullPointerException in org.apache.bcel.generic.ClassGen.setMethods(Method[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/ClassGen.java b/src/main/java/org/apache/bcel/generic/ClassGen.java
index b612050a93..7799b14f7f 100644
--- a/src/main/java/org/apache/bcel/generic/ClassGen.java
+++ b/src/main/java/org/apache/bcel/generic/ClassGen.java
@@ -486,7 +486,9 @@ public void setMethodAt(final Method method, final int pos) {
public void setMethods(final Method[] methods) {
methodList.clear();
- Collections.addAll(methodList, methods);
+ if (methods != null) {
+ Collections.addAll(methodList, methods);
+ }
}
/**
From 35cc0cc33f3c6df685a2f7f04b955e9925a24798 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:21:12 -0400
Subject: [PATCH 079/147] Javadoc
---
.../bcel/classfile/RuntimeInvisibleAnnotations.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java b/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java
index 0cdfa5fd6e..410c1876d1 100644
--- a/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java
+++ b/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java
@@ -23,13 +23,15 @@
import org.apache.bcel.Const;
/**
- * represents an annotation that is represented in the class file but is not provided to the JVM.
+ * An annotation that is represented in the class file but is not provided to the JVM.
*
* @since 6.0
*/
public class RuntimeInvisibleAnnotations extends Annotations {
/**
+ * Constructs a new instance.
+ *
* @param nameIndex Index pointing to the name Code
* @param length Content length in bytes
* @param input Input stream
@@ -41,7 +43,9 @@ public RuntimeInvisibleAnnotations(final int nameIndex, final int length, final
}
/**
- * @return deep copy of this attribute
+ * Creates a deep copy of this attribute.
+ *
+ * @return deep copy of this attribute.
*/
@Override
public Attribute copy(final ConstantPool constantPool) {
From 7baa87ac608e28a888ca87d3814b4c563d91d2fa Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:21:54 -0400
Subject: [PATCH 080/147] Javadoc
---
src/main/java/org/apache/bcel/generic/ClassGen.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/generic/ClassGen.java b/src/main/java/org/apache/bcel/generic/ClassGen.java
index 7799b14f7f..a579c85156 100644
--- a/src/main/java/org/apache/bcel/generic/ClassGen.java
+++ b/src/main/java/org/apache/bcel/generic/ClassGen.java
@@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import java.util.stream.Collectors;
import org.apache.bcel.Const;
import org.apache.bcel.classfile.AccessFlags;
@@ -30,12 +31,12 @@
import org.apache.bcel.classfile.Field;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
-import org.apache.bcel.classfile.RuntimeInvisibleAnnotations;
import org.apache.bcel.classfile.RuntimeVisibleAnnotations;
import org.apache.bcel.classfile.SourceFile;
import org.apache.bcel.classfile.Utility;
import org.apache.bcel.util.BCELComparator;
import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.stream.Streams;
/**
* Template class for building up a java class. May be initialized with an existing Java class (file).
@@ -511,7 +512,7 @@ public void setSuperclassNameIndex(final int superclassNameIndex) {
}
/**
- * Look for attributes representing annotations and unpack them.
+ * Unpacks attributes representing annotations.
*/
private AnnotationEntryGen[] unpackAnnotations(final Attribute[] attrs) {
final List annotationGenObjs = new ArrayList<>();
From 5235833264a5778843d24de54c0188818473e72d Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:22:37 -0400
Subject: [PATCH 081/147] Better local name
---
src/main/java/org/apache/bcel/generic/ClassGen.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/generic/ClassGen.java b/src/main/java/org/apache/bcel/generic/ClassGen.java
index a579c85156..9526bb1498 100644
--- a/src/main/java/org/apache/bcel/generic/ClassGen.java
+++ b/src/main/java/org/apache/bcel/generic/ClassGen.java
@@ -514,9 +514,9 @@ public void setSuperclassNameIndex(final int superclassNameIndex) {
/**
* Unpacks attributes representing annotations.
*/
- private AnnotationEntryGen[] unpackAnnotations(final Attribute[] attrs) {
+ private AnnotationEntryGen[] unpackAnnotations(final Attribute[] attributes) {
final List annotationGenObjs = new ArrayList<>();
- for (final Attribute attr : attrs) {
+ for (final Attribute attr : attributes) {
if (attr instanceof RuntimeVisibleAnnotations) {
final RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations) attr;
rva.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
From 490800accbf9df8264e94ecde75b9ca1a25fc9d6 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:25:40 -0400
Subject: [PATCH 082/147] Javadoc
---
.../org/apache/bcel/classfile/ParameterAnnotations.java | 4 ++++
.../classfile/RuntimeInvisibleParameterAnnotations.java | 2 ++
.../apache/bcel/classfile/RuntimeVisibleAnnotations.java | 8 ++++++--
.../classfile/RuntimeVisibleParameterAnnotations.java | 2 ++
src/main/java/org/apache/bcel/generic/ClassGen.java | 3 +--
5 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java b/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
index d7a9a20d08..390d039104 100644
--- a/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
+++ b/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
@@ -33,6 +33,8 @@ public abstract class ParameterAnnotations extends Attribute implements Iterable
private ParameterAnnotationEntry[] parameterAnnotationTable;
/**
+ * Constructs a new instance.
+ *
* @param parameterAnnotationType the subclass type of the parameter annotation
* @param nameIndex Index pointing to the name Code
* @param length Content length in bytes
@@ -50,6 +52,8 @@ public abstract class ParameterAnnotations extends Attribute implements Iterable
}
/**
+ * Constructs a new instance.
+ *
* @param parameterAnnotationType the subclass type of the parameter annotation
* @param nameIndex Index pointing to the name Code
* @param length Content length in bytes
diff --git a/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleParameterAnnotations.java b/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleParameterAnnotations.java
index 9fb84b96a6..44ff1bed45 100644
--- a/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleParameterAnnotations.java
+++ b/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleParameterAnnotations.java
@@ -29,6 +29,8 @@
public class RuntimeInvisibleParameterAnnotations extends ParameterAnnotations {
/**
+ * Constructs a new instance.
+ *
* @param nameIndex Index pointing to the name Code
* @param length Content length in bytes
* @param input Input stream
diff --git a/src/main/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java b/src/main/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java
index f17dd8e994..071e28659f 100644
--- a/src/main/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java
+++ b/src/main/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java
@@ -23,13 +23,15 @@
import org.apache.bcel.Const;
/**
- * represents an annotation that is represented in the class file and is provided to the JVM.
+ * An annotation that is represented in the class file and is provided to the JVM.
*
* @since 6.0
*/
public class RuntimeVisibleAnnotations extends Annotations {
/**
+ * Constructs a new instance.
+ *
* @param nameIndex Index pointing to the name Code
* @param length Content length in bytes
* @param input Input stream
@@ -41,7 +43,9 @@ public RuntimeVisibleAnnotations(final int nameIndex, final int length, final Da
}
/**
- * @return deep copy of this attribute
+ * Creates a deep copy of this attribute.
+ *
+ * @return deep copy of this attribute.
*/
@Override
public Attribute copy(final ConstantPool constantPool) {
diff --git a/src/main/java/org/apache/bcel/classfile/RuntimeVisibleParameterAnnotations.java b/src/main/java/org/apache/bcel/classfile/RuntimeVisibleParameterAnnotations.java
index 299627bcb4..ad9d662596 100644
--- a/src/main/java/org/apache/bcel/classfile/RuntimeVisibleParameterAnnotations.java
+++ b/src/main/java/org/apache/bcel/classfile/RuntimeVisibleParameterAnnotations.java
@@ -29,6 +29,8 @@
public class RuntimeVisibleParameterAnnotations extends ParameterAnnotations {
/**
+ * Constructs a new instance.
+ *
* @param nameIndex Index pointing to the name Code
* @param length Content length in bytes
* @param input Input stream
diff --git a/src/main/java/org/apache/bcel/generic/ClassGen.java b/src/main/java/org/apache/bcel/generic/ClassGen.java
index 9526bb1498..9ed5c42c7c 100644
--- a/src/main/java/org/apache/bcel/generic/ClassGen.java
+++ b/src/main/java/org/apache/bcel/generic/ClassGen.java
@@ -21,7 +21,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
-import java.util.stream.Collectors;
import org.apache.bcel.Const;
import org.apache.bcel.classfile.AccessFlags;
@@ -31,12 +30,12 @@
import org.apache.bcel.classfile.Field;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
+import org.apache.bcel.classfile.RuntimeInvisibleAnnotations;
import org.apache.bcel.classfile.RuntimeVisibleAnnotations;
import org.apache.bcel.classfile.SourceFile;
import org.apache.bcel.classfile.Utility;
import org.apache.bcel.util.BCELComparator;
import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.stream.Streams;
/**
* Template class for building up a java class. May be initialized with an existing Java class (file).
From a7016253948e2b8faa6b14575199ef9f402888d5 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:27:09 -0400
Subject: [PATCH 083/147] Avoid possible NullPointerException in
org.apache.bcel.generic.ClassGen.unpackAnnotations(Attribute[])
---
src/changes/changes.xml | 1 +
.../java/org/apache/bcel/generic/ClassGen.java | 16 +++++++++-------
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 919ec56dce..1e26e2fec5 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -65,6 +65,7 @@ The type attribute can be add,update,fix,remove.
Avoid possible NullPointerException in AnnotationEntryGen.copyValues(ElementValuePair[], ConstantPoolGen, boolean).
Avoid possible NullPointerException in ArrayElementValueGen.ArrayElementValueGen(int, ElementValue[], ConstantPoolGen).
Avoid possible NullPointerException in org.apache.bcel.generic.ClassGen.setMethods(Method[]).
+ Avoid possible NullPointerException in org.apache.bcel.generic.ClassGen.unpackAnnotations(Attribute[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/ClassGen.java b/src/main/java/org/apache/bcel/generic/ClassGen.java
index 9ed5c42c7c..aa9de68ee2 100644
--- a/src/main/java/org/apache/bcel/generic/ClassGen.java
+++ b/src/main/java/org/apache/bcel/generic/ClassGen.java
@@ -515,13 +515,15 @@ public void setSuperclassNameIndex(final int superclassNameIndex) {
*/
private AnnotationEntryGen[] unpackAnnotations(final Attribute[] attributes) {
final List annotationGenObjs = new ArrayList<>();
- for (final Attribute attr : attributes) {
- if (attr instanceof RuntimeVisibleAnnotations) {
- final RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations) attr;
- rva.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
- } else if (attr instanceof RuntimeInvisibleAnnotations) {
- final RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations) attr;
- ria.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
+ if (attributes != null) {
+ for (final Attribute attr : attributes) {
+ if (attr instanceof RuntimeVisibleAnnotations) {
+ final RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations) attr;
+ rva.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
+ } else if (attr instanceof RuntimeInvisibleAnnotations) {
+ final RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations) attr;
+ ria.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
+ }
}
}
return annotationGenObjs.toArray(AnnotationEntryGen.EMPTY_ARRAY);
From 1e4e630f4367d486694b68b759ea0371bb965bef Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:31:31 -0400
Subject: [PATCH 084/147] Avoid possible NullPointerException in
org.apache.bcel.classfile.ParameterAnnotationEntry.createParameterAnnotationEntries(Attribute[])
---
src/changes/changes.xml | 1 +
.../org/apache/bcel/classfile/ParameterAnnotationEntry.java | 5 ++++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1e26e2fec5..4f84d3a259 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -66,6 +66,7 @@ The type attribute can be add,update,fix,remove.
Avoid possible NullPointerException in ArrayElementValueGen.ArrayElementValueGen(int, ElementValue[], ConstantPoolGen).
Avoid possible NullPointerException in org.apache.bcel.generic.ClassGen.setMethods(Method[]).
Avoid possible NullPointerException in org.apache.bcel.generic.ClassGen.unpackAnnotations(Attribute[]).
+ Avoid possible NullPointerException in org.apache.bcel.classfile.ParameterAnnotationEntry.createParameterAnnotationEntries(Attribute[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java b/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
index 563ff6b091..f6aa2d2765 100644
--- a/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
+++ b/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
@@ -38,7 +38,10 @@ public static ParameterAnnotationEntry[] createParameterAnnotationEntries(final
for (final Attribute attribute : attrs) {
if (attribute instanceof ParameterAnnotations) {
final ParameterAnnotations runtimeAnnotations = (ParameterAnnotations) attribute;
- Collections.addAll(accumulatedAnnotations, runtimeAnnotations.getParameterAnnotationEntries());
+ final ParameterAnnotationEntry[] parameterAnnotationEntries = runtimeAnnotations.getParameterAnnotationEntries();
+ if (parameterAnnotationEntries != null) {
+ Collections.addAll(accumulatedAnnotations, parameterAnnotationEntries);
+ }
}
}
return accumulatedAnnotations.toArray(ParameterAnnotationEntry.EMPTY_ARRAY);
From c7082c0975590fc052ce10d777789bdd295df86f Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:36:44 -0400
Subject: [PATCH 085/147] Avoid possible NullPointerException in
org.apache.bcel.generic.ClassGen.ClassGen(JavaClass)
---
src/changes/changes.xml | 1 +
.../org/apache/bcel/generic/ClassGen.java | 26 +++++++++++++------
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4f84d3a259..9ac6575a1a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -67,6 +67,7 @@ The type attribute can be add,update,fix,remove.
Avoid possible NullPointerException in org.apache.bcel.generic.ClassGen.setMethods(Method[]).
Avoid possible NullPointerException in org.apache.bcel.generic.ClassGen.unpackAnnotations(Attribute[]).
Avoid possible NullPointerException in org.apache.bcel.classfile.ParameterAnnotationEntry.createParameterAnnotationEntries(Attribute[]).
+ Avoid possible NullPointerException in org.apache.bcel.generic.ClassGen.ClassGen(JavaClass).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/ClassGen.java b/src/main/java/org/apache/bcel/generic/ClassGen.java
index aa9de68ee2..12cb3bf46b 100644
--- a/src/main/java/org/apache/bcel/generic/ClassGen.java
+++ b/src/main/java/org/apache/bcel/generic/ClassGen.java
@@ -95,7 +95,7 @@ public static void setComparator(final BCELComparator comparator) {
private List observers;
/**
- * Initialize with existing class.
+ * Constructs a new instance from an existing class.
*
* @param clazz JavaClass object (e.g. read from file)
*/
@@ -112,16 +112,26 @@ public ClassGen(final JavaClass clazz) {
final Attribute[] attributes = clazz.getAttributes();
// J5TODO: Could make unpacking lazy, done on first reference
final AnnotationEntryGen[] annotations = unpackAnnotations(attributes);
- Collections.addAll(interfaceList, clazz.getInterfaceNames());
- for (final Attribute attribute : attributes) {
- if (!(attribute instanceof Annotations)) {
- addAttribute(attribute);
+ final String[] interfaceNames = clazz.getInterfaceNames();
+ if (interfaceNames != null) {
+ Collections.addAll(interfaceList, interfaceNames);
+ }
+ if (attributes != null) {
+ for (final Attribute attribute : attributes) {
+ if (!(attribute instanceof Annotations)) {
+ addAttribute(attribute);
+ }
}
}
Collections.addAll(annotationList, annotations);
- Collections.addAll(methodList, clazz.getMethods());
- Collections.addAll(fieldList, clazz.getFields());
- }
+ final Method[] methods = clazz.getMethods();
+ if (methods != null) {
+ Collections.addAll(methodList, methods);
+ }
+ final Field[] fields = clazz.getFields();
+ if (fields != null) {
+ Collections.addAll(fieldList, fields);
+ }}
/**
* Convenience constructor to set up some important values initially.
From f420889909d2920cb45eb006a860e4b04b43a999 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:37:53 -0400
Subject: [PATCH 086/147] Avoid possible NullPointerException in
org.apache.bcel.generic.FieldGenOrMethodGen.addAll(Attribute[])
---
src/changes/changes.xml | 1 +
.../java/org/apache/bcel/generic/FieldGenOrMethodGen.java | 6 ++++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9ac6575a1a..5246fd3f1a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -68,6 +68,7 @@ The type attribute can be add,update,fix,remove.
Avoid possible NullPointerException in org.apache.bcel.generic.ClassGen.unpackAnnotations(Attribute[]).
Avoid possible NullPointerException in org.apache.bcel.classfile.ParameterAnnotationEntry.createParameterAnnotationEntries(Attribute[]).
Avoid possible NullPointerException in org.apache.bcel.generic.ClassGen.ClassGen(JavaClass).
+ Avoid possible NullPointerException in org.apache.bcel.generic.FieldGenOrMethodGen.addAll(Attribute[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/FieldGenOrMethodGen.java b/src/main/java/org/apache/bcel/generic/FieldGenOrMethodGen.java
index 9f6c5b2d5d..9b6fbabedf 100644
--- a/src/main/java/org/apache/bcel/generic/FieldGenOrMethodGen.java
+++ b/src/main/java/org/apache/bcel/generic/FieldGenOrMethodGen.java
@@ -62,8 +62,10 @@ protected FieldGenOrMethodGen(final int accessFlags) { // TODO could this be pac
super(accessFlags);
}
- protected void addAll(final Attribute[] attrs) {
- Collections.addAll(attributeList, attrs);
+ protected void addAll(final Attribute[] attributes) {
+ if (attributes != null) {
+ Collections.addAll(attributeList, attributes);
+ }
}
/**
From e8357416743dc009e630d2d47121653e3b6e841e Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 09:45:44 -0400
Subject: [PATCH 087/147] Remove trainling whitespace
Fix Checkstyle formatting issue
---
.../org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java | 2 +-
src/main/java/org/apache/bcel/generic/ClassGen.java | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java b/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java
index 410c1876d1..1c087ed19f 100644
--- a/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java
+++ b/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java
@@ -44,7 +44,7 @@ public RuntimeInvisibleAnnotations(final int nameIndex, final int length, final
/**
* Creates a deep copy of this attribute.
- *
+ *
* @return deep copy of this attribute.
*/
@Override
diff --git a/src/main/java/org/apache/bcel/generic/ClassGen.java b/src/main/java/org/apache/bcel/generic/ClassGen.java
index 12cb3bf46b..e961cbcb54 100644
--- a/src/main/java/org/apache/bcel/generic/ClassGen.java
+++ b/src/main/java/org/apache/bcel/generic/ClassGen.java
@@ -131,7 +131,8 @@ public ClassGen(final JavaClass clazz) {
final Field[] fields = clazz.getFields();
if (fields != null) {
Collections.addAll(fieldList, fields);
- }}
+ }
+ }
/**
* Convenience constructor to set up some important values initially.
From d8b437b9c045094e4bb5bc3998b9e9dafcc296c1 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:22:29 -0400
Subject: [PATCH 088/147] Avoid possible NullPointerException in
org.apache.bcel.classfile.ParameterAnnotationEntry.createParameterAnnotationEntries(Attribute[])
---
src/changes/changes.xml | 1 +
.../bcel/classfile/ParameterAnnotationEntry.java | 11 +++++++----
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 5246fd3f1a..d8fc6196a6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -69,6 +69,7 @@ The type attribute can be add,update,fix,remove.
Avoid possible NullPointerException in org.apache.bcel.classfile.ParameterAnnotationEntry.createParameterAnnotationEntries(Attribute[]).
Avoid possible NullPointerException in org.apache.bcel.generic.ClassGen.ClassGen(JavaClass).
Avoid possible NullPointerException in org.apache.bcel.generic.FieldGenOrMethodGen.addAll(Attribute[]).
+ Avoid possible NullPointerException in org.apache.bcel.classfile.ParameterAnnotationEntry.createParameterAnnotationEntries(Attribute[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java b/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
index f6aa2d2765..70f6236e14 100644
--- a/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
+++ b/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
@@ -32,10 +32,13 @@ public class ParameterAnnotationEntry implements Node {
static final ParameterAnnotationEntry[] EMPTY_ARRAY = {};
- public static ParameterAnnotationEntry[] createParameterAnnotationEntries(final Attribute[] attrs) {
+ public static ParameterAnnotationEntry[] createParameterAnnotationEntries(final Attribute[] attributes) {
+ if (attributes == null) {
+ return EMPTY_ARRAY;
+ }
// Find attributes that contain parameter annotation data
- final List accumulatedAnnotations = new ArrayList<>(attrs.length);
- for (final Attribute attribute : attrs) {
+ final List accumulatedAnnotations = new ArrayList<>(attributes.length);
+ for (final Attribute attribute : attributes) {
if (attribute instanceof ParameterAnnotations) {
final ParameterAnnotations runtimeAnnotations = (ParameterAnnotations) attribute;
final ParameterAnnotationEntry[] parameterAnnotationEntries = runtimeAnnotations.getParameterAnnotationEntries();
@@ -44,7 +47,7 @@ public static ParameterAnnotationEntry[] createParameterAnnotationEntries(final
}
}
}
- return accumulatedAnnotations.toArray(ParameterAnnotationEntry.EMPTY_ARRAY);
+ return accumulatedAnnotations.toArray(EMPTY_ARRAY);
}
private final AnnotationEntry[] annotationTable;
From 97e4ac7c34de9991cfd582dbb8ef461889e288f2 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:23:15 -0400
Subject: [PATCH 089/147] Remove whitespace
---
src/main/java/org/apache/bcel/classfile/MethodParameters.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/main/java/org/apache/bcel/classfile/MethodParameters.java b/src/main/java/org/apache/bcel/classfile/MethodParameters.java
index 3378e204ba..e4fe39393d 100644
--- a/src/main/java/org/apache/bcel/classfile/MethodParameters.java
+++ b/src/main/java/org/apache/bcel/classfile/MethodParameters.java
@@ -44,7 +44,6 @@ public class MethodParameters extends Attribute implements Iterable
Date: Mon, 1 Apr 2024 10:23:23 -0400
Subject: [PATCH 090/147] Remove whitespace
---
src/main/java/org/apache/bcel/classfile/MethodParameters.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/main/java/org/apache/bcel/classfile/MethodParameters.java b/src/main/java/org/apache/bcel/classfile/MethodParameters.java
index e4fe39393d..caf2a3ddb1 100644
--- a/src/main/java/org/apache/bcel/classfile/MethodParameters.java
+++ b/src/main/java/org/apache/bcel/classfile/MethodParameters.java
@@ -60,7 +60,6 @@ public void accept(final Visitor v) {
public Attribute copy(final ConstantPool constantPool) {
final MethodParameters c = (MethodParameters) clone();
c.parameters = new MethodParameter[parameters.length];
-
Arrays.setAll(c.parameters, i -> parameters[i].copy());
c.setConstantPool(constantPool);
return c;
From 69e745d679447e0e6899923b72df05a70e0e1e65 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:28:05 -0400
Subject: [PATCH 091/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.MethodParameters.setParameters(MethodParameter[])
with null
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/classfile/MethodParameters.java | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d8fc6196a6..c791986d98 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -70,6 +70,7 @@ The type attribute can be add,update,fix,remove.
Avoid possible NullPointerException in org.apache.bcel.generic.ClassGen.ClassGen(JavaClass).
Avoid possible NullPointerException in org.apache.bcel.generic.FieldGenOrMethodGen.addAll(Attribute[]).
Avoid possible NullPointerException in org.apache.bcel.classfile.ParameterAnnotationEntry.createParameterAnnotationEntries(Attribute[]).
+ Avoid NullPointerException after calling org.apache.bcel.classfile.MethodParameters.setParameters(MethodParameter[]) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/MethodParameters.java b/src/main/java/org/apache/bcel/classfile/MethodParameters.java
index caf2a3ddb1..0799c21284 100644
--- a/src/main/java/org/apache/bcel/classfile/MethodParameters.java
+++ b/src/main/java/org/apache/bcel/classfile/MethodParameters.java
@@ -90,6 +90,6 @@ public Iterator iterator() {
}
public void setParameters(final MethodParameter[] parameters) {
- this.parameters = parameters;
+ this.parameters = parameters != null ? parameters : EMPTY_ARRAY;
}
}
From 80e862649d3ab6fb28ea55eacc772318b1182d06 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:28:45 -0400
Subject: [PATCH 092/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.ParameterAnnotations.setParameterAnnotationTable(ParameterAnnotationEntry[])
with null
---
src/changes/changes.xml | 1 +
.../java/org/apache/bcel/classfile/ParameterAnnotations.java | 4 +++-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c791986d98..03e74af392 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -71,6 +71,7 @@ The type attribute can be add,update,fix,remove.
Avoid possible NullPointerException in org.apache.bcel.generic.FieldGenOrMethodGen.addAll(Attribute[]).
Avoid possible NullPointerException in org.apache.bcel.classfile.ParameterAnnotationEntry.createParameterAnnotationEntries(Attribute[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.MethodParameters.setParameters(MethodParameter[]) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.ParameterAnnotations.setParameterAnnotationTable(ParameterAnnotationEntry[]) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java b/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
index 390d039104..615e163b59 100644
--- a/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
+++ b/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
@@ -29,6 +29,8 @@
*/
public abstract class ParameterAnnotations extends Attribute implements Iterable {
+ private static final ParameterAnnotationEntry[] EMPTY_ARRAY = {};
+
/** Table of parameter annotations */
private ParameterAnnotationEntry[] parameterAnnotationTable;
@@ -119,6 +121,6 @@ public Iterator iterator() {
* @param parameterAnnotationTable the entries to set in this parameter annotation
*/
public final void setParameterAnnotationTable(final ParameterAnnotationEntry[] parameterAnnotationTable) {
- this.parameterAnnotationTable = parameterAnnotationTable;
+ this.parameterAnnotationTable = parameterAnnotationTable != null ? parameterAnnotationTable : EMPTY_ARRAY;
}
}
From d6fa48b67b691a502cb9696e451944546fc47288 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:31:26 -0400
Subject: [PATCH 093/147] Remove whitespace
---
.../org/apache/bcel/classfile/LocalVariableTypeTable.java | 7 -------
1 file changed, 7 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java b/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
index 8a35c6ea20..bb8e1f0849 100644
--- a/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
+++ b/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
@@ -64,10 +64,8 @@ public class LocalVariableTypeTable extends Attribute implements Iterable localVariableTypeTable[i].copy());
c.setConstantPool(constantPool);
@@ -116,7 +113,6 @@ public final LocalVariable getLocalVariable(final int index) {
return variable;
}
}
-
return null;
}
@@ -143,15 +139,12 @@ public final void setLocalVariableTable(final LocalVariable[] localVariableTable
@Override
public final String toString() {
final StringBuilder buf = new StringBuilder();
-
for (int i = 0; i < localVariableTypeTable.length; i++) {
buf.append(localVariableTypeTable[i].toStringShared(true));
-
if (i < localVariableTypeTable.length - 1) {
buf.append('\n');
}
}
-
return buf.toString();
}
}
From 46eb29380955c75cf27d9cdb757debbb5bc64cd7 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:32:43 -0400
Subject: [PATCH 094/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.LocalVariableTypeTable.setLocalVariableTable(LocalVariable[])
with null
---
src/changes/changes.xml | 1 +
.../org/apache/bcel/classfile/LocalVariableTypeTable.java | 4 +++-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 03e74af392..be5a862d94 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -72,6 +72,7 @@ The type attribute can be add,update,fix,remove.
Avoid possible NullPointerException in org.apache.bcel.classfile.ParameterAnnotationEntry.createParameterAnnotationEntries(Attribute[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.MethodParameters.setParameters(MethodParameter[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.ParameterAnnotations.setParameterAnnotationTable(ParameterAnnotationEntry[]) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.LocalVariableTypeTable.setLocalVariableTable(LocalVariable[]) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java b/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
index bb8e1f0849..8f4e4e8f29 100644
--- a/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
+++ b/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
@@ -60,6 +60,8 @@
*/
public class LocalVariableTypeTable extends Attribute implements Iterable {
+ private static final LocalVariable[] EMPTY_ARRAY = {};
+
private LocalVariable[] localVariableTypeTable; // variables
LocalVariableTypeTable(final int nameIdx, final int len, final DataInput input, final ConstantPool cpool) throws IOException {
@@ -130,7 +132,7 @@ public Iterator iterator() {
}
public final void setLocalVariableTable(final LocalVariable[] localVariableTable) {
- this.localVariableTypeTable = localVariableTable;
+ this.localVariableTypeTable = localVariableTable != null ? localVariableTable : EMPTY_ARRAY;
}
/**
From a35914a398f249b14e9b93121aa6ab06a5c2dc39 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:39:29 -0400
Subject: [PATCH 095/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.LocalVariableTable.setLocalVariableTable(LocalVariable[])
with null
---
src/changes/changes.xml | 1 +
.../org/apache/bcel/classfile/LocalVariableTable.java | 8 +++++---
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index be5a862d94..b36badaa20 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -73,6 +73,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.MethodParameters.setParameters(MethodParameter[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.ParameterAnnotations.setParameterAnnotationTable(ParameterAnnotationEntry[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.LocalVariableTypeTable.setLocalVariableTable(LocalVariable[]) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.LocalVariableTable.setLocalVariableTable(LocalVariable[]) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/LocalVariableTable.java b/src/main/java/org/apache/bcel/classfile/LocalVariableTable.java
index 778932b620..b73e99c28f 100644
--- a/src/main/java/org/apache/bcel/classfile/LocalVariableTable.java
+++ b/src/main/java/org/apache/bcel/classfile/LocalVariableTable.java
@@ -35,6 +35,8 @@
*/
public class LocalVariableTable extends Attribute implements Iterable {
+ private static final LocalVariable[] EMPTY_ARRAY = {};
+
private LocalVariable[] localVariableTable; // variables
/**
@@ -63,7 +65,7 @@ public class LocalVariableTable extends Attribute implements Iterable iterator() {
}
public final void setLocalVariableTable(final LocalVariable[] localVariableTable) {
- this.localVariableTable = localVariableTable;
+ this.localVariableTable = localVariableTable != null ? localVariableTable : EMPTY_ARRAY;
}
/**
From 81e11ac5b573737647c95b48cfafb34e9ffa4521 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:39:35 -0400
Subject: [PATCH 096/147] Remove whitespace
---
.../java/org/apache/bcel/classfile/ParameterAnnotations.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java b/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
index 615e163b59..4120521d1c 100644
--- a/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
+++ b/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
@@ -30,7 +30,7 @@
public abstract class ParameterAnnotations extends Attribute implements Iterable {
private static final ParameterAnnotationEntry[] EMPTY_ARRAY = {};
-
+
/** Table of parameter annotations */
private ParameterAnnotationEntry[] parameterAnnotationTable;
From 6c0452a853a6820a4c885d79637a01e25b80dfde Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:43:16 -0400
Subject: [PATCH 097/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.LineNumberTable.setLineNumberTable(LineNumber[])
Update constant ref
---
src/changes/changes.xml | 1 +
.../bcel/classfile/LineNumberTable.java | 21 ++++++++++---------
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b36badaa20..1505feb540 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -74,6 +74,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.ParameterAnnotations.setParameterAnnotationTable(ParameterAnnotationEntry[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.LocalVariableTypeTable.setLocalVariableTable(LocalVariable[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.LocalVariableTable.setLocalVariableTable(LocalVariable[]) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.LineNumberTable.setLineNumberTable(LineNumber[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/LineNumberTable.java b/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
index 929b5f1805..55f58239e9 100644
--- a/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
+++ b/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
@@ -39,7 +39,7 @@ public final class LineNumberTable extends Attribute implements Iterable
+ * Note that both objects use the same references (shallow copy). Use copy() for a physical copy.
+ *
*/
public LineNumberTable(final LineNumberTable c) {
this(c.getNameIndex(), c.getLength(), c.getLineNumberTable(), c.getConstantPool());
@@ -173,7 +174,7 @@ public int getSourceLine(final int pos) {
}
public int getTableLength() {
- return lineNumberTable == null ? 0 : lineNumberTable.length;
+ return lineNumberTable.length;
}
@Override
@@ -185,7 +186,7 @@ public Iterator iterator() {
* @param lineNumberTable the line number entries for this table
*/
public void setLineNumberTable(final LineNumber[] lineNumberTable) {
- this.lineNumberTable = lineNumberTable;
+ this.lineNumberTable = lineNumberTable != null ? lineNumberTable : EMPTY_ARRAY;
}
/**
From ac67474e61bfa7ecc80c33f21aea19a209e33239 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:43:37 -0400
Subject: [PATCH 098/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.LineNumberTable.setLineNumberTable(LineNumber[])
Update constant ref
---
src/main/java/org/apache/bcel/classfile/LineNumberTable.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/bcel/classfile/LineNumberTable.java b/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
index 55f58239e9..fe5a53d65b 100644
--- a/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
+++ b/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
@@ -186,7 +186,7 @@ public Iterator iterator() {
* @param lineNumberTable the line number entries for this table
*/
public void setLineNumberTable(final LineNumber[] lineNumberTable) {
- this.lineNumberTable = lineNumberTable != null ? lineNumberTable : EMPTY_ARRAY;
+ this.lineNumberTable = lineNumberTable != null ? lineNumberTable : LineNumber.EMPTY_ARRAY;
}
/**
From 92b4730dba2e1aa10254ec053a20641f46e63bee Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:46:09 -0400
Subject: [PATCH 099/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.JavaClass.setMethods(Method[])
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/classfile/JavaClass.java | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1505feb540..d9662b7520 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -75,6 +75,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.LocalVariableTypeTable.setLocalVariableTable(LocalVariable[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.LocalVariableTable.setLocalVariableTable(LocalVariable[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.LineNumberTable.setLineNumberTable(LineNumber[]).
+ Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setMethods(Method[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/JavaClass.java b/src/main/java/org/apache/bcel/classfile/JavaClass.java
index 44cd75b1ed..8f85837159 100644
--- a/src/main/java/org/apache/bcel/classfile/JavaClass.java
+++ b/src/main/java/org/apache/bcel/classfile/JavaClass.java
@@ -812,7 +812,7 @@ public void setMajor(final int major) {
* @param methods .
*/
public void setMethods(final Method[] methods) {
- this.methods = methods;
+ this.methods = methods != null ? methods : Method.EMPTY_ARRAY;
}
/**
From fb6ef54b23edbdc4a34e5c1087d0785f09433771 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:47:36 -0400
Subject: [PATCH 100/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.JavaClass.setInterfaces(int[])
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/classfile/JavaClass.java | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d9662b7520..9ba1d17eeb 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -76,6 +76,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.LocalVariableTable.setLocalVariableTable(LocalVariable[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.LineNumberTable.setLineNumberTable(LineNumber[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setMethods(Method[]).
+ Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setInterfaces(int[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/JavaClass.java b/src/main/java/org/apache/bcel/classfile/JavaClass.java
index 8f85837159..ec54167ab1 100644
--- a/src/main/java/org/apache/bcel/classfile/JavaClass.java
+++ b/src/main/java/org/apache/bcel/classfile/JavaClass.java
@@ -798,7 +798,7 @@ public void setInterfaceNames(final String[] interfaceNames) {
* @param interfaces .
*/
public void setInterfaces(final int[] interfaces) {
- this.interfaces = interfaces;
+ this.interfaces = ArrayUtils.nullToEmpty(interfaces);
}
/**
From 7b44a1d8733dbd080f1a0c5670490220c302573d Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:48:55 -0400
Subject: [PATCH 101/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.JavaClass.setInterfaceNames(String[])
---
src/changes/changes.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9ba1d17eeb..8b1b818f4a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -77,6 +77,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.LineNumberTable.setLineNumberTable(LineNumber[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setMethods(Method[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setInterfaces(int[]).
+ Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setInterfaceNames(String[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
From f21a3121abd708fab5357597753d2a993a485dd0 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:49:56 -0400
Subject: [PATCH 102/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.JavaClass.setFields(Field[])
---
src/changes/changes.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8b1b818f4a..5e68da6d5b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -78,6 +78,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setMethods(Method[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setInterfaces(int[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setInterfaceNames(String[]).
+ Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setFields(Field[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
From 0e1b4721e911df7f1746f4cd4cd17cb3250b5202 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:52:03 -0400
Subject: [PATCH 103/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.JavaClass.setAttributes(Attribute[])
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/classfile/JavaClass.java | 6 +++---
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 5e68da6d5b..24803f8082 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -79,6 +79,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setInterfaces(int[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setInterfaceNames(String[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setFields(Field[]).
+ Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setAttributes(Attribute[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/JavaClass.java b/src/main/java/org/apache/bcel/classfile/JavaClass.java
index ec54167ab1..de4ac4b117 100644
--- a/src/main/java/org/apache/bcel/classfile/JavaClass.java
+++ b/src/main/java/org/apache/bcel/classfile/JavaClass.java
@@ -749,7 +749,7 @@ public final boolean isSuper() {
* @param attributes .
*/
public void setAttributes(final Attribute[] attributes) {
- this.attributes = attributes;
+ this.attributes = attributes != null ? attributes : Attribute.EMPTY_ARRAY;
}
/**
@@ -777,7 +777,7 @@ public void setConstantPool(final ConstantPool constantPool) {
* @param fields .
*/
public void setFields(final Field[] fields) {
- this.fields = fields;
+ this.fields = fields != null ? fields : Field.EMPTY_ARRAY;
}
/**
@@ -791,7 +791,7 @@ public void setFileName(final String fileName) {
* @param interfaceNames .
*/
public void setInterfaceNames(final String[] interfaceNames) {
- this.interfaceNames = interfaceNames;
+ this.interfaceNames = ArrayUtils.nullToEmpty(interfaceNames);
}
/**
From 3a743f9a4f6d42ea8b97dce76f68b7aca39f45e6 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:56:07 -0400
Subject: [PATCH 104/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.ConstantPool.setConstantPool(Constant[])
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/classfile/Constant.java | 2 ++
src/main/java/org/apache/bcel/classfile/ConstantPool.java | 6 +++---
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 24803f8082..a05260ba48 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -80,6 +80,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setInterfaceNames(String[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setFields(Field[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setAttributes(Attribute[]).
+ Avoid NullPointerException after calling org.apache.bcel.classfile.ConstantPool.setConstantPool(Constant[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/Constant.java b/src/main/java/org/apache/bcel/classfile/Constant.java
index 6ed876d058..c55601d8bc 100644
--- a/src/main/java/org/apache/bcel/classfile/Constant.java
+++ b/src/main/java/org/apache/bcel/classfile/Constant.java
@@ -30,6 +30,8 @@
*/
public abstract class Constant implements Cloneable, Node {
+ static final Constant[] EMPTY_ARRAY = {};
+
private static BCELComparator bcelComparator = new BCELComparator() {
@Override
diff --git a/src/main/java/org/apache/bcel/classfile/ConstantPool.java b/src/main/java/org/apache/bcel/classfile/ConstantPool.java
index e94f35dde5..a046dc5059 100644
--- a/src/main/java/org/apache/bcel/classfile/ConstantPool.java
+++ b/src/main/java/org/apache/bcel/classfile/ConstantPool.java
@@ -68,7 +68,7 @@ private static String escape(final String str) {
* @param constantPool Array of constants
*/
public ConstantPool(final Constant[] constantPool) {
- this.constantPool = constantPool;
+ setConstantPool(constantPool);
}
/**
@@ -399,7 +399,7 @@ public ConstantUtf8 getConstantUtf8(final int index) throws ClassFormatException
* @return Length of constant pool.
*/
public int getLength() {
- return constantPool == null ? 0 : constantPool.length;
+ return constantPool.length;
}
@Override
@@ -418,7 +418,7 @@ public void setConstant(final int index, final Constant constant) {
* @param constantPool
*/
public void setConstantPool(final Constant[] constantPool) {
- this.constantPool = constantPool;
+ this.constantPool = constantPool != null ? constantPool : Constant.EMPTY_ARRAY;
}
/**
From 82bd20aaa6fae62df8e714e839876d914c3022ee Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:59:20 -0400
Subject: [PATCH 105/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.FieldOrMethod.setAttributes(Attribute[])
---
src/changes/changes.xml | 1 +
.../java/org/apache/bcel/classfile/FieldOrMethod.java | 10 ++++------
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a05260ba48..1bf0a6d0be 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -81,6 +81,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setFields(Field[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setAttributes(Attribute[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.ConstantPool.setConstantPool(Constant[]).
+ Avoid NullPointerException after calling org.apache.bcel.classfile.FieldOrMethod.setAttributes(Attribute[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java b/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java
index 76f30617a6..1b2081ed9c 100644
--- a/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java
+++ b/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java
@@ -147,10 +147,8 @@ public final void dump(final DataOutputStream file) throws IOException {
file.writeShort(name_index);
file.writeShort(signature_index);
file.writeShort(attributes_count);
- if (attributes != null) {
- for (final Attribute attribute : attributes) {
- attribute.dump(file);
- }
+ for (final Attribute attribute : attributes) {
+ attribute.dump(file);
}
}
@@ -233,8 +231,8 @@ public final int getSignatureIndex() {
* @param attributes Collection of object attributes.
*/
public final void setAttributes(final Attribute[] attributes) {
- this.attributes = attributes;
- this.attributes_count = attributes != null ? attributes.length : 0; // init deprecated field
+ this.attributes = attributes != null ? attributes : Attribute.EMPTY_ARRAY;
+ this.attributes_count = this.attributes.length; // init deprecated field
}
/**
From 9c1771075155420c4c843df32acda455556710b6 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 10:59:59 -0400
Subject: [PATCH 106/147] Better local name
---
.../java/org/apache/bcel/classfile/AnnotationEntry.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java b/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java
index d0b4b045b2..4f7aada295 100644
--- a/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java
+++ b/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java
@@ -34,10 +34,10 @@ public class AnnotationEntry implements Node {
public static final AnnotationEntry[] EMPTY_ARRAY = {};
- public static AnnotationEntry[] createAnnotationEntries(final Attribute[] attrs) {
+ public static AnnotationEntry[] createAnnotationEntries(final Attribute[] attributes) {
// Find attributes that contain annotation data
- return Streams.of(attrs).filter(Annotations.class::isInstance).flatMap(e -> Stream.of(((Annotations) e).getAnnotationEntries()))
- .toArray(AnnotationEntry[]::new);
+ return Streams.of(attributes).filter(Annotations.class::isInstance).flatMap(e -> Stream.of(((Annotations) e).getAnnotationEntries()))
+ .toArray(AnnotationEntry[]::new);
}
/**
From 2586ee0b0b689fd323bf677256d931c025630826 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 11:02:33 -0400
Subject: [PATCH 107/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.Annotations.setAnnotationTable(AnnotationEntry[])
---
src/changes/changes.xml | 1 +
.../java/org/apache/bcel/classfile/Annotations.java | 10 ++--------
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1bf0a6d0be..4fe51edeca 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -82,6 +82,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setAttributes(Attribute[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.ConstantPool.setConstantPool(Constant[]).
Avoid NullPointerException after calling org.apache.bcel.classfile.FieldOrMethod.setAttributes(Attribute[]).
+ Avoid NullPointerException after calling org.apache.bcel.classfile.Annotations.setAnnotationTable(AnnotationEntry[]).
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/Annotations.java b/src/main/java/org/apache/bcel/classfile/Annotations.java
index 6ca224a93b..fab5d61247 100644
--- a/src/main/java/org/apache/bcel/classfile/Annotations.java
+++ b/src/main/java/org/apache/bcel/classfile/Annotations.java
@@ -47,7 +47,7 @@ public abstract class Annotations extends Attribute implements Iterable iterator() {
* @param annotationTable the entries to set in this annotation
*/
public final void setAnnotationTable(final AnnotationEntry[] annotationTable) {
- this.annotationTable = annotationTable;
+ this.annotationTable = annotationTable != null ? annotationTable : AnnotationEntry.EMPTY_ARRAY;
}
/**
@@ -146,9 +143,6 @@ public final String toString() {
}
protected void writeAnnotations(final DataOutputStream dos) throws IOException {
- if (annotationTable == null) {
- return;
- }
dos.writeShort(annotationTable.length);
for (final AnnotationEntry element : annotationTable) {
element.dump(dos);
From b467e8d980dd8d95343834426802484a9298e58c Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 11:05:31 -0400
Subject: [PATCH 108/147] Avoid NullPointerException after
callingorg.apache.bcel.classfile.ArrayElementValue.ArrayElementValue(int,
ElementValue[], ConstantPool) with null
---
src/changes/changes.xml | 19 ++++++++++---------
.../bcel/classfile/ArrayElementValue.java | 2 +-
.../apache/bcel/classfile/ElementValue.java | 1 +
3 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4fe51edeca..689263320f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -74,15 +74,16 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.ParameterAnnotations.setParameterAnnotationTable(ParameterAnnotationEntry[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.LocalVariableTypeTable.setLocalVariableTable(LocalVariable[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.LocalVariableTable.setLocalVariableTable(LocalVariable[]) with null.
- Avoid NullPointerException after calling org.apache.bcel.classfile.LineNumberTable.setLineNumberTable(LineNumber[]).
- Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setMethods(Method[]).
- Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setInterfaces(int[]).
- Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setInterfaceNames(String[]).
- Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setFields(Field[]).
- Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setAttributes(Attribute[]).
- Avoid NullPointerException after calling org.apache.bcel.classfile.ConstantPool.setConstantPool(Constant[]).
- Avoid NullPointerException after calling org.apache.bcel.classfile.FieldOrMethod.setAttributes(Attribute[]).
- Avoid NullPointerException after calling org.apache.bcel.classfile.Annotations.setAnnotationTable(AnnotationEntry[]).
+ Avoid NullPointerException after calling org.apache.bcel.classfile.LineNumberTable.setLineNumberTable(LineNumber[]) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setMethods(Method[] with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setInterfaces(int[]) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setInterfaceNames(String[]) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setFields(Field[]) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setAttributes(Attribute[]) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.ConstantPool.setConstantPool(Constant[]) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.FieldOrMethod.setAttributes(Attribute[]) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.Annotations.setAnnotationTable(AnnotationEntry[]) with null.
+ Avoid NullPointerException after callingorg.apache.bcel.classfile.ArrayElementValue.ArrayElementValue(int, ElementValue[], ConstantPool) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/ArrayElementValue.java b/src/main/java/org/apache/bcel/classfile/ArrayElementValue.java
index 00fdc7af3e..d932b112e2 100644
--- a/src/main/java/org/apache/bcel/classfile/ArrayElementValue.java
+++ b/src/main/java/org/apache/bcel/classfile/ArrayElementValue.java
@@ -31,7 +31,7 @@ public ArrayElementValue(final int type, final ElementValue[] elementValues, fin
if (type != ARRAY) {
throw new ClassFormatException("Only element values of type array can be built with this ctor - type specified: " + type);
}
- this.elementValues = elementValues;
+ this.elementValues = elementValues != null ? elementValues : ElementValue.EMPTY_ARRAY;
}
@Override
diff --git a/src/main/java/org/apache/bcel/classfile/ElementValue.java b/src/main/java/org/apache/bcel/classfile/ElementValue.java
index 7bcd73bda0..5619f48623 100644
--- a/src/main/java/org/apache/bcel/classfile/ElementValue.java
+++ b/src/main/java/org/apache/bcel/classfile/ElementValue.java
@@ -63,6 +63,7 @@ public abstract class ElementValue {
public static final byte PRIMITIVE_LONG = 'J';
public static final byte PRIMITIVE_SHORT = 'S';
public static final byte PRIMITIVE_BOOLEAN = 'Z';
+ static final ElementValue[] EMPTY_ARRAY = {};
/**
* Reads an {@code element_value} as an {@code ElementValue}.
From 5b975983d329cfff727f550e4beadf3a854d8902 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 11:08:21 -0400
Subject: [PATCH 109/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.BootstrapMethod.BootstrapMethod(int, int[]) with
null
Avoid NullPointerException after calling
org.apache.bcel.classfile.BootstrapMethod.setBootstrapArguments(int[])
with null.
---
src/changes/changes.xml | 4 +++-
src/main/java/org/apache/bcel/classfile/BootstrapMethod.java | 5 +++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 689263320f..98fbda75dd 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -83,7 +83,9 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.ConstantPool.setConstantPool(Constant[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.FieldOrMethod.setAttributes(Attribute[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.Annotations.setAnnotationTable(AnnotationEntry[]) with null.
- Avoid NullPointerException after callingorg.apache.bcel.classfile.ArrayElementValue.ArrayElementValue(int, ElementValue[], ConstantPool) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.ArrayElementValue.ArrayElementValue(int, ElementValue[], ConstantPool) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.BootstrapMethod.BootstrapMethod(int, int[]) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.BootstrapMethod.setBootstrapArguments(int[]) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java b/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java
index 5f2ec3dc6c..ad88aa1ec0 100644
--- a/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java
+++ b/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java
@@ -23,6 +23,7 @@
import java.util.Arrays;
import org.apache.bcel.Const;
+import org.apache.commons.lang3.ArrayUtils;
/**
* This class represents a bootstrap method attribute, i.e., the bootstrap method ref, the number of bootstrap arguments
@@ -74,7 +75,7 @@ private BootstrapMethod(final int bootstrapMethodRef, final int numBootstrapArgu
*/
public BootstrapMethod(final int bootstrapMethodRef, final int[] bootstrapArguments) {
this.bootstrapMethodRef = bootstrapMethodRef;
- this.bootstrapArguments = bootstrapArguments;
+ setBootstrapArguments(bootstrapArguments);
}
/**
@@ -128,7 +129,7 @@ public int getNumBootstrapArguments() {
* @param bootstrapArguments int[] indices into constant_pool of CONSTANT_[type]_info
*/
public void setBootstrapArguments(final int[] bootstrapArguments) {
- this.bootstrapArguments = bootstrapArguments;
+ this.bootstrapArguments = ArrayUtils.nullToEmpty(bootstrapArguments);
}
/**
From dc9b61b30fc364b4f610a8a5469ff65fe2000536 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 11:11:02 -0400
Subject: [PATCH 110/147] Avoid NullPointerException after calling
org.apache.bcel.classfile.BootstrapMethods.BootstrapMethods(int, int,
BootstrapMethod[], ConstantPool) with null
Avoid NullPointerException after calling
org.apache.bcel.classfile.BootstrapMethods.setBootstrapMethods(BootstrapMethod[])
with null.
---
src/changes/changes.xml | 2 ++
src/main/java/org/apache/bcel/classfile/BootstrapMethod.java | 2 ++
src/main/java/org/apache/bcel/classfile/BootstrapMethods.java | 4 ++--
3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 98fbda75dd..0df97860c1 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -86,6 +86,8 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.ArrayElementValue.ArrayElementValue(int, ElementValue[], ConstantPool) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.BootstrapMethod.BootstrapMethod(int, int[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.BootstrapMethod.setBootstrapArguments(int[]) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.BootstrapMethods.BootstrapMethods(int, int, BootstrapMethod[], ConstantPool) with null.
+ Avoid NullPointerException after calling org.apache.bcel.classfile.BootstrapMethods.setBootstrapMethods(BootstrapMethod[]) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java b/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java
index ad88aa1ec0..ff4b93b01a 100644
--- a/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java
+++ b/src/main/java/org/apache/bcel/classfile/BootstrapMethod.java
@@ -35,6 +35,8 @@
*/
public class BootstrapMethod implements Cloneable {
+ static final BootstrapMethod[] EMPTY_ARRAY = {};
+
/** Index of the CONSTANT_MethodHandle_info structure in the constant_pool table */
private int bootstrapMethodRef;
diff --git a/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java b/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java
index d44a1afad3..42af84eeac 100644
--- a/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java
+++ b/src/main/java/org/apache/bcel/classfile/BootstrapMethods.java
@@ -54,7 +54,7 @@ public BootstrapMethods(final BootstrapMethods c) {
*/
public BootstrapMethods(final int nameIndex, final int length, final BootstrapMethod[] bootstrapMethods, final ConstantPool constantPool) {
super(Const.ATTR_BOOTSTRAP_METHODS, nameIndex, length, constantPool);
- this.bootstrapMethods = bootstrapMethods;
+ setBootstrapMethods(bootstrapMethods);
}
/**
@@ -131,7 +131,7 @@ public Iterator iterator() {
* @param bootstrapMethods the array of bootstrap methods
*/
public final void setBootstrapMethods(final BootstrapMethod[] bootstrapMethods) {
- this.bootstrapMethods = bootstrapMethods;
+ this.bootstrapMethods = bootstrapMethods != null ? bootstrapMethods : BootstrapMethod.EMPTY_ARRAY;
}
/**
From e40de4552914c260da61ce80dc5a89c83325357c Mon Sep 17 00:00:00 2001
From: Heewon Lee <94441510+pingpingy1@users.noreply.github.com>
Date: Tue, 2 Apr 2024 00:14:53 +0900
Subject: [PATCH 111/147] Add null guard for InstructionFactor.createInvoke
(#289)
In the current implementation of the `createInvoke` method, an NPE
is thrown if the `argTypes` array is `null`. This commit adds a null
guard that skips the for loop if this is the case.
---
.../java/org/apache/bcel/generic/InstructionFactory.java | 6 ++++--
.../org/apache/bcel/generic/InstructionFactoryTestCase.java | 6 ++++++
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/generic/InstructionFactory.java b/src/main/java/org/apache/bcel/generic/InstructionFactory.java
index 2f1f91323b..90c82cfdcd 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionFactory.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionFactory.java
@@ -640,8 +640,10 @@ public InvokeInstruction createInvoke(final String className, final String name,
int index;
int nargs = 0;
final String signature = Type.getMethodSignature(retType, argTypes);
- for (final Type argType : argTypes) {
- nargs += argType.getSize();
+ if (argTypes != null) {
+ for (final Type argType : argTypes) {
+ nargs += argType.getSize();
+ }
}
if (useInterface) {
index = cp.addInterfaceMethodref(className, name, signature);
diff --git a/src/test/java/org/apache/bcel/generic/InstructionFactoryTestCase.java b/src/test/java/org/apache/bcel/generic/InstructionFactoryTestCase.java
index 84782d6743..073238f214 100644
--- a/src/test/java/org/apache/bcel/generic/InstructionFactoryTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/InstructionFactoryTestCase.java
@@ -97,4 +97,10 @@ public void testNull() throws Exception {
assertEquals(InstructionConst.ACONST_NULL, createNull(Type.OBJECT));
assertEquals(InstructionConst.ACONST_NULL, createNull(Type.getType("[I")));
}
+
+ @Test
+ public void testCreateInvokeNullArgTypes() throws Exception {
+ InstructionFactory factory = new InstructionFactory(new ClassGen(Repository.lookupClass(Object.class)));
+ factory.createInvoke("", "", Type.VOID, null, Const.INVOKESPECIAL, false); // Mustn't throw an NPE
+ }
}
From fb85ced57db2a9d28b29883b267a6dc3023b8299 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 11:16:42 -0400
Subject: [PATCH 112/147] Add null guard for InstructionFactory.createInvoke()
#289
---
src/changes/changes.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0df97860c1..e6541f7404 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -60,6 +60,7 @@ The type attribute can be add,update,fix,remove.
-->
+ Add null guard for InstructionFactory.createInvoke() #289.
Avoid possible NullPointerException in org.apache.bcel.classfile.DescendingVisitor.accept(E[]).
Avoid possible NullPointerException in AnnotationEntryGen.getAnnotationAttributes(ConstantPoolGen, AnnotationEntryGen[]).
Avoid possible NullPointerException in AnnotationEntryGen.copyValues(ElementValuePair[], ConstantPoolGen, boolean).
From 511a7787d4298082872ef1b36995f7247d0fea4d Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 11:21:26 -0400
Subject: [PATCH 113/147] Avoid NullPointerException calling
org.apache.bcel.generic.InstructionList.redirectLocalVariables(LocalVariableGen[],
InstructionHandle, InstructionHandle) with null
---
src/changes/changes.xml | 1 +
.../java/org/apache/bcel/generic/InstructionList.java | 11 +++++------
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index e6541f7404..bbf421d3b9 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -89,6 +89,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.BootstrapMethod.setBootstrapArguments(int[]) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.BootstrapMethods.BootstrapMethods(int, int, BootstrapMethod[], ConstantPool) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.BootstrapMethods.setBootstrapMethods(BootstrapMethod[]) with null.
+ Avoid NullPointerException calling org.apache.bcel.generic.InstructionList.redirectLocalVariables(LocalVariableGen[], InstructionHandle, InstructionHandle) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/InstructionList.java b/src/main/java/org/apache/bcel/generic/InstructionList.java
index ca053e4418..2f8c11aa6a 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionList.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionList.java
@@ -31,6 +31,7 @@
import org.apache.bcel.classfile.Constant;
import org.apache.bcel.util.ByteSequence;
import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.stream.Streams;
/**
* This class is a container for a list of Instruction objects. Instructions can be
@@ -978,16 +979,14 @@ public void redirectExceptionHandlers(final CodeExceptionGen[] exceptions, final
* @see MethodGen
*/
public void redirectLocalVariables(final LocalVariableGen[] lg, final InstructionHandle oldTarget, final InstructionHandle newTarget) {
- for (final LocalVariableGen element : lg) {
- final InstructionHandle start = element.getStart();
- final InstructionHandle end = element.getEnd();
- if (start == oldTarget) {
+ Streams.of(lg).forEach(element -> {
+ if (element.getStart() == oldTarget) {
element.setStart(newTarget);
}
- if (end == oldTarget) {
+ if (element.getEnd() == oldTarget) {
element.setEnd(newTarget);
}
- }
+ });
}
/**
From 95552fea8528697b0679f2b0a03e4426304f580d Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 11:22:43 -0400
Subject: [PATCH 114/147] Avoid NullPointerException calling
org.apache.bcel.generic.InstructionList.redirectExceptionHandlers(CodeExceptionGen[],
InstructionHandle, InstructionHandle) with null
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/generic/InstructionList.java | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index bbf421d3b9..1ee1e74f30 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -90,6 +90,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.BootstrapMethods.BootstrapMethods(int, int, BootstrapMethod[], ConstantPool) with null.
Avoid NullPointerException after calling org.apache.bcel.classfile.BootstrapMethods.setBootstrapMethods(BootstrapMethod[]) with null.
Avoid NullPointerException calling org.apache.bcel.generic.InstructionList.redirectLocalVariables(LocalVariableGen[], InstructionHandle, InstructionHandle) with null.
+ Avoid NullPointerException calling org.apache.bcel.generic.InstructionList.redirectExceptionHandlers(CodeExceptionGen[], InstructionHandle, InstructionHandle) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/InstructionList.java b/src/main/java/org/apache/bcel/generic/InstructionList.java
index 2f8c11aa6a..c840a7e71e 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionList.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionList.java
@@ -957,7 +957,7 @@ public void redirectBranches(final InstructionHandle oldTarget, final Instructio
* @see MethodGen
*/
public void redirectExceptionHandlers(final CodeExceptionGen[] exceptions, final InstructionHandle oldTarget, final InstructionHandle newTarget) {
- for (final CodeExceptionGen exception : exceptions) {
+ Streams.of(exceptions).forEach(exception -> {
if (exception.getStartPC() == oldTarget) {
exception.setStartPC(newTarget);
}
@@ -967,7 +967,7 @@ public void redirectExceptionHandlers(final CodeExceptionGen[] exceptions, final
if (exception.getHandlerPC() == oldTarget) {
exception.setHandlerPC(newTarget);
}
- }
+ });
}
/**
From ca1add6d481319fb80ac2930c8500484b2e000e3 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 11:24:05 -0400
Subject: [PATCH 115/147] Avoid NullPointerException calling
org.apache.bcel.generic.InstructionList.findHandle(InstructionHandle[],
int[], int, int) with null
---
src/changes/changes.xml | 1 +
.../apache/bcel/generic/InstructionList.java | 36 ++++++++++---------
2 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1ee1e74f30..4d0d81a0dd 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -91,6 +91,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException after calling org.apache.bcel.classfile.BootstrapMethods.setBootstrapMethods(BootstrapMethod[]) with null.
Avoid NullPointerException calling org.apache.bcel.generic.InstructionList.redirectLocalVariables(LocalVariableGen[], InstructionHandle, InstructionHandle) with null.
Avoid NullPointerException calling org.apache.bcel.generic.InstructionList.redirectExceptionHandlers(CodeExceptionGen[], InstructionHandle, InstructionHandle) with null.
+ Avoid NullPointerException calling org.apache.bcel.generic.InstructionList.findHandle(InstructionHandle[], int[], int, int) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/InstructionList.java b/src/main/java/org/apache/bcel/generic/InstructionList.java
index c840a7e71e..0f4340b70f 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionList.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionList.java
@@ -58,23 +58,25 @@ public class InstructionList implements Iterable {
* @return target position's instruction handle if available
*/
public static InstructionHandle findHandle(final InstructionHandle[] ihs, final int[] pos, final int count, final int target) {
- int l = 0;
- int r = count - 1;
- /*
- * Do a binary search since the pos array is orderd.
- */
- do {
- final int i = l + r >>> 1;
- final int j = pos[i];
- if (j == target) {
- return ihs[i];
- }
- if (target < j) {
- r = i - 1;
- } else {
- l = i + 1;
- }
- } while (l <= r);
+ if (ihs != null && pos != null) {
+ int l = 0;
+ int r = count - 1;
+ /*
+ * Do a binary search since the pos array is orderd.
+ */
+ do {
+ final int i = l + r >>> 1;
+ final int j = pos[i];
+ if (j == target) {
+ return ihs[i];
+ }
+ if (target < j) {
+ r = i - 1;
+ } else {
+ l = i + 1;
+ }
+ } while (l <= r);
+ }
return null;
}
From 87eac0ab55adfdb043017016d73ff101747093c5 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 11:25:11 -0400
Subject: [PATCH 116/147] Fix typo in comment
---
src/main/java/org/apache/bcel/generic/Select.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/bcel/generic/Select.java b/src/main/java/org/apache/bcel/generic/Select.java
index ce1efc3b48..b08e5596b1 100644
--- a/src/main/java/org/apache/bcel/generic/Select.java
+++ b/src/main/java/org/apache/bcel/generic/Select.java
@@ -83,7 +83,7 @@ public abstract class Select extends BranchInstruction implements VariableLength
* @param defaultTarget default instruction target
*/
Select(final short opcode, final int[] match, final InstructionHandle[] targets, final InstructionHandle defaultTarget) {
- // don't set default target before instuction is built
+ // don't set default target before instruction is built
super(opcode, null);
this.match = match;
this.targets = targets;
From 0aebd69e9fa517a044c491d23fcf2bc22bbe5d09 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 11:28:46 -0400
Subject: [PATCH 117/147] Avoid NullPointerException calling
org.apache.bcel.generic.MethodGen.setArgumentTypes(Type[]) with null
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/generic/MethodGen.java | 8 +++-----
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4d0d81a0dd..7004873ede 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -92,6 +92,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException calling org.apache.bcel.generic.InstructionList.redirectLocalVariables(LocalVariableGen[], InstructionHandle, InstructionHandle) with null.
Avoid NullPointerException calling org.apache.bcel.generic.InstructionList.redirectExceptionHandlers(CodeExceptionGen[], InstructionHandle, InstructionHandle) with null.
Avoid NullPointerException calling org.apache.bcel.generic.InstructionList.findHandle(InstructionHandle[], int[], int, int) with null.
+ Avoid NullPointerException calling org.apache.bcel.generic.MethodGen.setArgumentTypes(Type[]) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/MethodGen.java b/src/main/java/org/apache/bcel/generic/MethodGen.java
index 1cccda44a9..37e216791a 100644
--- a/src/main/java/org/apache/bcel/generic/MethodGen.java
+++ b/src/main/java/org/apache/bcel/generic/MethodGen.java
@@ -1042,7 +1042,7 @@ public void setArgumentType(final int i, final Type type) {
}
public void setArgumentTypes(final Type[] argTypes) {
- this.argTypes = argTypes;
+ this.argTypes = argTypes != null ? argTypes : Type.NO_ARGS;
}
public void setClassName(final String className) { // TODO could be package-protected?
@@ -1059,10 +1059,8 @@ public void setInstructionList(final InstructionList il) { // TODO could be pack
public void setMaxLocals() { // TODO could be package-protected? (some tests would need repackaging)
if (il != null) {
int max = isStatic() ? 0 : 1;
- if (argTypes != null) {
- for (final Type argType : argTypes) {
- max += argType.getSize();
- }
+ for (final Type argType : argTypes) {
+ max += argType.getSize();
}
for (InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) {
final Instruction ins = ih.getInstruction();
From c032ef5d7db20640d8cd4847df4d46081842f338 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 11:30:20 -0400
Subject: [PATCH 118/147] Avoid NullPointerException calling
org.apache.bcel.generic.MethodGen.setArgumentNames(String[]) with null
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/generic/MethodGen.java | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 7004873ede..2897042143 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -93,6 +93,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException calling org.apache.bcel.generic.InstructionList.redirectExceptionHandlers(CodeExceptionGen[], InstructionHandle, InstructionHandle) with null.
Avoid NullPointerException calling org.apache.bcel.generic.InstructionList.findHandle(InstructionHandle[], int[], int, int) with null.
Avoid NullPointerException calling org.apache.bcel.generic.MethodGen.setArgumentTypes(Type[]) with null.
+ Avoid NullPointerException calling org.apache.bcel.generic.MethodGen.setArgumentNames(String[]) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/MethodGen.java b/src/main/java/org/apache/bcel/generic/MethodGen.java
index 37e216791a..b93400f854 100644
--- a/src/main/java/org/apache/bcel/generic/MethodGen.java
+++ b/src/main/java/org/apache/bcel/generic/MethodGen.java
@@ -1034,7 +1034,7 @@ public void setArgumentName(final int i, final String name) {
}
public void setArgumentNames(final String[] argNames) {
- this.argNames = argNames;
+ this.argNames = ArrayUtils.nullToEmpty(argNames);
}
public void setArgumentType(final int i, final Type type) {
From 0e4e0d69df4cfc062e18891953bee085c9f79dfa Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 11:31:52 -0400
Subject: [PATCH 119/147] Avoid NullPointerException calling
org.apache.bcel.generic.MethodGen.removeRuntimeAttributes(Attribute[]) with
null
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/generic/MethodGen.java | 7 +++----
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 2897042143..c4d1f37989 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -94,6 +94,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException calling org.apache.bcel.generic.InstructionList.findHandle(InstructionHandle[], int[], int, int) with null.
Avoid NullPointerException calling org.apache.bcel.generic.MethodGen.setArgumentTypes(Type[]) with null.
Avoid NullPointerException calling org.apache.bcel.generic.MethodGen.setArgumentNames(String[]) with null.
+ Avoid NullPointerException calling org.apache.bcel.generic.MethodGen.removeRuntimeAttributes(Attribute[]) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/MethodGen.java b/src/main/java/org/apache/bcel/generic/MethodGen.java
index b93400f854..9167a15fdb 100644
--- a/src/main/java/org/apache/bcel/generic/MethodGen.java
+++ b/src/main/java/org/apache/bcel/generic/MethodGen.java
@@ -44,6 +44,7 @@
import org.apache.bcel.classfile.Utility;
import org.apache.bcel.util.BCELComparator;
import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.stream.Streams;
/**
* Template class for building up a method. This is done by defining exception handlers, adding thrown exceptions, local
@@ -1023,10 +1024,8 @@ public void removeObserver(final MethodObserver o) {
*
* @since 6.5.0
*/
- public void removeRuntimeAttributes(final Attribute[] attrs) {
- for (final Attribute attr : attrs) {
- removeAttribute(attr);
- }
+ public void removeRuntimeAttributes(final Attribute[] attributes) {
+ Streams.of(attributes).forEach(this::removeAttribute);
}
public void setArgumentName(final int i, final String name) {
From 1dbef18b2f548174b439a72febf5de78399856ee Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 11:35:07 -0400
Subject: [PATCH 120/147] Avoid NullPointerException calling
org.apache.bcel.generic.MethodGen.makeMutableVersion(AnnotationEntry[]) with
null
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/generic/MethodGen.java | 7 ++-----
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c4d1f37989..0325b7395e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -95,6 +95,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException calling org.apache.bcel.generic.MethodGen.setArgumentTypes(Type[]) with null.
Avoid NullPointerException calling org.apache.bcel.generic.MethodGen.setArgumentNames(String[]) with null.
Avoid NullPointerException calling org.apache.bcel.generic.MethodGen.removeRuntimeAttributes(Attribute[]) with null.
+ Avoid NullPointerException calling org.apache.bcel.generic.MethodGen.makeMutableVersion(AnnotationEntry[]) with null.
Bump org.apache.commons:commons-parent from 66 to 67 #283.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
diff --git a/src/main/java/org/apache/bcel/generic/MethodGen.java b/src/main/java/org/apache/bcel/generic/MethodGen.java
index 9167a15fdb..0f3cc8c95a 100644
--- a/src/main/java/org/apache/bcel/generic/MethodGen.java
+++ b/src/main/java/org/apache/bcel/generic/MethodGen.java
@@ -24,6 +24,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Stack;
+import java.util.stream.Collectors;
import org.apache.bcel.Const;
import org.apache.bcel.classfile.AnnotationEntry;
@@ -894,11 +895,7 @@ public int hashCode() {
}
private List makeMutableVersion(final AnnotationEntry[] mutableArray) {
- final List result = new ArrayList<>();
- for (final AnnotationEntry element : mutableArray) {
- result.add(new AnnotationEntryGen(element, getConstantPool(), false));
- }
- return result;
+ return Streams.of(mutableArray).map(ae -> new AnnotationEntryGen(ae, getConstantPool(), false)).collect(Collectors.toList());
}
/**
From 2308a513a3fc581c64104faec99ab2c255a1ae4c Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 1 Apr 2024 13:54:44 -0400
Subject: [PATCH 121/147] Bump org.apache.commons:commons-parent from 67 to 69
(#297)
Bumps [org.apache.commons:commons-parent](https://github.com/apache/commons-parent) from 67 to 69.
- [Changelog](https://github.com/apache/commons-parent/blob/master/RELEASE-NOTES.txt)
- [Commits](https://github.com/apache/commons-parent/commits)
---
updated-dependencies:
- dependency-name: org.apache.commons:commons-parent
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c7f06ea184..d7fb4280e2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@
org.apache.commons
commons-parent
- 67
+ 69
org.apache.bcel
From 2a91c5d97b103ca742b5bc48bd3e556459c96d81 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 1 Apr 2024 13:55:30 -0400
Subject: [PATCH 122/147] Bump org.apache.commons:commons-parent from 67 to 69
#297
---
src/changes/changes.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0325b7395e..afe25d4b8f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -97,7 +97,7 @@ The type attribute can be add,update,fix,remove.
Avoid NullPointerException calling org.apache.bcel.generic.MethodGen.removeRuntimeAttributes(Attribute[]) with null.
Avoid NullPointerException calling org.apache.bcel.generic.MethodGen.makeMutableVersion(AnnotationEntry[]) with null.
- Bump org.apache.commons:commons-parent from 66 to 67 #283.
+ Bump org.apache.commons:commons-parent from 66 to 69 #283, #297.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
Bump commons-io:commons-io from 2.15.1 to 2.16.0 #295.
From 31227a3094beb28edafb4d86a639954ecae06aa7 Mon Sep 17 00:00:00 2001
From: "Gary David Gregory (Code signing key)"
Date: Wed, 3 Apr 2024 11:00:59 -0400
Subject: [PATCH 123/147] Reuse ArrayFill
---
src/main/java/org/apache/bcel/classfile/Utility.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/Utility.java b/src/main/java/org/apache/bcel/classfile/Utility.java
index a860906872..76fc8932ab 100644
--- a/src/main/java/org/apache/bcel/classfile/Utility.java
+++ b/src/main/java/org/apache/bcel/classfile/Utility.java
@@ -37,6 +37,7 @@
import org.apache.bcel.Const;
import org.apache.bcel.util.ByteSequence;
+import org.apache.commons.lang3.ArrayFill;
import org.apache.commons.lang3.ArrayUtils;
/**
@@ -715,8 +716,7 @@ public static String encode(byte[] bytes, final boolean compress) throws IOExcep
*/
public static String fillup(final String str, final int length, final boolean leftJustify, final char fill) {
final int len = length - str.length();
- final char[] buf = new char[Math.max(len, 0)];
- Arrays.fill(buf, fill);
+ final char[] buf = ArrayFill.fill(new char[Math.max(len, 0)], fill);
if (leftJustify) {
return str + new String(buf);
}
From 10c4fed28828d8d67adb2d278ad5597a342767b4 Mon Sep 17 00:00:00 2001
From: "Gary David Gregory (Code signing key)"
Date: Wed, 3 Apr 2024 11:01:11 -0400
Subject: [PATCH 124/147] Reuse ArrayFill
---
.../org/apache/bcel/verifier/structurals/LocalVariables.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java b/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java
index 9f9c887fb9..2024c2cc7d 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java
@@ -22,6 +22,7 @@
import org.apache.bcel.generic.Type;
import org.apache.bcel.verifier.exc.AssertionViolatedException;
import org.apache.bcel.verifier.exc.StructuralCodeConstraintException;
+import org.apache.commons.lang3.ArrayFill;
/**
* This class implements an array of local variables used for symbolic JVM simulation.
@@ -37,8 +38,7 @@ public class LocalVariables implements Cloneable {
* @param localVariableCount local variable count.
*/
public LocalVariables(final int localVariableCount) {
- locals = new Type[localVariableCount];
- Arrays.fill(locals, Type.UNKNOWN);
+ locals = ArrayFill.fill(new Type[localVariableCount], Type.UNKNOWN);
}
/**
From abeaef0a409470b907ec4892408e34350c02d573 Mon Sep 17 00:00:00 2001
From: "Gary David Gregory (Code signing key)"
Date: Wed, 3 Apr 2024 11:13:03 -0400
Subject: [PATCH 125/147] Remove unused import
---
.../org/apache/bcel/verifier/structurals/LocalVariables.java | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java b/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java
index 2024c2cc7d..1b27bb6769 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java
@@ -16,8 +16,6 @@
*/
package org.apache.bcel.verifier.structurals;
-import java.util.Arrays;
-
import org.apache.bcel.generic.ReferenceType;
import org.apache.bcel.generic.Type;
import org.apache.bcel.verifier.exc.AssertionViolatedException;
From 97f2bec8c46e99aa6e29b636fd414f23320f4a9f Mon Sep 17 00:00:00 2001
From: Pablo Nicolas Diaz
Date: Thu, 4 Apr 2024 09:05:43 -0300
Subject: [PATCH 126/147] Support for Java 16 Record feature (#290)
* Support for java 17 Record feature
* Fix whitespace
* Fix whitespace
* Fix whitespace
* More whitespace fixing
* Fix whitespace
* Add Javadoc since tag
* Fix Javadoc since tag
* Remove trailing whitespace
* Remove trailing whitespace
* Remove trailing whitespace
* Remove trailing whitespace
* Remove trailing whitespace
* added a missing new line
* visitRecordComponent declared as a default method and documented.
* removed visitRecordComponent, as is unneeded from previous commit
* fixed version reference
* fixed comments
* javadoc added
* fixed checkstyle errors
* fixed checkstyle and pmd errors
* fixed variable names and comments
* adding tests to cover new functionality
* fixed checkstyle and pmd errors
* added new test cases
* fixing javadoc and comments from pr
* Order Javadoc tags
* Javadoc
* Javadoc
* Javadoc
* Javadoc
* Javadoc
* Fix whitespace
* fixed typo
* solved pr comments
* constant pool check added
* visitor fixed
---------
Co-authored-by: nicolas
Co-authored-by: Gary Gregory
---
src/main/java/org/apache/bcel/Const.java | 5 +-
.../org/apache/bcel/classfile/Attribute.java | 2 +
.../bcel/classfile/DescendingVisitor.java | 16 ++
.../org/apache/bcel/classfile/JavaClass.java | 26 +++
.../org/apache/bcel/classfile/Record.java | 149 ++++++++++++++++++
.../bcel/classfile/RecordComponentInfo.java | 135 ++++++++++++++++
.../org/apache/bcel/classfile/Visitor.java | 23 +++
.../statics/StringRepresentation.java | 13 ++
.../apache/bcel/CounterVisitorTestCase.java | 5 +
.../apache/bcel/classfile/RecordTestCase.java | 121 ++++++++++++++
.../apache/bcel/visitors/CountingVisitor.java | 19 +++
src/test/resources/record/SimpleRecord.class | Bin 0 -> 1506 bytes
src/test/resources/record/SimpleRecord.java | 5 +
13 files changed, 517 insertions(+), 2 deletions(-)
create mode 100644 src/main/java/org/apache/bcel/classfile/Record.java
create mode 100644 src/main/java/org/apache/bcel/classfile/RecordComponentInfo.java
create mode 100644 src/test/java/org/apache/bcel/classfile/RecordTestCase.java
create mode 100644 src/test/resources/record/SimpleRecord.class
create mode 100644 src/test/resources/record/SimpleRecord.java
diff --git a/src/main/java/org/apache/bcel/Const.java b/src/main/java/org/apache/bcel/Const.java
index edf739ae25..fd554493fd 100644
--- a/src/main/java/org/apache/bcel/Const.java
+++ b/src/main/java/org/apache/bcel/Const.java
@@ -3073,12 +3073,13 @@ public final class Const {
public static final byte ATTR_MODULE_MAIN_CLASS = 24;
public static final byte ATTR_NEST_HOST = 25;
public static final byte ATTR_NEST_MEMBERS = 26;
+ public static final byte ATTR_RECORD = 27;
- public static final short KNOWN_ATTRIBUTES = 27; // count of attributes
+ public static final short KNOWN_ATTRIBUTES = 28; // count of attributes
private static final String[] ATTRIBUTE_NAMES = {"SourceFile", "ConstantValue", "Code", "Exceptions", "LineNumberTable", "LocalVariableTable",
"InnerClasses", "Synthetic", "Deprecated", "PMGClass", "Signature", "StackMap", "RuntimeVisibleAnnotations", "RuntimeInvisibleAnnotations",
"RuntimeVisibleParameterAnnotations", "RuntimeInvisibleParameterAnnotations", "AnnotationDefault", "LocalVariableTypeTable", "EnclosingMethod",
- "StackMapTable", "BootstrapMethods", "MethodParameters", "Module", "ModulePackages", "ModuleMainClass", "NestHost", "NestMembers"};
+ "StackMapTable", "BootstrapMethods", "MethodParameters", "Module", "ModulePackages", "ModuleMainClass", "NestHost", "NestMembers", "Record"};
/**
* Constants used in the StackMap attribute.
*/
diff --git a/src/main/java/org/apache/bcel/classfile/Attribute.java b/src/main/java/org/apache/bcel/classfile/Attribute.java
index 42510a9a11..0dd994c24b 100644
--- a/src/main/java/org/apache/bcel/classfile/Attribute.java
+++ b/src/main/java/org/apache/bcel/classfile/Attribute.java
@@ -191,6 +191,8 @@ public static Attribute readAttribute(final DataInput dataInput, final ConstantP
return new NestHost(nameIndex, length, dataInput, constantPool);
case Const.ATTR_NEST_MEMBERS:
return new NestMembers(nameIndex, length, dataInput, constantPool);
+ case Const.ATTR_RECORD:
+ return new Record(nameIndex, length, dataInput, constantPool);
default:
// Never reached
throw new IllegalStateException("Unrecognized attribute type tag parsed: " + tag);
diff --git a/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java b/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
index 85de2a2a26..880f1009e6 100644
--- a/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
+++ b/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
@@ -560,4 +560,20 @@ public void visitUnknown(final Unknown attribute) {
attribute.accept(visitor);
stack.pop();
}
+
+ @Override
+ public void visitRecord(Record record) {
+ stack.push(record);
+ record.accept(visitor);
+ accept(record.getComponents());
+ stack.pop();
+ }
+
+ @Override
+ public void visitRecordComponent(RecordComponentInfo recordComponentInfo) {
+ stack.push(recordComponentInfo);
+ recordComponentInfo.accept(visitor);
+ stack.pop();
+ }
+
}
diff --git a/src/main/java/org/apache/bcel/classfile/JavaClass.java b/src/main/java/org/apache/bcel/classfile/JavaClass.java
index de4ac4b117..fe96798353 100644
--- a/src/main/java/org/apache/bcel/classfile/JavaClass.java
+++ b/src/main/java/org/apache/bcel/classfile/JavaClass.java
@@ -133,8 +133,10 @@ public static void setComparator(final BCELComparator comparator) {
private boolean isAnonymous;
private boolean isNested;
+ private boolean isRecord;
private boolean computedNestedTypeStatus;
+ private boolean computedRecord;
/**
* In cases where we go ahead and create something, use the default SyntheticRepository, because we don't know any
@@ -904,4 +906,28 @@ public String toString() {
}
return buf.toString();
}
+
+ /**
+ * Tests whether this class was declared as a record
+ *
+ * @return true if a record attribute is present, false otherwise.
+ * @since 6.9.0
+ */
+ public boolean isRecord() {
+ computeIsRecord();
+ return this.isRecord;
+ }
+
+ private void computeIsRecord() {
+ if (computedRecord) {
+ return;
+ }
+ for (final Attribute attribute : this.attributes) {
+ if (attribute instanceof Record) {
+ isRecord = true;
+ break;
+ }
+ }
+ this.computedRecord = true;
+ }
}
diff --git a/src/main/java/org/apache/bcel/classfile/Record.java b/src/main/java/org/apache/bcel/classfile/Record.java
new file mode 100644
index 0000000000..e459a0fe79
--- /dev/null
+++ b/src/main/java/org/apache/bcel/classfile/Record.java
@@ -0,0 +1,149 @@
+/*
+ * 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
+ *
+ * http://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 java.io.DataInput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.bcel.Const;
+import org.apache.bcel.util.Args;
+
+/**
+ * Extends {@link Attribute} and records the classes and
+ * interfaces that are authorized to claim membership in the nest hosted by the
+ * current class or interface. There may be at most one Record attribute in a
+ * ClassFile structure.
+ *
+ * @see Attribute
+ * @since 6.9.0
+ */
+public final class Record extends Attribute {
+
+ private static final RecordComponentInfo[] EMPTY_RCI_ARRAY = new RecordComponentInfo[] {};
+
+ private RecordComponentInfo[] components;
+
+ /**
+ * Constructs object from input stream.
+ *
+ * @param nameIndex Index in constant pool
+ * @param length Content length in bytes
+ * @param input Input stream
+ * @param constantPool Array of constants
+ * @throws IOException if an I/O error occurs.
+ */
+ Record(final int nameIndex, final int length, final DataInput input, final ConstantPool constantPool)
+ throws IOException {
+ this(nameIndex, length, readComponents(input, constantPool), constantPool);
+ }
+
+ private static RecordComponentInfo[] readComponents(final DataInput input, final ConstantPool constantPool)
+ throws IOException {
+ final int classCount = input.readUnsignedShort();
+ final RecordComponentInfo[] components = new RecordComponentInfo[classCount];
+ for (int i = 0; i < classCount; i++) {
+ components[i] = new RecordComponentInfo(input, constantPool);
+ }
+ return components;
+ }
+
+ /**
+ * Constructs a new instance using components.
+ *
+ * @param nameIndex Index in constant pool
+ * @param length Content length in bytes
+ * @param classes Array of Record Component Info elements
+ * @param constantPool Array of constants
+ */
+ public Record(final int nameIndex, final int length, final RecordComponentInfo[] classes,
+ final ConstantPool constantPool) {
+ super(Const.ATTR_RECORD, nameIndex, length, constantPool);
+ this.components = classes != null ? classes : EMPTY_RCI_ARRAY;
+ Args.requireU2(this.components.length, "attributes.length");
+ }
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitly
+ * defined by the contents of a Java class. For example, the hierarchy of methods,
+ * fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ @Override
+ public void accept(final Visitor v) {
+ v.visitRecord(this);
+ }
+
+ /**
+ * Copies this instance and its components.
+ *
+ * @return a deep copy of this instance and its components.
+ */
+ @Override
+ public Attribute copy(final ConstantPool constantPool) {
+ final Record c = (Record) clone();
+ if (components.length > 0) {
+ c.components = components.clone();
+ }
+ c.setConstantPool(constantPool);
+ return c;
+ }
+
+ /**
+ * Dumps this instance into a file stream in binary format.
+ *
+ * @param file output stream.
+ * @throws IOException if an I/O error occurs.
+ */
+ @Override
+ public void dump(final DataOutputStream file) throws IOException {
+ super.dump(file);
+ file.writeShort(components.length);
+ for (final RecordComponentInfo component : components) {
+ component.dump(file);
+ }
+ }
+
+ /**
+ * Gets all the record components.
+ *
+ * @return array of Record Component Info elements.
+ */
+ public RecordComponentInfo[] getComponents() {
+ return components;
+ }
+
+ /**
+ * Converts this instance to a String suitable for debugging.
+ *
+ * @return String a String suitable for debugging.
+ */
+ @Override
+ public String toString() {
+ final StringBuilder buf = new StringBuilder();
+ buf.append("Record(");
+ buf.append(components.length);
+ buf.append("):\n");
+ for (final RecordComponentInfo component : components) {
+ buf.append(" ").append(component.toString()).append("\n");
+ }
+ return buf.substring(0, buf.length() - 1); // remove the last newline
+ }
+
+}
diff --git a/src/main/java/org/apache/bcel/classfile/RecordComponentInfo.java b/src/main/java/org/apache/bcel/classfile/RecordComponentInfo.java
new file mode 100644
index 0000000000..bf489d0f42
--- /dev/null
+++ b/src/main/java/org/apache/bcel/classfile/RecordComponentInfo.java
@@ -0,0 +1,135 @@
+/*
+ * 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
+ *
+ * http://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 java.io.DataInput;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.bcel.Const;
+
+/**
+ * Record component info from a record. Instances from this class maps
+ * every component from a given record.
+ *
+ * @see
+ * The Java Virtual Machine Specification, Java SE 14 Edition, Records (preview)
+ * @since 6.9.0
+ */
+public class RecordComponentInfo implements Node {
+
+ private final int index;
+ private final int descriptorIndex;
+ private final Attribute[] attributes;
+ private final ConstantPool constantPool;
+
+ /**
+ * Constructs a new instance from an input stream.
+ *
+ * @param input Input stream
+ * @param constantPool Array of constants
+ * @throws IOException if an I/O error occurs.
+ */
+ public RecordComponentInfo(final DataInput input, ConstantPool constantPool) throws IOException {
+ this.index = input.readUnsignedShort();
+ this.descriptorIndex = input.readUnsignedShort();
+ final int attributesCount = input.readUnsignedShort();
+ this.attributes = new Attribute[attributesCount];
+ for (int j = 0; j < attributesCount; j++) {
+ attributes[j] = Attribute.readAttribute(input, constantPool);
+ }
+ this.constantPool = constantPool;
+ }
+
+ /**
+ * Dumps contents into a file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException if an I/O error occurs.
+ */
+ public void dump(DataOutputStream file) throws IOException {
+ file.writeShort(index);
+ file.writeShort(descriptorIndex);
+ file.writeShort(attributes.length);
+ for (final Attribute attribute : attributes) {
+ attribute.dump(file);
+ }
+ }
+
+ @Override
+ public void accept(Visitor v) {
+ v.visitRecordComponent(this);
+ }
+
+ /**
+ * Gets the name index.
+ *
+ * @return index in constant pool of this record component name.
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Gets the description index.
+ *
+ * @return index in constant pool of this record component descriptor.
+ */
+ public int getDescriptorIndex() {
+ return descriptorIndex;
+ }
+
+ /**
+ * Gets all attributes.
+ *
+ * @return all attributes.
+ */
+ public Attribute[] getAttributes() {
+ return attributes;
+ }
+
+ /**
+ * Gets the constant pool.
+ *
+ * @return Constant pool.
+ */
+ public ConstantPool getConstantPool() {
+ return constantPool;
+ }
+
+ /**
+ * Converts this instance to a String suitable for debugging.
+ *
+ * @return a String suitable for debugging.
+ */
+ @Override
+ public String toString() {
+ final StringBuilder buf = new StringBuilder();
+ buf.append("RecordComponentInfo(");
+ buf.append(constantPool.getConstantString(index, Const.CONSTANT_Utf8));
+ buf.append(",");
+ buf.append(constantPool.getConstantString(descriptorIndex, Const.CONSTANT_Utf8));
+ buf.append(",");
+ buf.append(attributes.length);
+ buf.append("):\n");
+ for (final Attribute attribute : attributes) {
+ buf.append(" ").append(attribute.toString()).append("\n");
+ }
+ return buf.substring(0, buf.length() - 1); // remove the last newline
+ }
+
+}
diff --git a/src/main/java/org/apache/bcel/classfile/Visitor.java b/src/main/java/org/apache/bcel/classfile/Visitor.java
index 4f4b5c2116..6f73932468 100644
--- a/src/main/java/org/apache/bcel/classfile/Visitor.java
+++ b/src/main/java/org/apache/bcel/classfile/Visitor.java
@@ -207,6 +207,17 @@ default void visitNestMembers(final NestMembers obj) {
// empty
}
+ /**
+ * Visits a {@link Record} object.
+ *
+ * @param obj Record to visit
+ * @since 6.9.0
+ */
+ default void visitRecord(final Record obj) {
+ // empty
+ }
+
+
/**
* @since 6.0
*/
@@ -227,6 +238,7 @@ default void visitNestMembers(final NestMembers obj) {
/**
* Visits a {@link StackMapType} object.
+ *
* @param obj object to visit
* @since 6.8.0
*/
@@ -237,4 +249,15 @@ default void visitStackMapType(final StackMapType obj) {
void visitSynthetic(Synthetic obj);
void visitUnknown(Unknown obj);
+
+ /**
+ * Visits a {@link RecordComponentInfo} object.
+ *
+ * @param record component to visit
+ * @since 6.9.0
+ */
+ default void visitRecordComponent(RecordComponentInfo record) {
+ // noop
+ }
+
}
diff --git a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
index a894174608..af12ed5a24 100644
--- a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
+++ b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
@@ -59,6 +59,8 @@
import org.apache.bcel.classfile.Node;
import org.apache.bcel.classfile.ParameterAnnotationEntry;
import org.apache.bcel.classfile.ParameterAnnotations;
+import org.apache.bcel.classfile.Record;
+import org.apache.bcel.classfile.RecordComponentInfo;
import org.apache.bcel.classfile.Signature;
import org.apache.bcel.classfile.SourceFile;
import org.apache.bcel.classfile.StackMap;
@@ -429,4 +431,15 @@ public void visitSynthetic(final Synthetic obj) {
public void visitUnknown(final Unknown obj) {
tostring = toString(obj);
}
+
+ @Override
+ public void visitRecord(Record obj) {
+ tostring = toString(obj);
+ }
+
+ @Override
+ public void visitRecordComponent(RecordComponentInfo obj) {
+ tostring = toString(obj);
+ }
+
}
diff --git a/src/test/java/org/apache/bcel/CounterVisitorTestCase.java b/src/test/java/org/apache/bcel/CounterVisitorTestCase.java
index d1fcfa5e35..224369ba3f 100644
--- a/src/test/java/org/apache/bcel/CounterVisitorTestCase.java
+++ b/src/test/java/org/apache/bcel/CounterVisitorTestCase.java
@@ -217,4 +217,9 @@ public void testSyntheticCount() {
public void testUnknownCount() {
assertEquals(0, getVisitor().unknownCount, "unknownCount");
}
+
+ @Test
+ public void testRecordCount() {
+ assertEquals(0, getVisitor().recordCount, "recordCount");
+ }
}
diff --git a/src/test/java/org/apache/bcel/classfile/RecordTestCase.java b/src/test/java/org/apache/bcel/classfile/RecordTestCase.java
new file mode 100644
index 0000000000..7a2e639d76
--- /dev/null
+++ b/src/test/java/org/apache/bcel/classfile/RecordTestCase.java
@@ -0,0 +1,121 @@
+/*
+ * 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
+ *
+ * http://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.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.File;
+import java.io.IOException;
+
+import org.apache.bcel.AbstractTestCase;
+import org.apache.bcel.util.SyntheticRepository;
+import org.apache.bcel.visitors.CountingVisitor;
+import org.junit.jupiter.api.Test;
+
+public class RecordTestCase extends AbstractTestCase {
+
+ /**
+ * A record type, once compiled, should result in a class file that is
+ * marked such that we can determine from the access flags
+ * (through BCEL) that it is in fact a record.
+ *
+ * @throws IOException
+ * @throws ClassFormatException
+ */
+ @Test
+ public void testRecordClassSaysItIs() throws ClassNotFoundException, ClassFormatException, IOException {
+ final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
+ assertTrue(clazz.isRecord(), "Expected SimpleRecord class to say it was a record - but it didn't !");
+ final JavaClass simpleClazz = getTestJavaClass(PACKAGE_BASE_NAME + ".data.SimpleClass");
+ assertFalse(simpleClazz.isRecord(), "Expected SimpleClass class to say it was not a record - but it didn't !");
+ }
+
+ /**
+ * A simple record with two simple fields, an integer and a String field, should
+ * show its content in its string representation.
+ *
+ * @throws ClassNotFoundException
+ * @throws ClassFormatException
+ * @throws IOException
+ */
+ @Test
+ public void testRecordToString() throws ClassNotFoundException, ClassFormatException, IOException {
+ final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
+ final Attribute[] attributes = clazz.getAttributes();
+ final Record recordAttribute = (Record) findAttribute("Record",clazz)[0];
+ assertEquals(4, attributes.length);
+ assertEquals("SourceFile: SimpleRecord.java", attributes[0].toString());
+ assertEquals("Record(2):\n"
+ + " RecordComponentInfo(aNumber,I,0):\n"
+ + " RecordComponentInfo(aString,Ljava/lang/String;,1):\n"
+ + " RuntimeVisibleAnnotations:\n"
+ + " @Ljavax/annotation/Nonnull;"
+ ,recordAttribute.toString());
+ final RecordComponentInfo firstComponent = recordAttribute.getComponents()[0];
+ assertEquals(5, firstComponent.getIndex());
+ assertEquals(6, firstComponent.getDescriptorIndex());
+ assertEquals(0, firstComponent.getAttributes().length);
+ assertEquals(recordAttribute.getConstantPool(),firstComponent.getConstantPool());
+ assertEquals("RecordComponentInfo(aNumber,I,0):", firstComponent.toString());
+ }
+
+
+ /**
+ * Check that we can save and load the attribute correctly.
+ */
+ @Test
+ public void testAttributeSerializtion() throws ClassNotFoundException, IOException {
+ final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
+ final File tfile = createTestdataFile("SimpleRecord.class");
+ final Record recordAttribute = (Record)findAttribute("Record",clazz)[0];
+ clazz.dump(tfile);
+ // Read in the new version and check it is OK
+ final SyntheticRepository repos2 = createRepos(".");
+ final JavaClass clazzFromRepo = repos2.loadClass("SimpleRecord");
+ assertNotNull(clazzFromRepo); // Use the variable to avoid a warning
+ final Record recordAttributeFromRepo = (Record)findAttribute("Record",clazzFromRepo)[0];
+ assertEquals(recordAttribute.toString(), recordAttributeFromRepo.toString(), "Both attributes needs to be equal");
+ tfile.deleteOnExit();
+ }
+
+ /**
+ * Check that we can copy a attribute correctly.
+ */
+ @Test
+ public void recordsCanBeCopied() throws ClassNotFoundException, IOException {
+ final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
+ final JavaClass copyClazz = clazz.copy();
+ assertEquals(clazz.toString(), copyClazz.toString(), "both records should have the same value");
+ }
+
+ /**
+ * Check that a record can be visited by our visitors
+ */
+ @Test
+ public void recordsCanBeVisited() throws ClassNotFoundException, IOException {
+ final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
+ final CountingVisitor countVisitor = new CountingVisitor();
+ final DescendingVisitor desendingVisitor = new DescendingVisitor(clazz, countVisitor);
+ desendingVisitor.visit();
+ assertEquals(1,countVisitor.recordCount, "should count one record");
+ assertEquals(2,countVisitor.recordComponentCount, "should count two record components");
+ }
+
+}
diff --git a/src/test/java/org/apache/bcel/visitors/CountingVisitor.java b/src/test/java/org/apache/bcel/visitors/CountingVisitor.java
index 3522df260f..936954790b 100644
--- a/src/test/java/org/apache/bcel/visitors/CountingVisitor.java
+++ b/src/test/java/org/apache/bcel/visitors/CountingVisitor.java
@@ -68,6 +68,8 @@
import org.apache.bcel.classfile.NestMembers;
import org.apache.bcel.classfile.ParameterAnnotationEntry;
import org.apache.bcel.classfile.ParameterAnnotations;
+import org.apache.bcel.classfile.Record;
+import org.apache.bcel.classfile.RecordComponentInfo;
import org.apache.bcel.classfile.Signature;
import org.apache.bcel.classfile.SourceFile;
import org.apache.bcel.classfile.StackMap;
@@ -204,6 +206,13 @@ public class CountingVisitor implements Visitor {
/** @since 6.4.0 */
public int nestMembersCount;
+
+ /** @since 6.9.0 */
+ public int recordCount;
+
+ /** @since 6.9.0 */
+ public int recordComponentCount;
+
// CHECKSTYLE:ON
@Override
@@ -517,4 +526,14 @@ public void visitSynthetic(final Synthetic obj) {
public void visitUnknown(final Unknown obj) {
unknownCount++;
}
+
+ @Override
+ public void visitRecord(Record v) {
+ recordCount++;
+ }
+
+ @Override
+ public void visitRecordComponent(RecordComponentInfo v) {
+ recordComponentCount++;
+ }
}
diff --git a/src/test/resources/record/SimpleRecord.class b/src/test/resources/record/SimpleRecord.class
new file mode 100644
index 0000000000000000000000000000000000000000..bf6b81196e5121e296b4e17c517f70235719c1f9
GIT binary patch
literal 1506
zcmaJ>TT|0O6#ll9rY(`uT2L+m0+qBN@qR1fD2^jD1s!1epikR&hX&GYO;SexlMgZ@
z;|ve}0DqL@*(N|}k%!$qdvd<>o!jQm-;>_}UgDL87=ylJwc57W7Io=1G{hN3_W2<<
zZSL%uftEqzTb))-xD0GV-FAG}a`qT?ByYPNXoIMV07B^{4p
zq6_$H@-wBmB^{?@+XPIkT8`zfF^m}-{f>)OhPjKbKXRA1gfH9+9PxG85NQlxM8^=a
z3J8oUPvs87m(E_Zf-cu3YNa=gN
z%iBRUyfjvDPlL%Yb3PqzFcW4FNoc9#J{~ZnYNs9;j-p{(&Y?UIW?=oEI}KZS3l%93
zI_+{K+HmqBnh?1Atu5XPukKoHU%FAqy3IW=stA32?spPpFGrgb7B!Q=-6S5O%ts=y|E3)5pI`Lcp6?X6wWJiMUom;8K$o`rIrU3At89KR8*QnYIF=aHSi?m
z)VPy2MRJ19ba)OyC(CPeOT}mlJ`9tzNnqt7Q~E_~@))_&@-gy9q>5pTcI5?Ra)b8S
zz!WzzPB#K|S=IMUmp6t9l8IrE4viKgX_9uuRG?Ft4wil*_nm}(|3PRPrs!KVgI;+4
z$A95jdTUc5<083Hj9Tdg(?BnXb#qdjS$bxtVMal7KyRQ?Pyu&BCWDxiqhx961dCUp
r;wW`vU&1n-!-Ri`IPH({1W)mdbZNRhN16WH<5;8n1bGgc+t=EEvSvb$
literal 0
HcmV?d00001
diff --git a/src/test/resources/record/SimpleRecord.java b/src/test/resources/record/SimpleRecord.java
new file mode 100644
index 0000000000..10316b07f8
--- /dev/null
+++ b/src/test/resources/record/SimpleRecord.java
@@ -0,0 +1,5 @@
+import javax.annotation.Nonnull;
+
+public record SimpleRecord(int aNumber,@Nonnull String aString) {
+
+}
From a5cb8b1a1a03795552ef3977be95901a1004fbb2 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Thu, 4 Apr 2024 08:09:02 -0400
Subject: [PATCH 127/147] Add Support for Java 16 records #290
---
src/changes/changes.xml | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index afe25d4b8f..2a86891ab5 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -60,6 +60,9 @@ The type attribute can be add,update,fix,remove.
-->
+
+ Add Support for Java 16 records #290.
+
Add null guard for InstructionFactory.createInvoke() #289.
Avoid possible NullPointerException in org.apache.bcel.classfile.DescendingVisitor.accept(E[]).
Avoid possible NullPointerException in AnnotationEntryGen.getAnnotationAttributes(ConstantPoolGen, AnnotationEntryGen[]).
From 0aadc311d1e7b382e8bb94a0f691f02036e80502 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Thu, 4 Apr 2024 08:10:53 -0400
Subject: [PATCH 128/147] The next release will be 6.9.0
---
pom.xml | 8 ++++----
src/changes/changes.xml | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/pom.xml b/pom.xml
index d7fb4280e2..f8eb033e28 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,7 +33,7 @@
org.apache.bcel
bcel
jar
- 6.8.3-SNAPSHOT
+ 6.9.0-SNAPSHOT
Apache Commons BCEL
Apache Commons Bytecode Engineering Library
@@ -48,11 +48,11 @@
1.8
bcel
org.apache.bcel
- 6.8.2
- 6.8.3
+ 6.9.0
+ 6.9.1
true
RC1
- 6.8.1
+ 6.8.2
(Java 8 or above)
https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-bcel
scm:svn:https://dist.apache.org/repos/dist/dev/commons/${commons.componentid}
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 2a86891ab5..c51bfac3cd 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -59,7 +59,7 @@ The type attribute can be add,update,fix,remove.
Defining changes.version allows one to create the RN without first removing the SNAPSHOT suffix.
-->
-
+
Add Support for Java 16 records #290.
From d8968470cedacfcb549d9652d7da7c3f8ef7fd03 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 5 Apr 2024 17:24:42 -0400
Subject: [PATCH 129/147] Bump codecov/codecov-action from 4.1.1 to 4.2.0
(#298)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4.1.1 to 4.2.0.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/c16abc29c95fcf9174b58eb7e1abf4c866893bc8...7afa10ed9b269c561c2336fd862446844e0cbf71)
---
updated-dependencies:
- dependency-name: codecov/codecov-action
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
.github/workflows/coverage.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
index 763dfa3047..72d99fb798 100644
--- a/.github/workflows/coverage.yml
+++ b/.github/workflows/coverage.yml
@@ -47,6 +47,6 @@ jobs:
run: mvn --show-version --batch-mode --no-transfer-progress install jacoco:report -DdataFile=jacoco_jdk${{ matrix.java }}.exec
- name: Upload coverage to Codecov
- uses: codecov/codecov-action@c16abc29c95fcf9174b58eb7e1abf4c866893bc8 # v4.1.1
+ uses: codecov/codecov-action@7afa10ed9b269c561c2336fd862446844e0cbf71 # v4.2.0
with:
files: ./target/site/jacoco/jacoco.xml
From 399d543b06c55bc8bd0fd3e0892050fdb1e0c819 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 5 Apr 2024 17:24:52 -0400
Subject: [PATCH 130/147] Bump github/codeql-action from 3.24.9 to 3.24.10
(#299)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.24.9 to 3.24.10.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/1b1aada464948af03b950897e5eb522f92603cc2...4355270be187e1b672a7a1c7c7bae5afdc1ab94a)
---
updated-dependencies:
- dependency-name: github/codeql-action
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
.github/workflows/codeql-analysis.yml | 6 +++---
.github/workflows/scorecards-analysis.yml | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index 4c57dc078b..3dfa7ac033 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -57,7 +57,7 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
- uses: github/codeql-action/init@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
+ uses: github/codeql-action/init@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -68,7 +68,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
- uses: github/codeql-action/autobuild@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
+ uses: github/codeql-action/autobuild@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
# âšī¸ Command-line programs to run using the OS shell.
# đ https://git.io/JvXDl
@@ -82,4 +82,4 @@ jobs:
# make release
- name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
+ uses: github/codeql-action/analyze@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml
index acbe79d9a3..cc2917c910 100644
--- a/.github/workflows/scorecards-analysis.yml
+++ b/.github/workflows/scorecards-analysis.yml
@@ -64,6 +64,6 @@ jobs:
retention-days: 5
- name: "Upload to code-scanning"
- uses: github/codeql-action/upload-sarif@1b1aada464948af03b950897e5eb522f92603cc2 # 3.24.9
+ uses: github/codeql-action/upload-sarif@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # 3.24.10
with:
sarif_file: results.sarif
From 1fe6337b91274817339883b7092a26beed08db22 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 8 Apr 2024 13:27:08 -0400
Subject: [PATCH 131/147] Bump commons-io:commons-io from 2.16.0 to 2.16.1
(#300)
Bumps commons-io:commons-io from 2.16.0 to 2.16.1.
---
updated-dependencies:
- dependency-name: commons-io:commons-io
dependency-type: direct:development
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index f8eb033e28..b891d66137 100644
--- a/pom.xml
+++ b/pom.xml
@@ -371,7 +371,7 @@
commons-io
commons-io
- 2.16.0
+ 2.16.1
test
@@ -463,7 +463,7 @@
commons-io
commons-io
- 2.16.0
+ 2.16.1
test
From 19c959a5db7f64588c045457142c219886a4cdc6 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Mon, 8 Apr 2024 13:27:43 -0400
Subject: [PATCH 132/147] Bump commons-io:commons-io from 2.16.0 to 2.16.1 #300
---
src/changes/changes.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c51bfac3cd..62de36c9a8 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -102,7 +102,7 @@ The type attribute can be add,update,fix,remove.
Bump org.apache.commons:commons-parent from 66 to 69 #283, #297.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.
- Bump commons-io:commons-io from 2.15.1 to 2.16.0 #295.
+ Bump commons-io:commons-io from 2.15.1 to 2.16.1 #295, #300.
From 93cf485ab68029de30fe072862f611c4f185d9cc Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 12 Apr 2024 15:37:53 -0400
Subject: [PATCH 133/147] Bump codecov/codecov-action from 4.2.0 to 4.3.0
(#301)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4.2.0 to 4.3.0.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/7afa10ed9b269c561c2336fd862446844e0cbf71...84508663e988701840491b86de86b666e8a86bed)
---
updated-dependencies:
- dependency-name: codecov/codecov-action
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
.github/workflows/coverage.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
index 72d99fb798..4d688fdc69 100644
--- a/.github/workflows/coverage.yml
+++ b/.github/workflows/coverage.yml
@@ -47,6 +47,6 @@ jobs:
run: mvn --show-version --batch-mode --no-transfer-progress install jacoco:report -DdataFile=jacoco_jdk${{ matrix.java }}.exec
- name: Upload coverage to Codecov
- uses: codecov/codecov-action@7afa10ed9b269c561c2336fd862446844e0cbf71 # v4.2.0
+ uses: codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed # v4.3.0
with:
files: ./target/site/jacoco/jacoco.xml
From 86194e26fe10efa7f336661683a22d38ca20c21d Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 19 Apr 2024 19:06:42 -0400
Subject: [PATCH 134/147] Bump actions/upload-artifact from 4.3.1 to 4.3.2
(#304)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.3.1 to 4.3.2.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/5d5d22a31266ced268874388b861e4b58bb5c2f3...1746f4ab65b179e0ea60a494b83293b640dd5bba)
---
updated-dependencies:
- dependency-name: actions/upload-artifact
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
.github/workflows/scorecards-analysis.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml
index cc2917c910..fb0f378fa1 100644
--- a/.github/workflows/scorecards-analysis.yml
+++ b/.github/workflows/scorecards-analysis.yml
@@ -57,7 +57,7 @@ jobs:
publish_results: true
- name: "Upload artifact"
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
+ uses: actions/upload-artifact@1746f4ab65b179e0ea60a494b83293b640dd5bba # v4.3.2
with:
name: SARIF file
path: results.sarif
From 7d1c4c708ad7912645fbf41019f400e39be7e6b3 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 19 Apr 2024 19:06:52 -0400
Subject: [PATCH 135/147] Bump github/codeql-action from 3.24.10 to 3.25.1
(#303)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.24.10 to 3.25.1.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/4355270be187e1b672a7a1c7c7bae5afdc1ab94a...c7f9125735019aa87cfc361530512d50ea439c71)
---
updated-dependencies:
- dependency-name: github/codeql-action
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
.github/workflows/codeql-analysis.yml | 6 +++---
.github/workflows/scorecards-analysis.yml | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index 3dfa7ac033..13d6077417 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -57,7 +57,7 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
- uses: github/codeql-action/init@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
+ uses: github/codeql-action/init@c7f9125735019aa87cfc361530512d50ea439c71 # v3.25.1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -68,7 +68,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
- uses: github/codeql-action/autobuild@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
+ uses: github/codeql-action/autobuild@c7f9125735019aa87cfc361530512d50ea439c71 # v3.25.1
# âšī¸ Command-line programs to run using the OS shell.
# đ https://git.io/JvXDl
@@ -82,4 +82,4 @@ jobs:
# make release
- name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
+ uses: github/codeql-action/analyze@c7f9125735019aa87cfc361530512d50ea439c71 # v3.25.1
diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml
index fb0f378fa1..1a80879c0e 100644
--- a/.github/workflows/scorecards-analysis.yml
+++ b/.github/workflows/scorecards-analysis.yml
@@ -64,6 +64,6 @@ jobs:
retention-days: 5
- name: "Upload to code-scanning"
- uses: github/codeql-action/upload-sarif@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # 3.24.10
+ uses: github/codeql-action/upload-sarif@c7f9125735019aa87cfc361530512d50ea439c71 # 3.25.1
with:
sarif_file: results.sarif
From d18eae68a98d5a82c44fd5030b4375ac93bc1fc6 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 19 Apr 2024 19:07:01 -0400
Subject: [PATCH 136/147] Bump actions/checkout from 4.1.2 to 4.1.3 (#302)
Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.2 to 4.1.3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/9bb56186c3b09b4f86b1c65136769dd318469633...1d96c772d19495a3b5c517cd2bc0cb401ea0529f)
---
updated-dependencies:
- dependency-name: actions/checkout
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
.github/workflows/codeql-analysis.yml | 2 +-
.github/workflows/coverage.yml | 2 +-
.github/workflows/maven.yml | 2 +-
.github/workflows/scorecards-analysis.yml | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index 13d6077417..0a59457faa 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -45,7 +45,7 @@ jobs:
steps:
- name: Checkout repository
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
+ uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
with:
persist-credentials: false
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
index 4d688fdc69..ef257b7528 100644
--- a/.github/workflows/coverage.yml
+++ b/.github/workflows/coverage.yml
@@ -29,7 +29,7 @@ jobs:
java: [ 8, 11 ]
steps:
- - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
+ - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
with:
persist-credentials: false
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index eb78adb016..fd54b482a0 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -45,7 +45,7 @@ jobs:
steps:
- name: Prepare git
run: git config --global core.autocrlf false
- - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
+ - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
with:
persist-credentials: false
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml
index 1a80879c0e..b398ee5964 100644
--- a/.github/workflows/scorecards-analysis.yml
+++ b/.github/workflows/scorecards-analysis.yml
@@ -40,7 +40,7 @@ jobs:
steps:
- name: "Checkout code"
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
+ uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
with:
persist-credentials: false
From 8083fb59b6cf7bf41c055aee332501bee59bf99f Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 21 Apr 2024 09:25:22 -0400
Subject: [PATCH 137/147] Sort members
---
.../bcel/classfile/DescendingVisitor.java | 30 +++----
.../org/apache/bcel/classfile/JavaClass.java | 48 +++++------
.../org/apache/bcel/classfile/Record.java | 20 ++---
.../bcel/classfile/RecordComponentInfo.java | 40 ++++-----
.../org/apache/bcel/classfile/Visitor.java | 36 ++++----
.../statics/StringRepresentation.java | 20 ++---
.../apache/bcel/CounterVisitorTestCase.java | 10 +--
.../apache/bcel/classfile/RecordTestCase.java | 84 +++++++++----------
.../generic/InstructionFactoryTestCase.java | 12 +--
.../apache/bcel/visitors/CountingVisitor.java | 20 ++---
10 files changed, 160 insertions(+), 160 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java b/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
index 880f1009e6..69fdab6c72 100644
--- a/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
+++ b/src/main/java/org/apache/bcel/classfile/DescendingVisitor.java
@@ -504,6 +504,21 @@ public void visitParameterAnnotationEntry(final ParameterAnnotationEntry obj) {
stack.pop();
}
+ @Override
+ public void visitRecord(Record record) {
+ stack.push(record);
+ record.accept(visitor);
+ accept(record.getComponents());
+ stack.pop();
+ }
+
+ @Override
+ public void visitRecordComponent(RecordComponentInfo recordComponentInfo) {
+ stack.push(recordComponentInfo);
+ recordComponentInfo.accept(visitor);
+ stack.pop();
+ }
+
@Override
public void visitSignature(final Signature attribute) {
stack.push(attribute);
@@ -561,19 +576,4 @@ public void visitUnknown(final Unknown attribute) {
stack.pop();
}
- @Override
- public void visitRecord(Record record) {
- stack.push(record);
- record.accept(visitor);
- accept(record.getComponents());
- stack.pop();
- }
-
- @Override
- public void visitRecordComponent(RecordComponentInfo recordComponentInfo) {
- stack.push(recordComponentInfo);
- recordComponentInfo.accept(visitor);
- stack.pop();
- }
-
}
diff --git a/src/main/java/org/apache/bcel/classfile/JavaClass.java b/src/main/java/org/apache/bcel/classfile/JavaClass.java
index fe96798353..d52336d011 100644
--- a/src/main/java/org/apache/bcel/classfile/JavaClass.java
+++ b/src/main/java/org/apache/bcel/classfile/JavaClass.java
@@ -259,6 +259,19 @@ public int compareTo(final JavaClass obj) {
return getClassName().compareTo(obj.getClassName());
}
+ private void computeIsRecord() {
+ if (computedRecord) {
+ return;
+ }
+ for (final Attribute attribute : this.attributes) {
+ if (attribute instanceof Record) {
+ isRecord = true;
+ break;
+ }
+ }
+ this.computedRecord = true;
+ }
+
private void computeNestedTypeStatus() {
if (computedNestedTypeStatus) {
return;
@@ -743,6 +756,17 @@ public final boolean isNested() {
return this.isNested;
}
+ /**
+ * Tests whether this class was declared as a record
+ *
+ * @return true if a record attribute is present, false otherwise.
+ * @since 6.9.0
+ */
+ public boolean isRecord() {
+ computeIsRecord();
+ return this.isRecord;
+ }
+
public final boolean isSuper() {
return (super.getAccessFlags() & Const.ACC_SUPER) != 0;
}
@@ -906,28 +930,4 @@ public String toString() {
}
return buf.toString();
}
-
- /**
- * Tests whether this class was declared as a record
- *
- * @return true if a record attribute is present, false otherwise.
- * @since 6.9.0
- */
- public boolean isRecord() {
- computeIsRecord();
- return this.isRecord;
- }
-
- private void computeIsRecord() {
- if (computedRecord) {
- return;
- }
- for (final Attribute attribute : this.attributes) {
- if (attribute instanceof Record) {
- isRecord = true;
- break;
- }
- }
- this.computedRecord = true;
- }
}
diff --git a/src/main/java/org/apache/bcel/classfile/Record.java b/src/main/java/org/apache/bcel/classfile/Record.java
index e459a0fe79..21f17634b1 100644
--- a/src/main/java/org/apache/bcel/classfile/Record.java
+++ b/src/main/java/org/apache/bcel/classfile/Record.java
@@ -37,6 +37,16 @@ public final class Record extends Attribute {
private static final RecordComponentInfo[] EMPTY_RCI_ARRAY = new RecordComponentInfo[] {};
+ private static RecordComponentInfo[] readComponents(final DataInput input, final ConstantPool constantPool)
+ throws IOException {
+ final int classCount = input.readUnsignedShort();
+ final RecordComponentInfo[] components = new RecordComponentInfo[classCount];
+ for (int i = 0; i < classCount; i++) {
+ components[i] = new RecordComponentInfo(input, constantPool);
+ }
+ return components;
+ }
+
private RecordComponentInfo[] components;
/**
@@ -53,16 +63,6 @@ public final class Record extends Attribute {
this(nameIndex, length, readComponents(input, constantPool), constantPool);
}
- private static RecordComponentInfo[] readComponents(final DataInput input, final ConstantPool constantPool)
- throws IOException {
- final int classCount = input.readUnsignedShort();
- final RecordComponentInfo[] components = new RecordComponentInfo[classCount];
- for (int i = 0; i < classCount; i++) {
- components[i] = new RecordComponentInfo(input, constantPool);
- }
- return components;
- }
-
/**
* Constructs a new instance using components.
*
diff --git a/src/main/java/org/apache/bcel/classfile/RecordComponentInfo.java b/src/main/java/org/apache/bcel/classfile/RecordComponentInfo.java
index bf489d0f42..cf3ac1f9d2 100644
--- a/src/main/java/org/apache/bcel/classfile/RecordComponentInfo.java
+++ b/src/main/java/org/apache/bcel/classfile/RecordComponentInfo.java
@@ -55,6 +55,11 @@ public RecordComponentInfo(final DataInput input, ConstantPool constantPool) thr
this.constantPool = constantPool;
}
+ @Override
+ public void accept(Visitor v) {
+ v.visitRecordComponent(this);
+ }
+
/**
* Dumps contents into a file stream in binary format.
*
@@ -70,18 +75,22 @@ public void dump(DataOutputStream file) throws IOException {
}
}
- @Override
- public void accept(Visitor v) {
- v.visitRecordComponent(this);
+ /**
+ * Gets all attributes.
+ *
+ * @return all attributes.
+ */
+ public Attribute[] getAttributes() {
+ return attributes;
}
/**
- * Gets the name index.
+ * Gets the constant pool.
*
- * @return index in constant pool of this record component name.
+ * @return Constant pool.
*/
- public int getIndex() {
- return index;
+ public ConstantPool getConstantPool() {
+ return constantPool;
}
/**
@@ -94,21 +103,12 @@ public int getDescriptorIndex() {
}
/**
- * Gets all attributes.
- *
- * @return all attributes.
- */
- public Attribute[] getAttributes() {
- return attributes;
- }
-
- /**
- * Gets the constant pool.
+ * Gets the name index.
*
- * @return Constant pool.
+ * @return index in constant pool of this record component name.
*/
- public ConstantPool getConstantPool() {
- return constantPool;
+ public int getIndex() {
+ return index;
}
/**
diff --git a/src/main/java/org/apache/bcel/classfile/Visitor.java b/src/main/java/org/apache/bcel/classfile/Visitor.java
index 6f73932468..89a72c8c74 100644
--- a/src/main/java/org/apache/bcel/classfile/Visitor.java
+++ b/src/main/java/org/apache/bcel/classfile/Visitor.java
@@ -207,6 +207,17 @@ default void visitNestMembers(final NestMembers obj) {
// empty
}
+ /**
+ * @since 6.0
+ */
+ void visitParameterAnnotation(ParameterAnnotations obj);
+
+
+ /**
+ * @since 6.0
+ */
+ void visitParameterAnnotationEntry(ParameterAnnotationEntry obj);
+
/**
* Visits a {@link Record} object.
*
@@ -217,16 +228,15 @@ default void visitRecord(final Record obj) {
// empty
}
-
/**
- * @since 6.0
- */
- void visitParameterAnnotation(ParameterAnnotations obj);
-
- /**
- * @since 6.0
+ * Visits a {@link RecordComponentInfo} object.
+ *
+ * @param record component to visit
+ * @since 6.9.0
*/
- void visitParameterAnnotationEntry(ParameterAnnotationEntry obj);
+ default void visitRecordComponent(RecordComponentInfo record) {
+ // noop
+ }
void visitSignature(Signature obj);
@@ -250,14 +260,4 @@ default void visitStackMapType(final StackMapType obj) {
void visitUnknown(Unknown obj);
- /**
- * Visits a {@link RecordComponentInfo} object.
- *
- * @param record component to visit
- * @since 6.9.0
- */
- default void visitRecordComponent(RecordComponentInfo record) {
- // noop
- }
-
}
diff --git a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
index af12ed5a24..c89d1d757b 100644
--- a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
+++ b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
@@ -399,6 +399,16 @@ public void visitParameterAnnotationEntry(final ParameterAnnotationEntry obj) {
tostring = toString(obj);
}
+ @Override
+ public void visitRecord(Record obj) {
+ tostring = toString(obj);
+ }
+
+ @Override
+ public void visitRecordComponent(RecordComponentInfo obj) {
+ tostring = toString(obj);
+ }
+
@Override
public void visitSignature(final Signature obj) {
tostring = toString(obj);
@@ -432,14 +442,4 @@ public void visitUnknown(final Unknown obj) {
tostring = toString(obj);
}
- @Override
- public void visitRecord(Record obj) {
- tostring = toString(obj);
- }
-
- @Override
- public void visitRecordComponent(RecordComponentInfo obj) {
- tostring = toString(obj);
- }
-
}
diff --git a/src/test/java/org/apache/bcel/CounterVisitorTestCase.java b/src/test/java/org/apache/bcel/CounterVisitorTestCase.java
index 224369ba3f..6ecf3da8b9 100644
--- a/src/test/java/org/apache/bcel/CounterVisitorTestCase.java
+++ b/src/test/java/org/apache/bcel/CounterVisitorTestCase.java
@@ -183,6 +183,11 @@ public void testParameterAnnotationCount() {
assertEquals(0, getVisitor().parameterAnnotationCount, "parameterAnnotationCount");
}
+ @Test
+ public void testRecordCount() {
+ assertEquals(0, getVisitor().recordCount, "recordCount");
+ }
+
@Test
public void testSignatureCount() {
assertEquals(0, getVisitor().signatureAnnotationCount, "signatureAnnotationCount");
@@ -217,9 +222,4 @@ public void testSyntheticCount() {
public void testUnknownCount() {
assertEquals(0, getVisitor().unknownCount, "unknownCount");
}
-
- @Test
- public void testRecordCount() {
- assertEquals(0, getVisitor().recordCount, "recordCount");
- }
}
diff --git a/src/test/java/org/apache/bcel/classfile/RecordTestCase.java b/src/test/java/org/apache/bcel/classfile/RecordTestCase.java
index 7a2e639d76..8056250a7d 100644
--- a/src/test/java/org/apache/bcel/classfile/RecordTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/RecordTestCase.java
@@ -31,6 +31,48 @@
public class RecordTestCase extends AbstractTestCase {
+ /**
+ * Check that we can copy a attribute correctly.
+ */
+ @Test
+ public void recordsCanBeCopied() throws ClassNotFoundException, IOException {
+ final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
+ final JavaClass copyClazz = clazz.copy();
+ assertEquals(clazz.toString(), copyClazz.toString(), "both records should have the same value");
+ }
+
+ /**
+ * Check that a record can be visited by our visitors
+ */
+ @Test
+ public void recordsCanBeVisited() throws ClassNotFoundException, IOException {
+ final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
+ final CountingVisitor countVisitor = new CountingVisitor();
+ final DescendingVisitor desendingVisitor = new DescendingVisitor(clazz, countVisitor);
+ desendingVisitor.visit();
+ assertEquals(1,countVisitor.recordCount, "should count one record");
+ assertEquals(2,countVisitor.recordComponentCount, "should count two record components");
+ }
+
+
+ /**
+ * Check that we can save and load the attribute correctly.
+ */
+ @Test
+ public void testAttributeSerializtion() throws ClassNotFoundException, IOException {
+ final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
+ final File tfile = createTestdataFile("SimpleRecord.class");
+ final Record recordAttribute = (Record)findAttribute("Record",clazz)[0];
+ clazz.dump(tfile);
+ // Read in the new version and check it is OK
+ final SyntheticRepository repos2 = createRepos(".");
+ final JavaClass clazzFromRepo = repos2.loadClass("SimpleRecord");
+ assertNotNull(clazzFromRepo); // Use the variable to avoid a warning
+ final Record recordAttributeFromRepo = (Record)findAttribute("Record",clazzFromRepo)[0];
+ assertEquals(recordAttribute.toString(), recordAttributeFromRepo.toString(), "Both attributes needs to be equal");
+ tfile.deleteOnExit();
+ }
+
/**
* A record type, once compiled, should result in a class file that is
* marked such that we can determine from the access flags
@@ -76,46 +118,4 @@ public void testRecordToString() throws ClassNotFoundException, ClassFormatExcep
assertEquals("RecordComponentInfo(aNumber,I,0):", firstComponent.toString());
}
-
- /**
- * Check that we can save and load the attribute correctly.
- */
- @Test
- public void testAttributeSerializtion() throws ClassNotFoundException, IOException {
- final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
- final File tfile = createTestdataFile("SimpleRecord.class");
- final Record recordAttribute = (Record)findAttribute("Record",clazz)[0];
- clazz.dump(tfile);
- // Read in the new version and check it is OK
- final SyntheticRepository repos2 = createRepos(".");
- final JavaClass clazzFromRepo = repos2.loadClass("SimpleRecord");
- assertNotNull(clazzFromRepo); // Use the variable to avoid a warning
- final Record recordAttributeFromRepo = (Record)findAttribute("Record",clazzFromRepo)[0];
- assertEquals(recordAttribute.toString(), recordAttributeFromRepo.toString(), "Both attributes needs to be equal");
- tfile.deleteOnExit();
- }
-
- /**
- * Check that we can copy a attribute correctly.
- */
- @Test
- public void recordsCanBeCopied() throws ClassNotFoundException, IOException {
- final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
- final JavaClass copyClazz = clazz.copy();
- assertEquals(clazz.toString(), copyClazz.toString(), "both records should have the same value");
- }
-
- /**
- * Check that a record can be visited by our visitors
- */
- @Test
- public void recordsCanBeVisited() throws ClassNotFoundException, IOException {
- final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
- final CountingVisitor countVisitor = new CountingVisitor();
- final DescendingVisitor desendingVisitor = new DescendingVisitor(clazz, countVisitor);
- desendingVisitor.visit();
- assertEquals(1,countVisitor.recordCount, "should count one record");
- assertEquals(2,countVisitor.recordComponentCount, "should count two record components");
- }
-
}
diff --git a/src/test/java/org/apache/bcel/generic/InstructionFactoryTestCase.java b/src/test/java/org/apache/bcel/generic/InstructionFactoryTestCase.java
index 073238f214..6dda101c27 100644
--- a/src/test/java/org/apache/bcel/generic/InstructionFactoryTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/InstructionFactoryTestCase.java
@@ -62,6 +62,12 @@ public void testArrayStore() throws Exception {
assertEquals(InstructionConst.AASTORE, createArrayStore(Type.getType("[I")));
}
+ @Test
+ public void testCreateInvokeNullArgTypes() throws Exception {
+ InstructionFactory factory = new InstructionFactory(new ClassGen(Repository.lookupClass(Object.class)));
+ factory.createInvoke("", "", Type.VOID, null, Const.INVOKESPECIAL, false); // Mustn't throw an NPE
+ }
+
@Test
public void testExceptions() throws Exception {
final InstructionFactory factory = new InstructionFactory(new ClassGen(Repository.lookupClass(Object.class)));
@@ -97,10 +103,4 @@ public void testNull() throws Exception {
assertEquals(InstructionConst.ACONST_NULL, createNull(Type.OBJECT));
assertEquals(InstructionConst.ACONST_NULL, createNull(Type.getType("[I")));
}
-
- @Test
- public void testCreateInvokeNullArgTypes() throws Exception {
- InstructionFactory factory = new InstructionFactory(new ClassGen(Repository.lookupClass(Object.class)));
- factory.createInvoke("", "", Type.VOID, null, Const.INVOKESPECIAL, false); // Mustn't throw an NPE
- }
}
diff --git a/src/test/java/org/apache/bcel/visitors/CountingVisitor.java b/src/test/java/org/apache/bcel/visitors/CountingVisitor.java
index 936954790b..c06098436a 100644
--- a/src/test/java/org/apache/bcel/visitors/CountingVisitor.java
+++ b/src/test/java/org/apache/bcel/visitors/CountingVisitor.java
@@ -489,6 +489,16 @@ public void visitParameterAnnotationEntry(final ParameterAnnotationEntry paramet
// TODO Auto-generated method stub
}
+ @Override
+ public void visitRecord(Record v) {
+ recordCount++;
+ }
+
+ @Override
+ public void visitRecordComponent(RecordComponentInfo v) {
+ recordComponentCount++;
+ }
+
@Override
public void visitSignature(final Signature obj) {
signatureAnnotationCount++;
@@ -526,14 +536,4 @@ public void visitSynthetic(final Synthetic obj) {
public void visitUnknown(final Unknown obj) {
unknownCount++;
}
-
- @Override
- public void visitRecord(Record v) {
- recordCount++;
- }
-
- @Override
- public void visitRecordComponent(RecordComponentInfo v) {
- recordComponentCount++;
- }
}
From f670f11172996ef53e043d4ea48590f33dd31d08 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 21 Apr 2024 09:33:49 -0400
Subject: [PATCH 138/147] Set the (low) bar for JaCoCo checks
---
pom.xml | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/pom.xml b/pom.xml
index b891d66137..68b075eeba 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,6 +68,14 @@
3.25.3
5.14.0
false
+
+ true
+ 0.90
+ 0.65
+ 0.70
+ 0.58
+ 0.68
+ 0.58
| bcel-6.8.2-bin.tar.gz | -sha512 | -pgp | +bcel-6.9.0-bin.tar.gz | +sha512 | +pgp |
| bcel-6.8.2-bin.zip | -sha512 | -pgp | +bcel-6.9.0-bin.zip | +sha512 | +pgp |
| bcel-6.8.2-src.tar.gz | -sha512 | -pgp | +bcel-6.9.0-src.tar.gz | +sha512 | +pgp |
| bcel-6.8.2-src.zip | -sha512 | -pgp | +bcel-6.9.0-src.zip | +sha512 | +pgp |