From 904ab72c8f5cde60a0d905fcd8b607aaa0850a4c Mon Sep 17 00:00:00 2001
From: "Gary David Gregory (Code signing key)"
Date: Tue, 5 Dec 2023 13:32:32 -0500
Subject: [PATCH 01/46] Fix link to the user mailing list
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index c4950df67a..d14a423ddb 100644
--- a/README.md
+++ b/README.md
@@ -57,7 +57,7 @@ Documentation
More information can be found on the [Apache Commons BCEL homepage](https://commons.apache.org/proper/commons-bcel).
The [Javadoc](https://commons.apache.org/proper/commons-bcel/apidocs) can be browsed.
-Questions related to the usage of Apache Commons BCEL should be posted to the [user mailing list][ml].
+Questions related to the usage of Apache Commons BCEL should be posted to the [user mailing list](https://commons.apache.org/mail-lists.html).
Getting the latest release
--------------------------
From 4a1f0ed06952df3ef12d3890c7f1d7e2d3f9a145 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Thu, 7 Dec 2023 16:10:22 -0500
Subject: [PATCH 02/46] Bump to next development version
---
pom.xml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 5ef796451b..d01cc25503 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,7 +33,7 @@
org.apache.bcel
bcel
jar
- 6.8.0
+ 6.8.1-SNAPSHOT
Apache Commons BCEL
Apache Commons Bytecode Engineering Library
@@ -48,6 +48,7 @@
bcel
org.apache.bcel
6.8.0
+ 6.8.1
true
RC1
6.7.0
From fa8edb6285e3c7460e99310fbad3c5655f5a8c6a Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Thu, 7 Dec 2023 16:13:05 -0500
Subject: [PATCH 03/46] Add a section for the next release
---
src/changes/changes.xml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9d8828f65c..152b1420d0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -64,6 +64,8 @@ The type attribute can be add,update,fix,remove.
-->
+
+
Add and use InvalidMethodSignatureException extending ClassFormatException.
From b3056c1740ae4fb34a7c17621e3e787202e0d7c4 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sat, 9 Dec 2023 11:52:50 -0500
Subject: [PATCH 04/46] grammar
---
src/changes/release-notes.vm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/changes/release-notes.vm b/src/changes/release-notes.vm
index 97122d5e2d..9401b57fd2 100644
--- a/src/changes/release-notes.vm
+++ b/src/changes/release-notes.vm
@@ -28,7 +28,7 @@ ${project.name} ${version}!
The Byte Code Engineering Library (BCEL) is intended to give users a convenient
way to analyze, create, and manipulate compiled .class files. Classes are
represented by objects containing all the symbolic information of the given
-class: methods, fields and byte code instructions.
+class: methods, fields, and byte code instructions.
##$introduction.replaceAll("(?
Date: Sun, 10 Dec 2023 10:21:15 -0500
Subject: [PATCH 05/46] Replace internal StringBuffer with StringBuilder
---
src/examples/Mini/ASTFunDecl.java | 2 +-
src/main/java/org/apache/bcel/util/InstructionFinder.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/examples/Mini/ASTFunDecl.java b/src/examples/Mini/ASTFunDecl.java
index 6002a168c9..2a3fadf591 100644
--- a/src/examples/Mini/ASTFunDecl.java
+++ b/src/examples/Mini/ASTFunDecl.java
@@ -317,7 +317,7 @@ public void code(final PrintWriter out) {
}
if (!ignore) {
- final StringBuffer buf = new StringBuffer();
+ final StringBuilder buf = new StringBuilder();
body.code(buf);
out.println(getVarDecls());
diff --git a/src/main/java/org/apache/bcel/util/InstructionFinder.java b/src/main/java/org/apache/bcel/util/InstructionFinder.java
index 07750cf5d6..62169817ee 100644
--- a/src/main/java/org/apache/bcel/util/InstructionFinder.java
+++ b/src/main/java/org/apache/bcel/util/InstructionFinder.java
@@ -369,7 +369,7 @@ public final Iterator search(final String pattern, final In
// }
// private static final String pattern2string( String pattern, boolean make_string ) {
-// StringBuffer buf = new StringBuffer();
+// StringBuilder buf = new StringBuilder();
// for (int i = 0; i < pattern.length(); i++) {
// char ch = pattern.charAt(i);
// if (ch >= OFFSET) {
From a61ffa8df395a34e3b522423cea517bf4f711aab Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 10 Dec 2023 10:22:46 -0500
Subject: [PATCH 06/46] Replace internal StringBuffer with StringBuilder
---
src/changes/changes.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 152b1420d0..590dcd49e3 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -65,6 +65,7 @@ The type attribute can be add,update,fix,remove.
+ Replace internal StringBuffer with StringBuilder.
From 79c08224ba9feb59e86dc8dd8bc99f182564e101 Mon Sep 17 00:00:00 2001
From: "Gary David Gregory (Code signing key)"
Date: Thu, 14 Dec 2023 09:43:14 -0500
Subject: [PATCH 07/46] Javadoc
---
src/main/java/org/apache/bcel/verifier/GraphicalVerifier.java | 2 +-
src/main/java/org/apache/bcel/verifier/VerifierAppFrame.java | 2 +-
.../apache/bcel/verifier/structurals/ExceptionHandlers.java | 2 +-
.../apache/bcel/verifier/structurals/ExecutionVisitor.java | 2 +-
.../org/apache/bcel/verifier/structurals/Subroutines.java | 4 ++--
5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/bcel/verifier/GraphicalVerifier.java b/src/main/java/org/apache/bcel/verifier/GraphicalVerifier.java
index 115055e0b4..331eb5f979 100644
--- a/src/main/java/org/apache/bcel/verifier/GraphicalVerifier.java
+++ b/src/main/java/org/apache/bcel/verifier/GraphicalVerifier.java
@@ -40,7 +40,7 @@ public static void main(final String[] args) {
new GraphicalVerifier();
}
- /** Constructor. */
+ /** Constructs a new instance. */
public GraphicalVerifier() {
final VerifierAppFrame frame = new VerifierAppFrame();
// Frames �berpr�fen, die voreingestellte Gr��e haben
diff --git a/src/main/java/org/apache/bcel/verifier/VerifierAppFrame.java b/src/main/java/org/apache/bcel/verifier/VerifierAppFrame.java
index 8ec40e1239..e8482cc2ab 100644
--- a/src/main/java/org/apache/bcel/verifier/VerifierAppFrame.java
+++ b/src/main/java/org/apache/bcel/verifier/VerifierAppFrame.java
@@ -90,7 +90,7 @@ public class VerifierAppFrame extends JFrame {
private final JMenuItem whatisMenuItem = new JMenuItem();
private final JMenuItem aboutMenuItem = new JMenuItem();
- /** Constructor. */
+ /** Constructs a new instance. */
public VerifierAppFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java b/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java
index be1cdb1270..0a9dbab8c8 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java
@@ -41,7 +41,7 @@ public class ExceptionHandlers {
private final Map> exceptionHandlers;
/**
- * Constructor. Creates a new ExceptionHandlers instance.
+ * Constructs a new ExceptionHandlers instance.
*/
public ExceptionHandlers(final MethodGen mg) {
exceptionHandlers = new HashMap<>();
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java b/src/main/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java
index baa03b99ca..36c9af0cd1 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java
@@ -70,7 +70,7 @@ public class ExecutionVisitor extends EmptyVisitor {
private ConstantPoolGen cpg;
/**
- * Constructor. Constructs a new instance of this class.
+ * Constructs a new instance of this class.
*/
public ExecutionVisitor() {
}
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java b/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
index 49300a0318..565c95362e 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
@@ -398,7 +398,7 @@ private static InstructionHandle[] getSuccessors(final InstructionHandle instruc
// CHECKSTYLE:ON
/**
- * Constructor.
+ * Constructs a new instance.
*
* @param mg A MethodGen object representing method to create the Subroutine objects of. Assumes that JustIce strict
* checks are needed.
@@ -408,7 +408,7 @@ public Subroutines(final MethodGen mg) {
}
/**
- * Constructor.
+ * Constructs a new instance.
*
* @param mg A MethodGen object representing method to create the Subroutine objects of.
* @param enableJustIceCheck whether to enable additional JustIce checks
From 0d5365be26fa763d317c07a1e27b158adc33b75b Mon Sep 17 00:00:00 2001
From: "Gary David Gregory (Code signing key)"
Date: Thu, 14 Dec 2023 13:46:15 -0500
Subject: [PATCH 08/46] Javadoc
---
src/main/java/org/apache/bcel/classfile/CodeException.java | 2 +-
src/main/java/org/apache/bcel/classfile/LineNumber.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/CodeException.java b/src/main/java/org/apache/bcel/classfile/CodeException.java
index d5b16ce6ed..5171bcacf5 100644
--- a/src/main/java/org/apache/bcel/classfile/CodeException.java
+++ b/src/main/java/org/apache/bcel/classfile/CodeException.java
@@ -60,7 +60,7 @@ public final class CodeException implements Cloneable, Node, Constants {
/** Range in the code the exception handler. */
private int startPc;
- /** active. startPc is inclusive, endPc exclusive. */
+ /** Active. startPc is inclusive, endPc exclusive. */
private int endPc;
/**
diff --git a/src/main/java/org/apache/bcel/classfile/LineNumber.java b/src/main/java/org/apache/bcel/classfile/LineNumber.java
index 4f0cbcd4e7..c09c29ea43 100644
--- a/src/main/java/org/apache/bcel/classfile/LineNumber.java
+++ b/src/main/java/org/apache/bcel/classfile/LineNumber.java
@@ -35,7 +35,7 @@ public final class LineNumber implements Cloneable, Node {
/** Program Counter (PC) corresponds to line */
private int startPc;
- /** number in source file */
+ /** Number in source file */
private int lineNumber;
/**
From 39f35620a07d17dcf2465b167ff3d7d8dacaf31b Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 15 Dec 2023 14:26:58 -0500
Subject: [PATCH 09/46] Bump jna.version from 5.13.0 to 5.14.0 (#250)
Bumps `jna.version` from 5.13.0 to 5.14.0.
Updates `net.java.dev.jna:jna` from 5.13.0 to 5.14.0
- [Changelog](https://github.com/java-native-access/jna/blob/master/CHANGES.md)
- [Commits](https://github.com/java-native-access/jna/compare/5.13.0...5.14.0)
Updates `net.java.dev.jna:jna-platform` from 5.13.0 to 5.14.0
- [Changelog](https://github.com/java-native-access/jna/blob/master/CHANGES.md)
- [Commits](https://github.com/java-native-access/jna/compare/5.13.0...5.14.0)
---
updated-dependencies:
- dependency-name: net.java.dev.jna:jna
dependency-type: direct:development
update-type: version-update:semver-minor
- dependency-name: net.java.dev.jna:jna-platform
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 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index d01cc25503..833a7f1747 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,7 +63,7 @@
BCEL
12314220
- 5.13.0
+ 5.14.0
false
From d8f116c8a2a41f191d2e94215d11f5a83ffd30fc Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Fri, 15 Dec 2023 14:29:39 -0500
Subject: [PATCH 10/46] Bump jna.version from 5.13.0 to 5.14.0 #250
---
src/changes/changes.xml | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 590dcd49e3..403c57b50b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -65,7 +65,10 @@ The type attribute can be add,update,fix,remove.
+
Replace internal StringBuffer with StringBuilder.
+
+ Bump jna.version from 5.13.0 to 5.14.0 #250.
From 3dae0f1ed279f987bb2a572ac24bf2a6cfe6ba25 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 15 Dec 2023 14:30:00 -0500
Subject: [PATCH 11/46] Bump actions/upload-artifact from 3.1.3 to 4.0.0 (#251)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3.1.3 to 4.0.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/a8a3f3ad30e3422c9c7b888a15615d19a852ae32...c7d193f32edcb7bfad88892161225aeda64e9392)
---
updated-dependencies:
- dependency-name: actions/upload-artifact
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>
---
.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 b92b2de8ca..512e4a1acf 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@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # 3.1.0
+ uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # 3.1.0
with:
name: SARIF file
path: results.sarif
From 184a0cd18ba3be400471d6db96899812c09f4414 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Fri, 15 Dec 2023 14:30:50 -0500
Subject: [PATCH 12/46] Bump GitHub various actions for CI builds
---
src/changes/changes.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 403c57b50b..ca738aedc6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -68,6 +68,7 @@ The type attribute can be add,update,fix,remove.
Replace internal StringBuffer with StringBuilder.
+ Bump GitHub various actions for CI builds.
Bump jna.version from 5.13.0 to 5.14.0 #250.
From e4e3dfff33ec37977f466fae2643996793a5e127 Mon Sep 17 00:00:00 2001
From: Sebb
Date: Sun, 17 Dec 2023 00:04:43 +0000
Subject: [PATCH 13/46] Avoid a spotbugs complaint [skip ci]
---
.../java/org/apache/bcel/classfile/ConstantUtf8.java | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java b/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java
index 51a843c861..edbdfef8b4 100644
--- a/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java
+++ b/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java
@@ -178,6 +178,11 @@ static void printStats() {
Cache.MAX_ENTRY_SIZE);
}
+ // Avoid Spotbugs complaint about Write to static field
+ private static void countCreated() {
+ created++;
+ }
+
private final String value;
/**
@@ -198,7 +203,7 @@ public ConstantUtf8(final ConstantUtf8 constantUtf8) {
ConstantUtf8(final DataInput dataInput) throws IOException {
super(Const.CONSTANT_Utf8);
value = dataInput.readUTF();
- created++;
+ countCreated();
}
/**
@@ -207,7 +212,7 @@ public ConstantUtf8(final ConstantUtf8 constantUtf8) {
public ConstantUtf8(final String value) {
super(Const.CONSTANT_Utf8);
this.value = Objects.requireNonNull(value, "value");
- created++;
+ countCreated();
}
/**
From faba736fb7ff57c422e19726aba63a31c311b2b7 Mon Sep 17 00:00:00 2001
From: Sebb
Date: Sun, 17 Dec 2023 00:05:16 +0000
Subject: [PATCH 14/46] Avoid a spotbugs complaint [skip ci]
---
src/main/java/org/apache/bcel/generic/InstructionList.java | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/main/java/org/apache/bcel/generic/InstructionList.java b/src/main/java/org/apache/bcel/generic/InstructionList.java
index c373e3b3f5..ca053e4418 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionList.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionList.java
@@ -1129,6 +1129,9 @@ public void setPositions(final boolean check) { // called by code in other packa
case Const.LOOKUPSWITCH:
maxAdditionalBytes += 3;
break;
+ default:
+ // TODO should this be an error?
+ break;
}
index += i.getLength();
}
From bb9c610e5e2dffd641b19681a480ded1f4025117 Mon Sep 17 00:00:00 2001
From: Sebb
Date: Sun, 17 Dec 2023 00:06:19 +0000
Subject: [PATCH 15/46] Ignore specific spotbugs errors not the number
---
pom.xml | 2 -
src/conf/spotbugs-exclude-filter.xml | 69 ++++++++++++++++++++++++++--
2 files changed, 66 insertions(+), 5 deletions(-)
diff --git a/pom.xml b/pom.xml
index 833a7f1747..2035b710b3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -330,8 +330,6 @@
Normal
Default
src/conf/spotbugs-exclude-filter.xml
-
- 9
diff --git a/src/conf/spotbugs-exclude-filter.xml b/src/conf/spotbugs-exclude-filter.xml
index 0698d4fa45..f917b60c7f 100644
--- a/src/conf/spotbugs-exclude-filter.xml
+++ b/src/conf/spotbugs-exclude-filter.xml
@@ -62,10 +62,29 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -91,4 +110,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From 7e5e7d75ded63610469dc59f7a5c37792423005c Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 17 Dec 2023 10:27:58 -0500
Subject: [PATCH 16/46] Better Javadoc
---
src/main/java/org/apache/bcel/classfile/JavaClass.java | 6 +++---
src/main/java/org/apache/bcel/generic/ArrayType.java | 2 +-
.../java/org/apache/bcel/generic/ExceptionThrower.java | 2 +-
src/main/java/org/apache/bcel/generic/INVOKEDYNAMIC.java | 4 ++--
src/main/java/org/apache/bcel/generic/ObjectType.java | 4 ++--
src/main/java/org/apache/bcel/generic/ReferenceType.java | 8 ++++----
src/main/java/org/apache/bcel/generic/Type.java | 4 ++--
src/main/java/org/apache/bcel/verifier/VerifyDialog.java | 4 ++--
.../org/apache/bcel/verifier/statics/Pass2Verifier.java | 2 +-
.../bcel/verifier/structurals/ExceptionHandler.java | 2 +-
.../apache/bcel/verifier/structurals/GenericArray.java | 2 +-
11 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/JavaClass.java b/src/main/java/org/apache/bcel/classfile/JavaClass.java
index 210441f9ff..067a9f53c1 100644
--- a/src/main/java/org/apache/bcel/classfile/JavaClass.java
+++ b/src/main/java/org/apache/bcel/classfile/JavaClass.java
@@ -634,7 +634,7 @@ public String getSourceFilePath() {
}
/**
- * @return the superclass for this JavaClass object, or null if this is java.lang.Object
+ * @return the superclass for this JavaClass object, or null if this is {@link Object}
* @throws ClassNotFoundException if the superclass can't be found
*/
public JavaClass getSuperClass() throws ClassNotFoundException {
@@ -658,8 +658,8 @@ public JavaClass[] getSuperClasses() throws ClassNotFoundException {
}
/**
- * returns the super class name of this class. In the case that this class is java.lang.Object, it will return itself
- * (java.lang.Object). This is probably incorrect but isn't fixed at this time to not break existing clients.
+ * returns the super class name of this class. In the case that this class is {@link Object}, it will return itself
+ * ({@link Object}). This is probably incorrect but isn't fixed at this time to not break existing clients.
*
* @return Superclass name.
*/
diff --git a/src/main/java/org/apache/bcel/generic/ArrayType.java b/src/main/java/org/apache/bcel/generic/ArrayType.java
index 6b846a3ccd..d0c7501b32 100644
--- a/src/main/java/org/apache/bcel/generic/ArrayType.java
+++ b/src/main/java/org/apache/bcel/generic/ArrayType.java
@@ -39,7 +39,7 @@ public ArrayType(final byte type, final int dimensions) {
/**
* Convenience constructor for reference array type, e.g. Object[]
*
- * @param className complete name of class (java.lang.String, e.g.)
+ * @param className complete name of class ({@link String}, for example)
* @param dimensions array dimensions
*/
public ArrayType(final String className, final int dimensions) {
diff --git a/src/main/java/org/apache/bcel/generic/ExceptionThrower.java b/src/main/java/org/apache/bcel/generic/ExceptionThrower.java
index 8fa73e76f9..b21c620135 100644
--- a/src/main/java/org/apache/bcel/generic/ExceptionThrower.java
+++ b/src/main/java/org/apache/bcel/generic/ExceptionThrower.java
@@ -18,7 +18,7 @@
/**
* Denote an instruction that may throw a run-time or a linking exception (or both) during execution. This is not quite
- * the truth as such; because all instructions may throw an java.lang.VirtualMachineError. These exceptions are omitted.
+ * the truth as such; because all instructions may throw a {@link VirtualMachineError}. These exceptions are omitted.
*
* The Lava Language Specification specifies exactly which RUN-TIME and which LINKING exceptions each
* instruction may throw which is reflected by the implementers. Due to the structure of the JVM specification, it may
diff --git a/src/main/java/org/apache/bcel/generic/INVOKEDYNAMIC.java b/src/main/java/org/apache/bcel/generic/INVOKEDYNAMIC.java
index dd935b79c7..d849de4bb7 100644
--- a/src/main/java/org/apache/bcel/generic/INVOKEDYNAMIC.java
+++ b/src/main/java/org/apache/bcel/generic/INVOKEDYNAMIC.java
@@ -98,11 +98,11 @@ public Class>[] getExceptions() {
}
/**
- * Since InvokeDynamic doesn't refer to a reference type, just return java.lang.Object, as that is the only type we can
+ * Since InvokeDynamic doesn't refer to a reference type, just return {@link Object}, as that is the only type we can
* say for sure the reference will be.
*
* @param cpg the ConstantPoolGen used to create the instruction
- * @return an ObjectType for java.lang.Object
+ * @return an ObjectType for {@link Object}
* @since 6.1
*/
@Override
diff --git a/src/main/java/org/apache/bcel/generic/ObjectType.java b/src/main/java/org/apache/bcel/generic/ObjectType.java
index 28e2125477..95a4df3f4c 100644
--- a/src/main/java/org/apache/bcel/generic/ObjectType.java
+++ b/src/main/java/org/apache/bcel/generic/ObjectType.java
@@ -22,7 +22,7 @@
import org.apache.bcel.classfile.Utility;
/**
- * Denotes reference such as java.lang.String.
+ * Denotes reference such as {@link String}.
*/
public class ObjectType extends ReferenceType {
@@ -42,7 +42,7 @@ public static ObjectType getInstance(final String className) {
/**
* Constructs a new instance.
*
- * @param className fully qualified class name, e.g. java.lang.String
+ * @param className fully qualified class name, e.g. {@link String}
*/
public ObjectType(final String className) {
super(Const.T_REFERENCE, "L" + Utility.packageToPath(className) + ";");
diff --git a/src/main/java/org/apache/bcel/generic/ReferenceType.java b/src/main/java/org/apache/bcel/generic/ReferenceType.java
index 71f0d43423..546bf0ae19 100644
--- a/src/main/java/org/apache/bcel/generic/ReferenceType.java
+++ b/src/main/java/org/apache/bcel/generic/ReferenceType.java
@@ -56,8 +56,8 @@ public ReferenceType firstCommonSuperclass(final ReferenceType t) throws ClassNo
return this;
/*
* TODO: Above sounds a little arbitrary. On the other hand, there is no object referenced by Type.NULL so we can also
- * say all the objects referenced by Type.NULL were derived from java.lang.Object. However, the Java Language's
- * "instanceof" operator proves us wrong: "null" is not referring to an instance of java.lang.Object :)
+ * say all the objects referenced by Type.NULL were derived from {@link Object}. However, the Java Language's
+ * "instanceof" operator proves us wrong: "null" is not referring to an instance of {@link Object} :)
*/
}
if (this instanceof ArrayType || t instanceof ArrayType) {
@@ -87,8 +87,8 @@ public ReferenceType getFirstCommonSuperclass(final ReferenceType t) throws Clas
return this;
/*
* TODO: Above sounds a little arbitrary. On the other hand, there is no object referenced by Type.NULL so we can also
- * say all the objects referenced by Type.NULL were derived from java.lang.Object. However, the Java Language's
- * "instanceof" operator proves us wrong: "null" is not referring to an instance of java.lang.Object :)
+ * say all the objects referenced by Type.NULL were derived from {@link Object}. However, the Java Language's
+ * "instanceof" operator proves us wrong: "null" is not referring to an instance of {@link Object} :)
*/
}
/* This code is from a bug report by Konstantin Shagin */
diff --git a/src/main/java/org/apache/bcel/generic/Type.java b/src/main/java/org/apache/bcel/generic/Type.java
index 71b28383de..76b833907f 100644
--- a/src/main/java/org/apache/bcel/generic/Type.java
+++ b/src/main/java/org/apache/bcel/generic/Type.java
@@ -173,7 +173,7 @@ public static String getSignature(final java.lang.reflect.Method meth) {
}
/**
- * Convert runtime java.lang.Class to BCEL Type object.
+ * Convert runtime {@link Class} to BCEL Type object.
*
* @param cls Java class
* @return corresponding Type object
@@ -252,7 +252,7 @@ public static Type getType(final String signature) throws StringIndexOutOfBounds
}
/**
- * Convert runtime java.lang.Class[] to BCEL Type objects.
+ * Convert runtime {@code java.lang.Class[]} to BCEL Type objects.
*
* @param classes an array of runtime class objects
* @return array of corresponding Type objects
diff --git a/src/main/java/org/apache/bcel/verifier/VerifyDialog.java b/src/main/java/org/apache/bcel/verifier/VerifyDialog.java
index 9d316b02ca..88ef3b3ffd 100644
--- a/src/main/java/org/apache/bcel/verifier/VerifyDialog.java
+++ b/src/main/java/org/apache/bcel/verifier/VerifyDialog.java
@@ -178,9 +178,9 @@ public VerifyDialog(final Frame owner, final String title, final boolean modal)
}
/**
- * Use this constructor if you want a possibility to verify other class files than java.lang.Object.
+ * Use this constructor if you want a possibility to verify other class files than {@link Object}.
*
- * @param fullyQualifiedClassName java.lang.String
+ * @param fullyQualifiedClassName "java.lang.String"
*/
public VerifyDialog(String fullyQualifiedClassName) {
final int dotclasspos = fullyQualifiedClassName.lastIndexOf(JavaClass.EXTENSION);
diff --git a/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java b/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
index 810630eb74..34f9f5f35f 100644
--- a/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
+++ b/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
@@ -1321,7 +1321,7 @@ public VerificationResult do_verify() {
/**
* Ensures that every class has a super class and that final classes are not subclassed. This means, the class
- * this Pass2Verifier operates on has proper super classes (transitively) up to java.lang.Object. The reason for really
+ * this Pass2Verifier operates on has proper super classes (transitively) up to {@link Object}. The reason for really
* loading (and Pass1-verifying) all of those classes here is that we need them in Pass2 anyway to verify no final
* methods are overridden (that could be declared anywhere in the ancestor hierarchy).
*
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandler.java b/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandler.java
index b33e43bbd9..d501d097c3 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandler.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandler.java
@@ -20,7 +20,7 @@
import org.apache.bcel.generic.ObjectType;
/**
- * This class represents an exception handler; that is, an ObjectType representing a subclass of java.lang.Throwable and
+ * This class represents an exception handler; that is, an ObjectType representing a subclass of {@link Throwable} and
* the instruction the handler starts off (represented by an InstructionContext).
*/
public class ExceptionHandler {
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/GenericArray.java b/src/main/java/org/apache/bcel/verifier/structurals/GenericArray.java
index 4cd699ac7d..0fa6e412f0 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/GenericArray.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/GenericArray.java
@@ -20,7 +20,7 @@
/**
* A placeholder class that can be used to create an ObjectType of which has some of the properties arrays have. They
- * implement java.lang.Cloneable and java.io.Serializable and they extend java.lang.Object.
+ * implement {@link Cloneable} and {@link java.io.Serializable} and they extend {@link Object}.
*/
public class GenericArray implements Cloneable, Serializable {
From c799e77afb4e23dd190f459126b3a29f98f45f50 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 17 Dec 2023 14:27:37 -0500
Subject: [PATCH 17/46] Better Javadoc
---
src/examples/ProxyCreator.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/examples/ProxyCreator.java b/src/examples/ProxyCreator.java
index 4f80fbcf8c..995f607191 100644
--- a/src/examples/ProxyCreator.java
+++ b/src/examples/ProxyCreator.java
@@ -34,7 +34,7 @@
import org.apache.bcel.generic.Type;
/**
- * Dynamically creates and uses a proxy for {@code java.awt.event.ActionListener} via the class loader mechanism if
+ * Dynamically creates and uses a proxy for {@link java.awt.event.ActionListener} via the class loader mechanism if
* called with
*
*
@@ -45,7 +45,7 @@
* however in big ugly class name, so for many cases it will be more sufficient to put some clever creation code into
* the class loader.
*
- * This is comparable to the mechanism provided via {@code java.lang.reflect.Proxy}, but much more flexible.
+ * This is comparable to the mechanism provided via {@link java.lang.reflect.Proxy}, but much more flexible.
*
*
* @see org.apache.bcel.util.JavaWrapper
From 4bb23a8d4742c4349df31278e73a7573271eaf97 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Thu, 21 Dec 2023 22:22:38 -0500
Subject: [PATCH 18/46] Update github/codeql-action/upload-sarif version
reference
---
.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 512e4a1acf..d1049c90a6 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@cdcdbb579706841c47f7063dda365e292e5cad7a # 2.13.4
+ uses: github/codeql-action/upload-sarif@b374143c1149a9115d881581d29b8390bbcbb59c # 3.22.11
with:
sarif_file: results.sarif
From 932539819d8a800668d772c82b2ab9c0e1746b82 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 22 Dec 2023 15:58:02 -0500
Subject: [PATCH 19/46] Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.21 to
1.9.22 (#252)
Bumps [org.jetbrains.kotlin:kotlin-stdlib](https://github.com/JetBrains/kotlin) from 1.9.21 to 1.9.22.
- [Release notes](https://github.com/JetBrains/kotlin/releases)
- [Changelog](https://github.com/JetBrains/kotlin/blob/master/ChangeLog.md)
- [Commits](https://github.com/JetBrains/kotlin/compare/v1.9.21...v1.9.22)
---
updated-dependencies:
- dependency-name: org.jetbrains.kotlin:kotlin-stdlib
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 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 2035b710b3..a8ea860b96 100644
--- a/pom.xml
+++ b/pom.xml
@@ -510,7 +510,7 @@
org.jetbrains.kotlin
kotlin-stdlib
- 1.9.21
+ 1.9.22
test
From 3e7592bbc1473cfc932f9eba4c24a8f64ebeb26c Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Fri, 22 Dec 2023 15:58:56 -0500
Subject: [PATCH 20/46] Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.21 to
1.9.22 #252
---
src/changes/changes.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ca738aedc6..6e8d284b1f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -70,6 +70,7 @@ The type attribute can be add,update,fix,remove.
Bump GitHub various actions for CI builds.
Bump jna.version from 5.13.0 to 5.14.0 #250.
+ Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.21 to 1.9.22 #252.
From 5c74d0e56dfea2a3f795b07337a22fcf0923994a Mon Sep 17 00:00:00 2001
From: Sebb
Date: Sat, 23 Dec 2023 00:28:11 +0000
Subject: [PATCH 21/46] Fix version comment [skip ci]
---
.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 d1049c90a6..a6c5f2cfdb 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@c7d193f32edcb7bfad88892161225aeda64e9392 # 3.1.0
+ uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0
with:
name: SARIF file
path: results.sarif
From 2355925db95960c6de566964fefc1b52da5463a5 Mon Sep 17 00:00:00 2001
From: Sebb
Date: Sat, 23 Dec 2023 00:28:57 +0000
Subject: [PATCH 22/46] Bump codeql action
---
.github/workflows/codeql-analysis.yml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index 2e3c64ca25..23a4d3195c 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@cdcdbb579706841c47f7063dda365e292e5cad7a # v2.3.6
+ uses: github/codeql-action/init@012739e5082ff0c22ca6d6ab32e07c36df03c4a4 # v3.22.12
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@cdcdbb579706841c47f7063dda365e292e5cad7a # v2.3.6
+ uses: github/codeql-action/autobuild@012739e5082ff0c22ca6d6ab32e07c36df03c4a4 # v3.22.12
# ℹ️ 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@cdcdbb579706841c47f7063dda365e292e5cad7a # v2.3.6
+ uses: github/codeql-action/analyze@012739e5082ff0c22ca6d6ab32e07c36df03c4a4 # v3.22.12
From 8c365e42b05647ae69b184381c3d34b2323e81de Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 24 Dec 2023 21:28:33 -0500
Subject: [PATCH 23/46] Update NOTICE file for 2024
---
NOTICE.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/NOTICE.txt b/NOTICE.txt
index b1184ffb0d..f3ff767ae2 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -1,5 +1,5 @@
Apache Commons BCEL
-Copyright 2004-2023 The Apache Software Foundation
+Copyright 2004-2024 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (https://www.apache.org/).
From 20cf556aad679dc4fc30a1cc027b138070fe8812 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 29 Dec 2023 15:00:30 -0500
Subject: [PATCH 24/46] Bump github/codeql-action from 3.22.11 to 3.22.12
(#253)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.22.11 to 3.22.12.
- [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/v3.22.11...012739e5082ff0c22ca6d6ab32e07c36df03c4a4)
---
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/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 a6c5f2cfdb..4316d75c89 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@b374143c1149a9115d881581d29b8390bbcbb59c # 3.22.11
+ uses: github/codeql-action/upload-sarif@012739e5082ff0c22ca6d6ab32e07c36df03c4a4 # 3.22.12
with:
sarif_file: results.sarif
From fbc58b1d4693048c50849be2027a9b526ab4c462 Mon Sep 17 00:00:00 2001
From: "Gary David Gregory (Code signing key)"
Date: Thu, 4 Jan 2024 08:45:34 -0500
Subject: [PATCH 25/46] Javadoc
---
src/main/java/org/apache/bcel/classfile/Node.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/bcel/classfile/Node.java b/src/main/java/org/apache/bcel/classfile/Node.java
index 1fecc0cf9e..51a9bfbec3 100644
--- a/src/main/java/org/apache/bcel/classfile/Node.java
+++ b/src/main/java/org/apache/bcel/classfile/Node.java
@@ -21,5 +21,5 @@
*/
public interface Node {
- void accept(Visitor obj);
+ void accept(Visitor visitor);
}
From 566b468ecec8f01c67a6e387082c02993aff00ec Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 5 Jan 2024 17:22:21 -0500
Subject: [PATCH 26/46] Bump org.apache.commons:commons-exec from 1.3 to 1.4.0
(#255)
Bumps org.apache.commons:commons-exec from 1.3 to 1.4.0.
---
updated-dependencies:
- dependency-name: org.apache.commons:commons-exec
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 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index a8ea860b96..e81d84a313 100644
--- a/pom.xml
+++ b/pom.xml
@@ -483,7 +483,7 @@
org.apache.commons
commons-exec
- 1.3
+ 1.4.0
test
From f5f53f66ceb35b37ab0f66ca8de74d75d6049fbf Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Fri, 5 Jan 2024 17:22:59 -0500
Subject: [PATCH 27/46] Bump org.apache.commons:commons-exec from 1.3 to 1.4.0
#255
---
src/changes/changes.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6e8d284b1f..e41d791b95 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -71,6 +71,7 @@ The type attribute can be add,update,fix,remove.
Bump GitHub various actions for CI builds.
Bump jna.version from 5.13.0 to 5.14.0 #250.
Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.21 to 1.9.22 #252.
+ Bump org.apache.commons:commons-exec from 1.3 to 1.4.0 #255.
From 25ca2777270891b8a54c50bf6bdd217472ce8649 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Fri, 5 Jan 2024 17:23:35 -0500
Subject: [PATCH 28/46] Replace internal use of StringBuffer with StringBuilder
---
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 e41d791b95..1bc12ed7b0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -66,7 +66,7 @@ The type attribute can be add,update,fix,remove.
- Replace internal StringBuffer with StringBuilder.
+ Replace internal use of StringBuffer with StringBuilder.
Bump GitHub various actions for CI builds.
Bump jna.version from 5.13.0 to 5.14.0 #250.
From 2b2293a9274fa8192901e137e45c609ae3c1211a Mon Sep 17 00:00:00 2001
From: Guillaume Toison <86775455+gtoison@users.noreply.github.com>
Date: Sat, 6 Jan 2024 21:25:04 +0100
Subject: [PATCH 29/46] Tests and proposed fix for BCEL-370 (#254)
* Tests for BCEL-370
* Proposed fix for BCEL-370
* Added a test calling LDC.getType() for a CONSTANT_Dynamic
* Removed StringRepresentation.visitNestHost and a verifier test sample
* Removed unused import
* Fixed the checkstyle violations (lines too long)
* Removed trailing spaces
* test: verify that we reject constants unsupported by LDC
* test: downgraded mockito to 4. so the build can run on jdk 8
Mockito 4 can't mock final method classes and methods, modified the test
to use normal objects
---
pom.xml | 14 ++
.../java/org/apache/bcel/generic/LDC.java | 5 +
.../bcel/verifier/statics/Pass3aVerifier.java | 6 +-
.../structurals/ExecutionVisitor.java | 4 +
.../structurals/InstConstraintVisitor.java | 10 +-
.../ConstantPoolModuleToStringTestCase.java | 12 +-
.../org/apache/bcel/generic/TypeTestCase.java | 3 +-
.../bcel/verifier/JiraBcel370TestCase.java | 79 ++++++++++
.../statics/Pass3aVerifierTestCase.java | 135 ++++++++++++++++++
.../InstConstraintVisitorTestCase.java | 52 +++++++
src/test/resources/com/foo/Foo.class | Bin 0 -> 770 bytes
...JavaLanguageParser$ClassBlockContext.class | Bin 0 -> 2624 bytes
12 files changed, 314 insertions(+), 6 deletions(-)
create mode 100644 src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
create mode 100644 src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
create mode 100644 src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
create mode 100644 src/test/resources/com/foo/Foo.class
create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser$ClassBlockContext.class
diff --git a/pom.xml b/pom.xml
index e81d84a313..e830ae430b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,6 +63,8 @@
BCEL
12314220
+ 4.8.1
+ 3.25.1
5.14.0
false
@@ -450,6 +452,18 @@
junit-jupiter
test
+
+ org.mockito
+ mockito-core
+ ${mockito.version}
+ test
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
net.java.dev.jna
jna
diff --git a/src/main/java/org/apache/bcel/generic/LDC.java b/src/main/java/org/apache/bcel/generic/LDC.java
index 5969b15782..559d110851 100644
--- a/src/main/java/org/apache/bcel/generic/LDC.java
+++ b/src/main/java/org/apache/bcel/generic/LDC.java
@@ -89,6 +89,8 @@ public Type getType(final ConstantPoolGen cpg) {
return Type.INT;
case org.apache.bcel.Const.CONSTANT_Class:
return Type.CLASS;
+ case org.apache.bcel.Const.CONSTANT_Dynamic:
+ return Type.OBJECT;
default: // Never reached
throw new IllegalArgumentException("Unknown or invalid constant type at " + super.getIndex());
}
@@ -109,6 +111,9 @@ public Object getValue(final ConstantPoolGen cpg) {
final int nameIndex = ((org.apache.bcel.classfile.ConstantClass) c).getNameIndex();
c = cpg.getConstantPool().getConstant(nameIndex);
return Type.getType(Type.internalTypeNameToSignature(((org.apache.bcel.classfile.ConstantUtf8) c).getBytes()));
+ case org.apache.bcel.Const.CONSTANT_Dynamic:
+ // Really not sure what to return here, maybe a BootstrapMethod instance but how do we get it?
+ return c;
default: // Never reached
throw new IllegalArgumentException("Unknown or invalid constant type at " + super.getIndex());
}
diff --git a/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java b/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java
index 3764ebae74..25def60f6e 100644
--- a/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java
+++ b/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java
@@ -28,6 +28,7 @@
import org.apache.bcel.classfile.ConstantCP;
import org.apache.bcel.classfile.ConstantClass;
import org.apache.bcel.classfile.ConstantDouble;
+import org.apache.bcel.classfile.ConstantDynamic;
import org.apache.bcel.classfile.ConstantFieldref;
import org.apache.bcel.classfile.ConstantFloat;
import org.apache.bcel.classfile.ConstantInteger;
@@ -651,9 +652,10 @@ public void visitLDC(final LDC ldc) {
final Constant c = constantPoolGen.getConstant(ldc.getIndex());
if (c instanceof ConstantClass) {
addMessage("Operand of LDC or LDC_W is CONSTANT_Class '" + tostring(c) + "' - this is only supported in JDK 1.5 and higher.");
- } else if (!(c instanceof ConstantInteger || c instanceof ConstantFloat || c instanceof ConstantString)) {
+ } else if (!(c instanceof ConstantInteger || c instanceof ConstantFloat || c instanceof ConstantString || c instanceof ConstantDynamic)) {
constraintViolated(ldc,
- "Operand of LDC or LDC_W must be one of CONSTANT_Integer, CONSTANT_Float or CONSTANT_String, but is '" + tostring(c) + "'.");
+ "Operand of LDC or LDC_W must be one of CONSTANT_Integer, CONSTANT_Float, CONSTANT_String or CONSTANT_Dynamic but is '"
+ + tostring(c) + "'.");
}
}
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java b/src/main/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java
index 36c9af0cd1..d06665588c 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java
@@ -20,6 +20,7 @@
import org.apache.bcel.classfile.Constant;
import org.apache.bcel.classfile.ConstantClass;
import org.apache.bcel.classfile.ConstantDouble;
+import org.apache.bcel.classfile.ConstantDynamic;
import org.apache.bcel.classfile.ConstantFloat;
import org.apache.bcel.classfile.ConstantInteger;
import org.apache.bcel.classfile.ConstantLong;
@@ -1054,6 +1055,9 @@ public void visitLDC(final LDC o) {
if (c instanceof ConstantClass) {
stack().push(Type.CLASS);
}
+ if (c instanceof ConstantDynamic) {
+ stack().push(Type.OBJECT);
+ }
}
/** Symbolically executes the corresponding Java Virtual Machine instruction. */
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
index e41051b862..0b637e6dc8 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
@@ -21,6 +21,7 @@
import org.apache.bcel.classfile.Constant;
import org.apache.bcel.classfile.ConstantClass;
import org.apache.bcel.classfile.ConstantDouble;
+import org.apache.bcel.classfile.ConstantDynamic;
import org.apache.bcel.classfile.ConstantFieldref;
import org.apache.bcel.classfile.ConstantFloat;
import org.apache.bcel.classfile.ConstantInteger;
@@ -2030,9 +2031,14 @@ public void visitLDC(final LDC o) {
// visitCPInstruction is called first.
final Constant c = cpg.getConstant(o.getIndex());
- if (!(c instanceof ConstantInteger || c instanceof ConstantFloat || c instanceof ConstantString || c instanceof ConstantClass)) {
+ if (!(c instanceof ConstantInteger
+ || c instanceof ConstantFloat
+ || c instanceof ConstantString
+ || c instanceof ConstantClass
+ || c instanceof ConstantDynamic)) {
constraintViolated(o,
- "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float, a CONSTANT_String or a CONSTANT_Class, but is '" + c + "'.");
+ "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float, a CONSTANT_String, a CONSTANT_Class, or a CONSTANT_Dynamic but is '"
+ + c + "'.");
}
}
diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
index b482efe0de..8048b705cb 100644
--- a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
@@ -385,7 +385,17 @@ public void visitModuleRequires(final ModuleRequires constantModule) {
append(constantModule);
append(constantModule.toString(pool));
final String s = constantModule.toString(pool).trim();
- assertTrue(StringUtils.startsWithAny(s, "jdk.", "java.", "org.junit", "org.apiguardian.api", "org.opentest4j"), s);
+ boolean condition = StringUtils.startsWithAny(s,
+ "jdk.",
+ "java.",
+ "org.junit",
+ "org.apiguardian.api",
+ "org.opentest4j",
+ "net.bytebuddy",
+ "com.sun.jna",
+ "junit",
+ "org.hamcrest");
+ assertTrue(condition, s);
}
@Override
diff --git a/src/test/java/org/apache/bcel/generic/TypeTestCase.java b/src/test/java/org/apache/bcel/generic/TypeTestCase.java
index 4fd5c1166c..8378058990 100644
--- a/src/test/java/org/apache/bcel/generic/TypeTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/TypeTestCase.java
@@ -78,7 +78,8 @@ public void testInternalTypeNametoSignature() {
"org/apache/bcel/classfile/Method",
"org/apache/bcel/classfile/Synthetic",
"org/apache/bcel/generic/ConstantPoolGen",
- "org/apache/bcel/generic/MethodGen"})
+ "org/apache/bcel/generic/MethodGen",
+ "com/foo/Foo"})
// @formatter:on
public void testLDC(final String className) throws Exception {
final JavaClass jc = Repository.lookupClass(className);
diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
new file mode 100644
index 0000000000..ac9e09e4f8
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
@@ -0,0 +1,79 @@
+/*
+ * 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.verifier;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.bcel.AbstractTestCase;
+import org.apache.bcel.classfile.ClassParser;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.EmptyVisitor;
+import org.apache.bcel.generic.Instruction;
+import org.apache.bcel.generic.LDC;
+import org.apache.bcel.generic.MethodGen;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+/**
+ * Tests BCEL-370.
+ */
+public class JiraBcel370TestCase extends AbstractTestCase {
+ @ParameterizedTest
+ @ValueSource(strings = {
+ // @formatter:off
+ "com.foo.Foo"
+ })
+ // @formatter:on
+ public void testVerify(String className) throws ClassNotFoundException {
+ // Without the changes to the verifier this fails because it doesn't allow LDC CONSTANT_Dynamic
+ Verifier.verifyType(className);
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {
+ // @formatter:off
+ "target/test-classes/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser$ClassBlockContext.class",
+ "target/test-classes/com/foo/Foo.class"
+ })
+ // @formatter:on
+ public void testLdcGetType(final String classFileName) throws Exception {
+ try (FileInputStream file = new FileInputStream(classFileName)) {
+ final ClassParser parser = new ClassParser(file, new File(classFileName).getName());
+ JavaClass clazz = parser.parse();
+
+ Method[] methods = clazz.getMethods();
+
+ ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool());
+ MethodGen methodGen = new MethodGen(methods[0], classFileName, cp);
+
+ // The first instruction is an LDC CONSTANT_Dynamic added by Jacoco
+ Instruction instruction = methodGen.getInstructionList().getInstructions()[0];
+
+ instruction.accept(new EmptyVisitor() {
+ @Override
+ public void visitLDC(LDC ldc) {
+ // Without the change to LDC.getType() this fails because the tag is CONSTANT_Dynamic
+ ldc.getType(cp);
+ }
+ });
+ }
+ }
+}
diff --git a/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
new file mode 100644
index 0000000000..7128b235c4
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.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.verifier.statics;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.stream.Stream;
+
+import org.apache.bcel.Const;
+import org.apache.bcel.Repository;
+import org.apache.bcel.classfile.Attribute;
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.CodeException;
+import org.apache.bcel.classfile.Constant;
+import org.apache.bcel.classfile.ConstantDouble;
+import org.apache.bcel.classfile.ConstantFieldref;
+import org.apache.bcel.classfile.ConstantInterfaceMethodref;
+import org.apache.bcel.classfile.ConstantInvokeDynamic;
+import org.apache.bcel.classfile.ConstantLong;
+import org.apache.bcel.classfile.ConstantMethodHandle;
+import org.apache.bcel.classfile.ConstantMethodType;
+import org.apache.bcel.classfile.ConstantModule;
+import org.apache.bcel.classfile.ConstantNameAndType;
+import org.apache.bcel.classfile.ConstantPackage;
+import org.apache.bcel.classfile.ConstantPool;
+import org.apache.bcel.classfile.ConstantUtf8;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.util.SyntheticRepository;
+import org.apache.bcel.verifier.VerificationResult;
+import org.apache.bcel.verifier.Verifier;
+import org.apache.bcel.verifier.VerifierFactory;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+class Pass3aVerifierTestCase {
+ private Verifier verifier;
+ private org.apache.bcel.util.Repository repository;
+ private ConstantPool cp;
+ private JavaClass javaClass;
+
+ @BeforeEach
+ void setup() throws ClassNotFoundException {
+ String className = "org.apache.bcel.verifier.statics.Pass3aVerifierTestCase.foo";
+
+ verifier = spy(VerifierFactory.getVerifier(className));
+ repository = mock(org.apache.bcel.util.Repository.class);
+ cp = mock(ConstantPool.class);
+ javaClass = mock(JavaClass.class);
+
+ // Mock the verifier
+ doReturn(VerificationResult.VR_OK).when(verifier).doPass2();
+
+ // Mock the repository
+ Repository.setRepository(repository);
+ when(repository.loadClass(className)).thenReturn(javaClass);
+
+ // Mock the constant pool
+ when(cp.getConstantPool()).thenReturn(new Constant[] {new ConstantModule(0)});
+
+ // Mock the java class
+ when(javaClass.getConstantPool()).thenReturn(cp);
+ }
+
+ @AfterAll
+ public static void restoreRepository() {
+ // We have set our mock repository, revert the change
+ Repository.setRepository(SyntheticRepository.getInstance());
+ }
+
+ public static Stream constantsNotSupportedByLdc() {
+ return Stream.of(
+ new ConstantFieldref(0, 0),
+ new ConstantInterfaceMethodref(0, 0),
+ new ConstantInvokeDynamic(0, 0),
+ new ConstantMethodHandle(0, 0),
+ new ConstantDouble(0D),
+ new ConstantLong(0L),
+ new ConstantMethodHandle(0, 0),
+ new ConstantMethodType(0),
+ new ConstantModule(0),
+ new ConstantNameAndType(0, 0),
+ new ConstantPackage(0),
+ new ConstantUtf8("constant")
+ );
+ }
+
+ @ParameterizedTest
+ @MethodSource("constantsNotSupportedByLdc")
+ public void rejectLdcConstant(Constant constant) {
+ // LDC the constant 0 and then return
+ byte[] methodCode = new byte[] {
+ Const.LDC,
+ 0,
+ 0,
+ (byte) Const.RETURN,
+ };
+
+ Code code = new Code(0, 0, 0, 0, methodCode, new CodeException[0], new Attribute[0], cp);
+
+ when(cp.getConstantPool()).thenReturn(new Constant[] {constant});
+
+ Attribute[] attributes = new Attribute[] {code};
+ Method method = new Method(0, 0, 0, attributes, cp);
+
+ when(javaClass.getMethods()).thenReturn(new Method[] {method});
+
+ Pass3aVerifier pass3aVerifier = new Pass3aVerifier(verifier, 0);
+ VerificationResult verificationResult = pass3aVerifier.do_verify();
+
+ assertThat(verificationResult.getStatus()).isEqualTo(VerificationResult.VERIFIED_REJECTED);
+ assertThat(verificationResult.getMessage()).startsWith("Instruction ldc[18](2) 0 constraint violated: Operand of LDC");
+ }
+}
+
diff --git a/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
new file mode 100644
index 0000000000..7b12a62be8
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
@@ -0,0 +1,52 @@
+/*
+ * 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.verifier.structurals;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.bcel.classfile.Constant;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.LDC;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class InstConstraintVisitorTestCase {
+ private ConstantPoolGen cp;
+
+ @BeforeEach
+ public void setup() {
+ cp = mock(ConstantPoolGen.class);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.apache.bcel.verifier.statics.Pass3aVerifierTestCase#constantsNotSupportedByLdc")
+ public void rejectLdcConstantModule(Constant constant) {
+ InstConstraintVisitor visitor = new InstConstraintVisitor();
+
+ cp = mock(ConstantPoolGen.class);
+ when(cp.getConstant(0)).thenReturn(constant);
+
+ visitor.setConstantPoolGen(cp);
+
+ LDC ldc = new LDC(0);
+
+ assertThatCode(() -> visitor.visitLDC(ldc)).hasMessageStartingWith("Instruction LDC constraint violated: Referenced constant should be a");
+ }
+}
diff --git a/src/test/resources/com/foo/Foo.class b/src/test/resources/com/foo/Foo.class
new file mode 100644
index 0000000000000000000000000000000000000000..f405e5fe2098b6c4f70e417eb7197d98fa8858d9
GIT binary patch
literal 770
zcmYjO-EI;=7(D|E3tL(!BCS?!)v7?zy{I=0YN9ob7+Oe*T(lQvfPpSucA91ByZ8=X
zXrj@WXuS3Xd>iB0g`{LN-`{?7zVn^=^Y6zm0MGH*LJV;eMg|Ea1#%;KDQ#DJL%Z1>
zsa_zEeCBvg@IoM7DtFRIA#K9SUmWQ~LlRdA;JE$Pd#3Y5i9?72W={mU!9F-bZi#gtJ`Xu9|E&v_79+)E3%~
z1K;t6iPA0YT=}89bxM5L>o7p5bu7VF9V42kwW-Z2X`a*u|
zH|`x)zClzrzQU}=jrM2OW6093uqVmSg2_CE9Bai0w}4gTnGqqv7r4eaLAmGzi`Qwx
zL3=Qw3)yH;qw)pjj$yPv^4Dxel8s4T3$Zhd!ATKz&I(^*4pSsd$k!_1e*Qt?J9a)X
Q3o(k3T|<>V#JUCi2Ui=Jr2qf`
literal 0
HcmV?d00001
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser$ClassBlockContext.class b/src/test/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser$ClassBlockContext.class
new file mode 100644
index 0000000000000000000000000000000000000000..c5da924abfebdf3de76ed1fa0dbc5d639a84429f
GIT binary patch
literal 2624
zcmcImTUQ%Z6#h;UG9d|trbv<2OBFR2=va!SHj#UgUroM3tM
z#s8pd`5*M9ULIWd>Z?D+XI<_|rZ@_8Ef)BY*=P2d^X+f%voHDWub+PbFojPI+@q^HF*O|NCo6KcWbt(Isp
ztY>o-TQLh|i
z;o5Xsj+UyJt8|jZr9?5;w)cdsDR#y|cb8%8JXj1v|4y94=8NQ+I0sItU|Gd!qS05=
z+}>a1%^(ANYfjzcx~(WhS4-A|lhmir<9lEyN7fjUHQ83SSaSUQzkafIZu?8bV0x%P0}c$WZvAwpEko)hb)h%ft~jpyQZ|%59XiGG8QrDZJVU1`T@r+6$$jBbiDb)Xojk2C
zMYDcSNZ7J@xTIu*+Ha@W{)q@f{jz#eXr7#2==rnT>3=%~m1CFauH)_~-|_n|D>gq|
zolbmegGr6!#%w4!nIWO8b9V(Q)v)vJ8a5aP=B3mvt$4HRcni14ffR89dO&{$&`-|+dYeHUQIfA@mXENqn$NK4
zb3~57#-cInJKBiAcO_1r$CG`?&^k?PI)H2R1FeT}Jpd~OV3`1HV3xpQW3iJ+{UM~x
zG14$b0;FZ486)(;4pKG$1A6j>=ZKH@#H{a0A7(Ys!5ShReIH=?s~fmUXbi96b=vct
z{W3t!c2Ntz!uT4Q!V!%8Pe?>C9w(*+TKCf0=(3LCZ93Tt_9wv^Sm}f#Nr3U>HQY=N
zhKy&Ajc4%&-Xznv=x8@wzUD2`jFKjTcLtJvR?)jpYlvL+?|{HQ$*d-RM9mL8NPC5z
kBeX|TAALk3Npg^6isY*#-=+Ns-h)NbzoJEw*^VyyH%Eo?wEzGB
literal 0
HcmV?d00001
From fdfa9a9b435ca887d0f3fcb108309c4f81553b87 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sat, 6 Jan 2024 15:26:58 -0500
Subject: [PATCH 30/46] BCEL-370
---
src/changes/changes.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1bc12ed7b0..b0b8a17b9e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -67,6 +67,7 @@ The type attribute can be add,update,fix,remove.
Replace internal use of StringBuffer with StringBuilder.
+ CONSTANT_Dynamic is not handled in LDC #254.
Bump GitHub various actions for CI builds.
Bump jna.version from 5.13.0 to 5.14.0 #250.
From e5111d66561b11a726b7a37911bcac3bcfb65a81 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sat, 6 Jan 2024 15:33:35 -0500
Subject: [PATCH 31/46] Sort members
---
.../apache/bcel/classfile/ConstantUtf8.java | 10 +--
.../bcel/verifier/JiraBcel370TestCase.java | 22 +++---
.../statics/Pass3aVerifierTestCase.java | 68 +++++++++----------
.../InstConstraintVisitorTestCase.java | 10 +--
4 files changed, 55 insertions(+), 55 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java b/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java
index edbdfef8b4..7ac35fb5a7 100644
--- a/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java
+++ b/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java
@@ -112,6 +112,11 @@ static synchronized void clearStats() {
hits = considered = skipped = created = 0;
}
+ // Avoid Spotbugs complaint about Write to static field
+ private static void countCreated() {
+ created++;
+ }
+
/**
* Gets a new or cached instance of the given value.
*
@@ -178,11 +183,6 @@ static void printStats() {
Cache.MAX_ENTRY_SIZE);
}
- // Avoid Spotbugs complaint about Write to static field
- private static void countCreated() {
- created++;
- }
-
private final String value;
/**
diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
index ac9e09e4f8..659a9abe25 100644
--- a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
@@ -36,17 +36,6 @@
* Tests BCEL-370.
*/
public class JiraBcel370TestCase extends AbstractTestCase {
- @ParameterizedTest
- @ValueSource(strings = {
- // @formatter:off
- "com.foo.Foo"
- })
- // @formatter:on
- public void testVerify(String className) throws ClassNotFoundException {
- // Without the changes to the verifier this fails because it doesn't allow LDC CONSTANT_Dynamic
- Verifier.verifyType(className);
- }
-
@ParameterizedTest
@ValueSource(strings = {
// @formatter:off
@@ -76,4 +65,15 @@ public void visitLDC(LDC ldc) {
});
}
}
+
+ @ParameterizedTest
+ @ValueSource(strings = {
+ // @formatter:off
+ "com.foo.Foo"
+ })
+ // @formatter:on
+ public void testVerify(String className) throws ClassNotFoundException {
+ // Without the changes to the verifier this fails because it doesn't allow LDC CONSTANT_Dynamic
+ Verifier.verifyType(className);
+ }
}
diff --git a/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
index 7128b235c4..7cda6a874f 100644
--- a/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
@@ -54,40 +54,6 @@
import org.junit.jupiter.params.provider.MethodSource;
class Pass3aVerifierTestCase {
- private Verifier verifier;
- private org.apache.bcel.util.Repository repository;
- private ConstantPool cp;
- private JavaClass javaClass;
-
- @BeforeEach
- void setup() throws ClassNotFoundException {
- String className = "org.apache.bcel.verifier.statics.Pass3aVerifierTestCase.foo";
-
- verifier = spy(VerifierFactory.getVerifier(className));
- repository = mock(org.apache.bcel.util.Repository.class);
- cp = mock(ConstantPool.class);
- javaClass = mock(JavaClass.class);
-
- // Mock the verifier
- doReturn(VerificationResult.VR_OK).when(verifier).doPass2();
-
- // Mock the repository
- Repository.setRepository(repository);
- when(repository.loadClass(className)).thenReturn(javaClass);
-
- // Mock the constant pool
- when(cp.getConstantPool()).thenReturn(new Constant[] {new ConstantModule(0)});
-
- // Mock the java class
- when(javaClass.getConstantPool()).thenReturn(cp);
- }
-
- @AfterAll
- public static void restoreRepository() {
- // We have set our mock repository, revert the change
- Repository.setRepository(SyntheticRepository.getInstance());
- }
-
public static Stream constantsNotSupportedByLdc() {
return Stream.of(
new ConstantFieldref(0, 0),
@@ -104,6 +70,17 @@ public static Stream constantsNotSupportedByLdc() {
new ConstantUtf8("constant")
);
}
+ @AfterAll
+ public static void restoreRepository() {
+ // We have set our mock repository, revert the change
+ Repository.setRepository(SyntheticRepository.getInstance());
+ }
+ private Verifier verifier;
+ private org.apache.bcel.util.Repository repository;
+
+ private ConstantPool cp;
+
+ private JavaClass javaClass;
@ParameterizedTest
@MethodSource("constantsNotSupportedByLdc")
@@ -131,5 +108,28 @@ public void rejectLdcConstant(Constant constant) {
assertThat(verificationResult.getStatus()).isEqualTo(VerificationResult.VERIFIED_REJECTED);
assertThat(verificationResult.getMessage()).startsWith("Instruction ldc[18](2) 0 constraint violated: Operand of LDC");
}
+
+ @BeforeEach
+ void setup() throws ClassNotFoundException {
+ String className = "org.apache.bcel.verifier.statics.Pass3aVerifierTestCase.foo";
+
+ verifier = spy(VerifierFactory.getVerifier(className));
+ repository = mock(org.apache.bcel.util.Repository.class);
+ cp = mock(ConstantPool.class);
+ javaClass = mock(JavaClass.class);
+
+ // Mock the verifier
+ doReturn(VerificationResult.VR_OK).when(verifier).doPass2();
+
+ // Mock the repository
+ Repository.setRepository(repository);
+ when(repository.loadClass(className)).thenReturn(javaClass);
+
+ // Mock the constant pool
+ when(cp.getConstantPool()).thenReturn(new Constant[] {new ConstantModule(0)});
+
+ // Mock the java class
+ when(javaClass.getConstantPool()).thenReturn(cp);
+ }
}
diff --git a/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
index 7b12a62be8..3ebc5e29a7 100644
--- a/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
@@ -30,11 +30,6 @@
public class InstConstraintVisitorTestCase {
private ConstantPoolGen cp;
- @BeforeEach
- public void setup() {
- cp = mock(ConstantPoolGen.class);
- }
-
@ParameterizedTest
@MethodSource("org.apache.bcel.verifier.statics.Pass3aVerifierTestCase#constantsNotSupportedByLdc")
public void rejectLdcConstantModule(Constant constant) {
@@ -49,4 +44,9 @@ public void rejectLdcConstantModule(Constant constant) {
assertThatCode(() -> visitor.visitLDC(ldc)).hasMessageStartingWith("Instruction LDC constraint violated: Referenced constant should be a");
}
+
+ @BeforeEach
+ public void setup() {
+ cp = mock(ConstantPoolGen.class);
+ }
}
From da48305845cf112c914fe0993c76fcc8ef43fef3 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sat, 6 Jan 2024 15:33:54 -0500
Subject: [PATCH 32/46] Remove trailing whitespace
- Use final
- Use compact array creation syntax
---
.../org/apache/bcel/classfile/Visitor.java | 2 +-
.../ConstantPoolModuleToStringTestCase.java | 2 +-
.../bcel/classfile/ConstantPoolTestCase.java | 4 +-
.../bcel/classfile/UtilityTestCase.java | 2 +-
src/test/java/org/apache/bcel/data/SWAP.java | 2 +-
.../org/apache/bcel/generic/JavaHome.java | 2 +-
.../org/apache/bcel/generic/TypeTestCase.java | 2 +-
.../apache/bcel/util/BCELifierTestCase.java | 2 +-
.../bcel/verifier/JiraBcel369TestCase.java | 2 +-
.../bcel/verifier/JiraBcel370TestCase.java | 20 ++++-----
.../statics/Pass3aVerifierTestCase.java | 44 +++++++++----------
.../InstConstraintVisitorTestCase.java | 18 ++++----
12 files changed, 51 insertions(+), 51 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/Visitor.java b/src/main/java/org/apache/bcel/classfile/Visitor.java
index 9a3388cf0d..4f4b5c2116 100644
--- a/src/main/java/org/apache/bcel/classfile/Visitor.java
+++ b/src/main/java/org/apache/bcel/classfile/Visitor.java
@@ -230,7 +230,7 @@ default void visitNestMembers(final NestMembers obj) {
* @param obj object to visit
* @since 6.8.0
*/
- default void visitStackMapType(StackMapType obj) {
+ default void visitStackMapType(final StackMapType obj) {
// empty
}
diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
index 8048b705cb..e7f08c96eb 100644
--- a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
@@ -385,7 +385,7 @@ public void visitModuleRequires(final ModuleRequires constantModule) {
append(constantModule);
append(constantModule.toString(pool));
final String s = constantModule.toString(pool).trim();
- boolean condition = StringUtils.startsWithAny(s,
+ final boolean condition = StringUtils.startsWithAny(s,
"jdk.",
"java.",
"org.junit",
diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
index 3c154facb1..3454a1a8ee 100644
--- a/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
@@ -66,7 +66,7 @@ public void testClassWithDoubleConstantPoolItem() throws ClassNotFoundException,
// Next constant pool entry will be invalid so skip it
i++;
}
- } catch (Throwable t) {
+ } catch (final Throwable t) {
t.printStackTrace();
fail();
}
@@ -92,7 +92,7 @@ public void testClassWithLongConstantPoolItem() throws ClassNotFoundException, I
// Next constant pool entry will be invalid so skip it
i++;
}
- } catch (Throwable t) {
+ } catch (final Throwable t) {
t.printStackTrace();
fail();
}
diff --git a/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java b/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java
index 8c3144b66e..54561d4cb3 100644
--- a/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java
@@ -44,7 +44,7 @@ public void testClearBit() {
@Test
public void testCodeToString() throws Exception {
final class CodeToString {
- int[][] a = new int[0][0];
+ int[][] a = {};
CodeToString() {
if (a instanceof int[][]) {
diff --git a/src/test/java/org/apache/bcel/data/SWAP.java b/src/test/java/org/apache/bcel/data/SWAP.java
index 81a291e24b..ce1e29a2bf 100644
--- a/src/test/java/org/apache/bcel/data/SWAP.java
+++ b/src/test/java/org/apache/bcel/data/SWAP.java
@@ -32,6 +32,6 @@ public static Constructor getTestConstructor(final Class theClass) throws NoSuch
return theClass.getConstructor(args);
} catch (final NoSuchMethodException e) {
}
- return theClass.getConstructor(new Class[0]);
+ return theClass.getConstructor();
}
}
diff --git a/src/test/java/org/apache/bcel/generic/JavaHome.java b/src/test/java/org/apache/bcel/generic/JavaHome.java
index e4d04d45ba..f23be5537a 100644
--- a/src/test/java/org/apache/bcel/generic/JavaHome.java
+++ b/src/test/java/org/apache/bcel/generic/JavaHome.java
@@ -68,7 +68,7 @@ public class JavaHome {
private static Stream find(final Path start, final int maxDepth, final BiPredicate matcher,
final FileVisitOption... options) {
- // TODO Apache Commons 2.14.0: Use FilesUncheck
+ // TODO Apache Commons 2.14.0: Use FilesUncheck
return Files.exists(start) ? Uncheck.apply(Files::find, start, maxDepth, matcher, options) : Stream.empty();
}
diff --git a/src/test/java/org/apache/bcel/generic/TypeTestCase.java b/src/test/java/org/apache/bcel/generic/TypeTestCase.java
index 8378058990..303a75ba4c 100644
--- a/src/test/java/org/apache/bcel/generic/TypeTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/TypeTestCase.java
@@ -91,7 +91,7 @@ public void testLDC(final String className) throws Exception {
for (final InstructionHandle instructionHandle : instructionList) {
instructionHandle.accept(new EmptyVisitor() {
@Override
- public void visitLDC(LDC obj) {
+ public void visitLDC(final LDC obj) {
assertNotNull(obj.getValue(cpg));
}
});
diff --git a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java
index 1cdeff2d9d..8ab68d6c6d 100644
--- a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java
+++ b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java
@@ -174,7 +174,7 @@ public void testHelloWorld() throws Exception {
/*
* Dumps a class using "javap" and compare with the same class recreated using BCELifier, "javac", "java" and dumped with "javap".
- *
+ *
* TODO: detect if JDK present and skip test if not
*/
@ParameterizedTest
diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java
index bfd84f28ce..5a8502d173 100644
--- a/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java
@@ -109,7 +109,7 @@ public void testCompileAndVerify() throws ClassNotFoundException {
at org.apache.bcel.verifier.structurals.Pass3bVerifier.do_verify(Pass3bVerifier.java:386)
... 74 more
* }
- *
+ *
* @throws ClassNotFoundException
*/
@Test
diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
index 659a9abe25..a92a92240f 100644
--- a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
@@ -46,19 +46,19 @@ public class JiraBcel370TestCase extends AbstractTestCase {
public void testLdcGetType(final String classFileName) throws Exception {
try (FileInputStream file = new FileInputStream(classFileName)) {
final ClassParser parser = new ClassParser(file, new File(classFileName).getName());
- JavaClass clazz = parser.parse();
-
- Method[] methods = clazz.getMethods();
-
- ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool());
- MethodGen methodGen = new MethodGen(methods[0], classFileName, cp);
-
+ final JavaClass clazz = parser.parse();
+
+ final Method[] methods = clazz.getMethods();
+
+ final ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool());
+ final MethodGen methodGen = new MethodGen(methods[0], classFileName, cp);
+
// The first instruction is an LDC CONSTANT_Dynamic added by Jacoco
- Instruction instruction = methodGen.getInstructionList().getInstructions()[0];
+ final Instruction instruction = methodGen.getInstructionList().getInstructions()[0];
instruction.accept(new EmptyVisitor() {
@Override
- public void visitLDC(LDC ldc) {
+ public void visitLDC(final LDC ldc) {
// Without the change to LDC.getType() this fails because the tag is CONSTANT_Dynamic
ldc.getType(cp);
}
@@ -72,7 +72,7 @@ public void visitLDC(LDC ldc) {
"com.foo.Foo"
})
// @formatter:on
- public void testVerify(String className) throws ClassNotFoundException {
+ public void testVerify(final String className) throws ClassNotFoundException {
// Without the changes to the verifier this fails because it doesn't allow LDC CONSTANT_Dynamic
Verifier.verifyType(className);
}
diff --git a/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
index 7cda6a874f..c368c392c4 100644
--- a/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
@@ -72,62 +72,62 @@ public static Stream constantsNotSupportedByLdc() {
}
@AfterAll
public static void restoreRepository() {
- // We have set our mock repository, revert the change
+ // We have set our mock repository, revert the change
Repository.setRepository(SyntheticRepository.getInstance());
}
private Verifier verifier;
private org.apache.bcel.util.Repository repository;
private ConstantPool cp;
-
+
private JavaClass javaClass;
-
+
@ParameterizedTest
@MethodSource("constantsNotSupportedByLdc")
- public void rejectLdcConstant(Constant constant) {
+ public void rejectLdcConstant(final Constant constant) {
// LDC the constant 0 and then return
- byte[] methodCode = new byte[] {
+ final byte[] methodCode = {
Const.LDC,
0,
0,
(byte) Const.RETURN,
};
-
- Code code = new Code(0, 0, 0, 0, methodCode, new CodeException[0], new Attribute[0], cp);
+
+ final Code code = new Code(0, 0, 0, 0, methodCode, new CodeException[0], new Attribute[0], cp);
when(cp.getConstantPool()).thenReturn(new Constant[] {constant});
-
- Attribute[] attributes = new Attribute[] {code};
- Method method = new Method(0, 0, 0, attributes, cp);
-
+
+ final Attribute[] attributes = {code};
+ final Method method = new Method(0, 0, 0, attributes, cp);
+
when(javaClass.getMethods()).thenReturn(new Method[] {method});
-
- Pass3aVerifier pass3aVerifier = new Pass3aVerifier(verifier, 0);
- VerificationResult verificationResult = pass3aVerifier.do_verify();
-
+
+ final Pass3aVerifier pass3aVerifier = new Pass3aVerifier(verifier, 0);
+ final VerificationResult verificationResult = pass3aVerifier.do_verify();
+
assertThat(verificationResult.getStatus()).isEqualTo(VerificationResult.VERIFIED_REJECTED);
assertThat(verificationResult.getMessage()).startsWith("Instruction ldc[18](2) 0 constraint violated: Operand of LDC");
}
-
+
@BeforeEach
void setup() throws ClassNotFoundException {
- String className = "org.apache.bcel.verifier.statics.Pass3aVerifierTestCase.foo";
-
+ final String className = "org.apache.bcel.verifier.statics.Pass3aVerifierTestCase.foo";
+
verifier = spy(VerifierFactory.getVerifier(className));
repository = mock(org.apache.bcel.util.Repository.class);
cp = mock(ConstantPool.class);
javaClass = mock(JavaClass.class);
-
+
// Mock the verifier
doReturn(VerificationResult.VR_OK).when(verifier).doPass2();
-
+
// Mock the repository
Repository.setRepository(repository);
when(repository.loadClass(className)).thenReturn(javaClass);
-
+
// Mock the constant pool
when(cp.getConstantPool()).thenReturn(new Constant[] {new ConstantModule(0)});
-
+
// Mock the java class
when(javaClass.getConstantPool()).thenReturn(cp);
}
diff --git a/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
index 3ebc5e29a7..72d4c04b6e 100644
--- a/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
@@ -29,22 +29,22 @@
public class InstConstraintVisitorTestCase {
private ConstantPoolGen cp;
-
+
@ParameterizedTest
@MethodSource("org.apache.bcel.verifier.statics.Pass3aVerifierTestCase#constantsNotSupportedByLdc")
- public void rejectLdcConstantModule(Constant constant) {
- InstConstraintVisitor visitor = new InstConstraintVisitor();
-
+ public void rejectLdcConstantModule(final Constant constant) {
+ final InstConstraintVisitor visitor = new InstConstraintVisitor();
+
cp = mock(ConstantPoolGen.class);
when(cp.getConstant(0)).thenReturn(constant);
-
+
visitor.setConstantPoolGen(cp);
-
- LDC ldc = new LDC(0);
-
+
+ final LDC ldc = new LDC(0);
+
assertThatCode(() -> visitor.visitLDC(ldc)).hasMessageStartingWith("Instruction LDC constraint violated: Referenced constant should be a");
}
-
+
@BeforeEach
public void setup() {
cp = mock(ConstantPoolGen.class);
From f20946d0b1d768617e34aa2ee7a69e2ff0899728 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sat, 6 Jan 2024 15:37:06 -0500
Subject: [PATCH 33/46] Use current version of Mockito 4.
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index e830ae430b..d875b2957a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,7 +63,7 @@
BCEL
12314220
- 4.8.1
+ 4.11.0
3.25.1
5.14.0
false
From f3bcd0a7e163813436472b9cfd2f6e3cf0243486 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sat, 6 Jan 2024 15:37:21 -0500
Subject: [PATCH 34/46] Revert "Remove trailing whitespace"
This reverts commit da48305845cf112c914fe0993c76fcc8ef43fef3.
---
.../org/apache/bcel/classfile/Visitor.java | 2 +-
.../ConstantPoolModuleToStringTestCase.java | 2 +-
.../bcel/classfile/ConstantPoolTestCase.java | 4 +-
.../bcel/classfile/UtilityTestCase.java | 2 +-
src/test/java/org/apache/bcel/data/SWAP.java | 2 +-
.../org/apache/bcel/generic/JavaHome.java | 2 +-
.../org/apache/bcel/generic/TypeTestCase.java | 2 +-
.../apache/bcel/util/BCELifierTestCase.java | 2 +-
.../bcel/verifier/JiraBcel369TestCase.java | 2 +-
.../bcel/verifier/JiraBcel370TestCase.java | 20 ++++-----
.../statics/Pass3aVerifierTestCase.java | 44 +++++++++----------
.../InstConstraintVisitorTestCase.java | 18 ++++----
12 files changed, 51 insertions(+), 51 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/Visitor.java b/src/main/java/org/apache/bcel/classfile/Visitor.java
index 4f4b5c2116..9a3388cf0d 100644
--- a/src/main/java/org/apache/bcel/classfile/Visitor.java
+++ b/src/main/java/org/apache/bcel/classfile/Visitor.java
@@ -230,7 +230,7 @@ default void visitNestMembers(final NestMembers obj) {
* @param obj object to visit
* @since 6.8.0
*/
- default void visitStackMapType(final StackMapType obj) {
+ default void visitStackMapType(StackMapType obj) {
// empty
}
diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
index e7f08c96eb..8048b705cb 100644
--- a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
@@ -385,7 +385,7 @@ public void visitModuleRequires(final ModuleRequires constantModule) {
append(constantModule);
append(constantModule.toString(pool));
final String s = constantModule.toString(pool).trim();
- final boolean condition = StringUtils.startsWithAny(s,
+ boolean condition = StringUtils.startsWithAny(s,
"jdk.",
"java.",
"org.junit",
diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
index 3454a1a8ee..3c154facb1 100644
--- a/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
@@ -66,7 +66,7 @@ public void testClassWithDoubleConstantPoolItem() throws ClassNotFoundException,
// Next constant pool entry will be invalid so skip it
i++;
}
- } catch (final Throwable t) {
+ } catch (Throwable t) {
t.printStackTrace();
fail();
}
@@ -92,7 +92,7 @@ public void testClassWithLongConstantPoolItem() throws ClassNotFoundException, I
// Next constant pool entry will be invalid so skip it
i++;
}
- } catch (final Throwable t) {
+ } catch (Throwable t) {
t.printStackTrace();
fail();
}
diff --git a/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java b/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java
index 54561d4cb3..8c3144b66e 100644
--- a/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java
@@ -44,7 +44,7 @@ public void testClearBit() {
@Test
public void testCodeToString() throws Exception {
final class CodeToString {
- int[][] a = {};
+ int[][] a = new int[0][0];
CodeToString() {
if (a instanceof int[][]) {
diff --git a/src/test/java/org/apache/bcel/data/SWAP.java b/src/test/java/org/apache/bcel/data/SWAP.java
index ce1e29a2bf..81a291e24b 100644
--- a/src/test/java/org/apache/bcel/data/SWAP.java
+++ b/src/test/java/org/apache/bcel/data/SWAP.java
@@ -32,6 +32,6 @@ public static Constructor getTestConstructor(final Class theClass) throws NoSuch
return theClass.getConstructor(args);
} catch (final NoSuchMethodException e) {
}
- return theClass.getConstructor();
+ return theClass.getConstructor(new Class[0]);
}
}
diff --git a/src/test/java/org/apache/bcel/generic/JavaHome.java b/src/test/java/org/apache/bcel/generic/JavaHome.java
index f23be5537a..e4d04d45ba 100644
--- a/src/test/java/org/apache/bcel/generic/JavaHome.java
+++ b/src/test/java/org/apache/bcel/generic/JavaHome.java
@@ -68,7 +68,7 @@ public class JavaHome {
private static Stream find(final Path start, final int maxDepth, final BiPredicate matcher,
final FileVisitOption... options) {
- // TODO Apache Commons 2.14.0: Use FilesUncheck
+ // TODO Apache Commons 2.14.0: Use FilesUncheck
return Files.exists(start) ? Uncheck.apply(Files::find, start, maxDepth, matcher, options) : Stream.empty();
}
diff --git a/src/test/java/org/apache/bcel/generic/TypeTestCase.java b/src/test/java/org/apache/bcel/generic/TypeTestCase.java
index 303a75ba4c..8378058990 100644
--- a/src/test/java/org/apache/bcel/generic/TypeTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/TypeTestCase.java
@@ -91,7 +91,7 @@ public void testLDC(final String className) throws Exception {
for (final InstructionHandle instructionHandle : instructionList) {
instructionHandle.accept(new EmptyVisitor() {
@Override
- public void visitLDC(final LDC obj) {
+ public void visitLDC(LDC obj) {
assertNotNull(obj.getValue(cpg));
}
});
diff --git a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java
index 8ab68d6c6d..1cdeff2d9d 100644
--- a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java
+++ b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java
@@ -174,7 +174,7 @@ public void testHelloWorld() throws Exception {
/*
* Dumps a class using "javap" and compare with the same class recreated using BCELifier, "javac", "java" and dumped with "javap".
- *
+ *
* TODO: detect if JDK present and skip test if not
*/
@ParameterizedTest
diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java
index 5a8502d173..bfd84f28ce 100644
--- a/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java
@@ -109,7 +109,7 @@ public void testCompileAndVerify() throws ClassNotFoundException {
at org.apache.bcel.verifier.structurals.Pass3bVerifier.do_verify(Pass3bVerifier.java:386)
... 74 more
* }
- *
+ *
* @throws ClassNotFoundException
*/
@Test
diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
index a92a92240f..659a9abe25 100644
--- a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
@@ -46,19 +46,19 @@ public class JiraBcel370TestCase extends AbstractTestCase {
public void testLdcGetType(final String classFileName) throws Exception {
try (FileInputStream file = new FileInputStream(classFileName)) {
final ClassParser parser = new ClassParser(file, new File(classFileName).getName());
- final JavaClass clazz = parser.parse();
-
- final Method[] methods = clazz.getMethods();
-
- final ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool());
- final MethodGen methodGen = new MethodGen(methods[0], classFileName, cp);
-
+ JavaClass clazz = parser.parse();
+
+ Method[] methods = clazz.getMethods();
+
+ ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool());
+ MethodGen methodGen = new MethodGen(methods[0], classFileName, cp);
+
// The first instruction is an LDC CONSTANT_Dynamic added by Jacoco
- final Instruction instruction = methodGen.getInstructionList().getInstructions()[0];
+ Instruction instruction = methodGen.getInstructionList().getInstructions()[0];
instruction.accept(new EmptyVisitor() {
@Override
- public void visitLDC(final LDC ldc) {
+ public void visitLDC(LDC ldc) {
// Without the change to LDC.getType() this fails because the tag is CONSTANT_Dynamic
ldc.getType(cp);
}
@@ -72,7 +72,7 @@ public void visitLDC(final LDC ldc) {
"com.foo.Foo"
})
// @formatter:on
- public void testVerify(final String className) throws ClassNotFoundException {
+ public void testVerify(String className) throws ClassNotFoundException {
// Without the changes to the verifier this fails because it doesn't allow LDC CONSTANT_Dynamic
Verifier.verifyType(className);
}
diff --git a/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
index c368c392c4..7cda6a874f 100644
--- a/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
@@ -72,62 +72,62 @@ public static Stream constantsNotSupportedByLdc() {
}
@AfterAll
public static void restoreRepository() {
- // We have set our mock repository, revert the change
+ // We have set our mock repository, revert the change
Repository.setRepository(SyntheticRepository.getInstance());
}
private Verifier verifier;
private org.apache.bcel.util.Repository repository;
private ConstantPool cp;
-
+
private JavaClass javaClass;
-
+
@ParameterizedTest
@MethodSource("constantsNotSupportedByLdc")
- public void rejectLdcConstant(final Constant constant) {
+ public void rejectLdcConstant(Constant constant) {
// LDC the constant 0 and then return
- final byte[] methodCode = {
+ byte[] methodCode = new byte[] {
Const.LDC,
0,
0,
(byte) Const.RETURN,
};
-
- final Code code = new Code(0, 0, 0, 0, methodCode, new CodeException[0], new Attribute[0], cp);
+
+ Code code = new Code(0, 0, 0, 0, methodCode, new CodeException[0], new Attribute[0], cp);
when(cp.getConstantPool()).thenReturn(new Constant[] {constant});
-
- final Attribute[] attributes = {code};
- final Method method = new Method(0, 0, 0, attributes, cp);
-
+
+ Attribute[] attributes = new Attribute[] {code};
+ Method method = new Method(0, 0, 0, attributes, cp);
+
when(javaClass.getMethods()).thenReturn(new Method[] {method});
-
- final Pass3aVerifier pass3aVerifier = new Pass3aVerifier(verifier, 0);
- final VerificationResult verificationResult = pass3aVerifier.do_verify();
-
+
+ Pass3aVerifier pass3aVerifier = new Pass3aVerifier(verifier, 0);
+ VerificationResult verificationResult = pass3aVerifier.do_verify();
+
assertThat(verificationResult.getStatus()).isEqualTo(VerificationResult.VERIFIED_REJECTED);
assertThat(verificationResult.getMessage()).startsWith("Instruction ldc[18](2) 0 constraint violated: Operand of LDC");
}
-
+
@BeforeEach
void setup() throws ClassNotFoundException {
- final String className = "org.apache.bcel.verifier.statics.Pass3aVerifierTestCase.foo";
-
+ String className = "org.apache.bcel.verifier.statics.Pass3aVerifierTestCase.foo";
+
verifier = spy(VerifierFactory.getVerifier(className));
repository = mock(org.apache.bcel.util.Repository.class);
cp = mock(ConstantPool.class);
javaClass = mock(JavaClass.class);
-
+
// Mock the verifier
doReturn(VerificationResult.VR_OK).when(verifier).doPass2();
-
+
// Mock the repository
Repository.setRepository(repository);
when(repository.loadClass(className)).thenReturn(javaClass);
-
+
// Mock the constant pool
when(cp.getConstantPool()).thenReturn(new Constant[] {new ConstantModule(0)});
-
+
// Mock the java class
when(javaClass.getConstantPool()).thenReturn(cp);
}
diff --git a/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
index 72d4c04b6e..3ebc5e29a7 100644
--- a/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
@@ -29,22 +29,22 @@
public class InstConstraintVisitorTestCase {
private ConstantPoolGen cp;
-
+
@ParameterizedTest
@MethodSource("org.apache.bcel.verifier.statics.Pass3aVerifierTestCase#constantsNotSupportedByLdc")
- public void rejectLdcConstantModule(final Constant constant) {
- final InstConstraintVisitor visitor = new InstConstraintVisitor();
-
+ public void rejectLdcConstantModule(Constant constant) {
+ InstConstraintVisitor visitor = new InstConstraintVisitor();
+
cp = mock(ConstantPoolGen.class);
when(cp.getConstant(0)).thenReturn(constant);
-
+
visitor.setConstantPoolGen(cp);
-
- final LDC ldc = new LDC(0);
-
+
+ LDC ldc = new LDC(0);
+
assertThatCode(() -> visitor.visitLDC(ldc)).hasMessageStartingWith("Instruction LDC constraint violated: Referenced constant should be a");
}
-
+
@BeforeEach
public void setup() {
cp = mock(ConstantPoolGen.class);
From 73d3da8b871f9b1ef27d93e8fe2fa76adeaf14dc Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sat, 6 Jan 2024 17:24:16 -0500
Subject: [PATCH 35/46] Remove trailing whitespace
- Use final
- Use compact array creation syntax
- Merge if-else test
---
.../apache/bcel/classfile/StackMapEntry.java | 8 +---
.../org/apache/bcel/classfile/Visitor.java | 2 +-
.../ConstantPoolModuleToStringTestCase.java | 2 +-
.../bcel/classfile/ConstantPoolTestCase.java | 4 +-
.../apache/bcel/classfile/TestJira368.java | 4 +-
.../org/apache/bcel/generic/JavaHome.java | 2 +-
.../org/apache/bcel/generic/TypeTestCase.java | 2 +-
.../apache/bcel/util/BCELifierTestCase.java | 2 +-
.../bcel/verifier/JiraBcel369TestCase.java | 2 +-
.../bcel/verifier/JiraBcel370TestCase.java | 20 ++++-----
.../statics/Pass3aVerifierTestCase.java | 44 +++++++++----------
.../InstConstraintVisitorTestCase.java | 18 ++++----
12 files changed, 53 insertions(+), 57 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
index 5b8a7f5149..4afe9c0f4f 100644
--- a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
+++ b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
@@ -71,9 +71,7 @@ public final class StackMapEntry implements Node, Cloneable {
} else if (frameType == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
byteCodeOffset = dataInput.readUnsignedShort();
typesOfStackItems = new StackMapType[] { new StackMapType(dataInput, constantPool) };
- } else if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX) {
- byteCodeOffset = dataInput.readUnsignedShort();
- } else if (frameType == Const.SAME_FRAME_EXTENDED) {
+ } else if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX || frameType == Const.SAME_FRAME_EXTENDED) {
byteCodeOffset = dataInput.readUnsignedShort();
} else if (frameType >= Const.APPEND_FRAME && frameType <= Const.APPEND_FRAME_MAX) {
byteCodeOffset = dataInput.readUnsignedShort();
@@ -186,9 +184,7 @@ public void dump(final DataOutputStream file) throws IOException {
} else if (frameType == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
file.writeShort(byteCodeOffset);
typesOfStackItems[0].dump(file);
- } else if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX) {
- file.writeShort(byteCodeOffset);
- } else if (frameType == Const.SAME_FRAME_EXTENDED) {
+ } else if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX || frameType == Const.SAME_FRAME_EXTENDED) {
file.writeShort(byteCodeOffset);
} else if (frameType >= Const.APPEND_FRAME && frameType <= Const.APPEND_FRAME_MAX) {
file.writeShort(byteCodeOffset);
diff --git a/src/main/java/org/apache/bcel/classfile/Visitor.java b/src/main/java/org/apache/bcel/classfile/Visitor.java
index 9a3388cf0d..4f4b5c2116 100644
--- a/src/main/java/org/apache/bcel/classfile/Visitor.java
+++ b/src/main/java/org/apache/bcel/classfile/Visitor.java
@@ -230,7 +230,7 @@ default void visitNestMembers(final NestMembers obj) {
* @param obj object to visit
* @since 6.8.0
*/
- default void visitStackMapType(StackMapType obj) {
+ default void visitStackMapType(final StackMapType obj) {
// empty
}
diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
index 8048b705cb..e7f08c96eb 100644
--- a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
@@ -385,7 +385,7 @@ public void visitModuleRequires(final ModuleRequires constantModule) {
append(constantModule);
append(constantModule.toString(pool));
final String s = constantModule.toString(pool).trim();
- boolean condition = StringUtils.startsWithAny(s,
+ final boolean condition = StringUtils.startsWithAny(s,
"jdk.",
"java.",
"org.junit",
diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
index 3c154facb1..3454a1a8ee 100644
--- a/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
@@ -66,7 +66,7 @@ public void testClassWithDoubleConstantPoolItem() throws ClassNotFoundException,
// Next constant pool entry will be invalid so skip it
i++;
}
- } catch (Throwable t) {
+ } catch (final Throwable t) {
t.printStackTrace();
fail();
}
@@ -92,7 +92,7 @@ public void testClassWithLongConstantPoolItem() throws ClassNotFoundException, I
// Next constant pool entry will be invalid so skip it
i++;
}
- } catch (Throwable t) {
+ } catch (final Throwable t) {
t.printStackTrace();
fail();
}
diff --git a/src/test/java/org/apache/bcel/classfile/TestJira368.java b/src/test/java/org/apache/bcel/classfile/TestJira368.java
index 83cc510eb0..427276b913 100644
--- a/src/test/java/org/apache/bcel/classfile/TestJira368.java
+++ b/src/test/java/org/apache/bcel/classfile/TestJira368.java
@@ -35,7 +35,7 @@ private JavaClass parseJavaClass() throws IOException {
@Test
public void testInstructionListStringBrief() throws Exception {
- for (Method method : parseJavaClass().getMethods()) {
+ for (final Method method : parseJavaClass().getMethods()) {
if (!method.isAbstract() && !method.isNative()) {
final InstructionList instructionList = new InstructionList(method.getCode().getCode());
final String string = instructionList.toString(false);
@@ -46,7 +46,7 @@ public void testInstructionListStringBrief() throws Exception {
@Test
public void testInstructionListStringVerbose() throws Exception {
- for (Method method : parseJavaClass().getMethods()) {
+ for (final Method method : parseJavaClass().getMethods()) {
if (!method.isAbstract() && !method.isNative()) {
final InstructionList instructionList = new InstructionList(method.getCode().getCode());
final String string = instructionList.toString(true);
diff --git a/src/test/java/org/apache/bcel/generic/JavaHome.java b/src/test/java/org/apache/bcel/generic/JavaHome.java
index e4d04d45ba..f23be5537a 100644
--- a/src/test/java/org/apache/bcel/generic/JavaHome.java
+++ b/src/test/java/org/apache/bcel/generic/JavaHome.java
@@ -68,7 +68,7 @@ public class JavaHome {
private static Stream find(final Path start, final int maxDepth, final BiPredicate matcher,
final FileVisitOption... options) {
- // TODO Apache Commons 2.14.0: Use FilesUncheck
+ // TODO Apache Commons 2.14.0: Use FilesUncheck
return Files.exists(start) ? Uncheck.apply(Files::find, start, maxDepth, matcher, options) : Stream.empty();
}
diff --git a/src/test/java/org/apache/bcel/generic/TypeTestCase.java b/src/test/java/org/apache/bcel/generic/TypeTestCase.java
index 8378058990..303a75ba4c 100644
--- a/src/test/java/org/apache/bcel/generic/TypeTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/TypeTestCase.java
@@ -91,7 +91,7 @@ public void testLDC(final String className) throws Exception {
for (final InstructionHandle instructionHandle : instructionList) {
instructionHandle.accept(new EmptyVisitor() {
@Override
- public void visitLDC(LDC obj) {
+ public void visitLDC(final LDC obj) {
assertNotNull(obj.getValue(cpg));
}
});
diff --git a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java
index 1cdeff2d9d..8ab68d6c6d 100644
--- a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java
+++ b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java
@@ -174,7 +174,7 @@ public void testHelloWorld() throws Exception {
/*
* Dumps a class using "javap" and compare with the same class recreated using BCELifier, "javac", "java" and dumped with "javap".
- *
+ *
* TODO: detect if JDK present and skip test if not
*/
@ParameterizedTest
diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java
index bfd84f28ce..5a8502d173 100644
--- a/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java
@@ -109,7 +109,7 @@ public void testCompileAndVerify() throws ClassNotFoundException {
at org.apache.bcel.verifier.structurals.Pass3bVerifier.do_verify(Pass3bVerifier.java:386)
... 74 more
* }
- *
+ *
* @throws ClassNotFoundException
*/
@Test
diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
index 659a9abe25..a92a92240f 100644
--- a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
@@ -46,19 +46,19 @@ public class JiraBcel370TestCase extends AbstractTestCase {
public void testLdcGetType(final String classFileName) throws Exception {
try (FileInputStream file = new FileInputStream(classFileName)) {
final ClassParser parser = new ClassParser(file, new File(classFileName).getName());
- JavaClass clazz = parser.parse();
-
- Method[] methods = clazz.getMethods();
-
- ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool());
- MethodGen methodGen = new MethodGen(methods[0], classFileName, cp);
-
+ final JavaClass clazz = parser.parse();
+
+ final Method[] methods = clazz.getMethods();
+
+ final ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool());
+ final MethodGen methodGen = new MethodGen(methods[0], classFileName, cp);
+
// The first instruction is an LDC CONSTANT_Dynamic added by Jacoco
- Instruction instruction = methodGen.getInstructionList().getInstructions()[0];
+ final Instruction instruction = methodGen.getInstructionList().getInstructions()[0];
instruction.accept(new EmptyVisitor() {
@Override
- public void visitLDC(LDC ldc) {
+ public void visitLDC(final LDC ldc) {
// Without the change to LDC.getType() this fails because the tag is CONSTANT_Dynamic
ldc.getType(cp);
}
@@ -72,7 +72,7 @@ public void visitLDC(LDC ldc) {
"com.foo.Foo"
})
// @formatter:on
- public void testVerify(String className) throws ClassNotFoundException {
+ public void testVerify(final String className) throws ClassNotFoundException {
// Without the changes to the verifier this fails because it doesn't allow LDC CONSTANT_Dynamic
Verifier.verifyType(className);
}
diff --git a/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
index 7cda6a874f..c368c392c4 100644
--- a/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
@@ -72,62 +72,62 @@ public static Stream constantsNotSupportedByLdc() {
}
@AfterAll
public static void restoreRepository() {
- // We have set our mock repository, revert the change
+ // We have set our mock repository, revert the change
Repository.setRepository(SyntheticRepository.getInstance());
}
private Verifier verifier;
private org.apache.bcel.util.Repository repository;
private ConstantPool cp;
-
+
private JavaClass javaClass;
-
+
@ParameterizedTest
@MethodSource("constantsNotSupportedByLdc")
- public void rejectLdcConstant(Constant constant) {
+ public void rejectLdcConstant(final Constant constant) {
// LDC the constant 0 and then return
- byte[] methodCode = new byte[] {
+ final byte[] methodCode = {
Const.LDC,
0,
0,
(byte) Const.RETURN,
};
-
- Code code = new Code(0, 0, 0, 0, methodCode, new CodeException[0], new Attribute[0], cp);
+
+ final Code code = new Code(0, 0, 0, 0, methodCode, new CodeException[0], new Attribute[0], cp);
when(cp.getConstantPool()).thenReturn(new Constant[] {constant});
-
- Attribute[] attributes = new Attribute[] {code};
- Method method = new Method(0, 0, 0, attributes, cp);
-
+
+ final Attribute[] attributes = {code};
+ final Method method = new Method(0, 0, 0, attributes, cp);
+
when(javaClass.getMethods()).thenReturn(new Method[] {method});
-
- Pass3aVerifier pass3aVerifier = new Pass3aVerifier(verifier, 0);
- VerificationResult verificationResult = pass3aVerifier.do_verify();
-
+
+ final Pass3aVerifier pass3aVerifier = new Pass3aVerifier(verifier, 0);
+ final VerificationResult verificationResult = pass3aVerifier.do_verify();
+
assertThat(verificationResult.getStatus()).isEqualTo(VerificationResult.VERIFIED_REJECTED);
assertThat(verificationResult.getMessage()).startsWith("Instruction ldc[18](2) 0 constraint violated: Operand of LDC");
}
-
+
@BeforeEach
void setup() throws ClassNotFoundException {
- String className = "org.apache.bcel.verifier.statics.Pass3aVerifierTestCase.foo";
-
+ final String className = "org.apache.bcel.verifier.statics.Pass3aVerifierTestCase.foo";
+
verifier = spy(VerifierFactory.getVerifier(className));
repository = mock(org.apache.bcel.util.Repository.class);
cp = mock(ConstantPool.class);
javaClass = mock(JavaClass.class);
-
+
// Mock the verifier
doReturn(VerificationResult.VR_OK).when(verifier).doPass2();
-
+
// Mock the repository
Repository.setRepository(repository);
when(repository.loadClass(className)).thenReturn(javaClass);
-
+
// Mock the constant pool
when(cp.getConstantPool()).thenReturn(new Constant[] {new ConstantModule(0)});
-
+
// Mock the java class
when(javaClass.getConstantPool()).thenReturn(cp);
}
diff --git a/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
index 3ebc5e29a7..72d4c04b6e 100644
--- a/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
@@ -29,22 +29,22 @@
public class InstConstraintVisitorTestCase {
private ConstantPoolGen cp;
-
+
@ParameterizedTest
@MethodSource("org.apache.bcel.verifier.statics.Pass3aVerifierTestCase#constantsNotSupportedByLdc")
- public void rejectLdcConstantModule(Constant constant) {
- InstConstraintVisitor visitor = new InstConstraintVisitor();
-
+ public void rejectLdcConstantModule(final Constant constant) {
+ final InstConstraintVisitor visitor = new InstConstraintVisitor();
+
cp = mock(ConstantPoolGen.class);
when(cp.getConstant(0)).thenReturn(constant);
-
+
visitor.setConstantPoolGen(cp);
-
- LDC ldc = new LDC(0);
-
+
+ final LDC ldc = new LDC(0);
+
assertThatCode(() -> visitor.visitLDC(ldc)).hasMessageStartingWith("Instruction LDC constraint violated: Referenced constant should be a");
}
-
+
@BeforeEach
public void setup() {
cp = mock(ConstantPoolGen.class);
From b5e5872f5d23cd45b115134bd724cd8a76cc12c8 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sat, 6 Jan 2024 17:31:12 -0500
Subject: [PATCH 36/46] Javadoc
---
.../java/org/apache/bcel/classfile/ConstantObject.java | 7 +++++--
.../org/apache/bcel/EnclosingMethodAttributeTestCase.java | 1 +
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/ConstantObject.java b/src/main/java/org/apache/bcel/classfile/ConstantObject.java
index e15699f03e..64ae7cd950 100644
--- a/src/main/java/org/apache/bcel/classfile/ConstantObject.java
+++ b/src/main/java/org/apache/bcel/classfile/ConstantObject.java
@@ -24,7 +24,10 @@
public interface ConstantObject {
/**
- * @return object representing the constant, e.g., Long for ConstantLong
+ * Gets the object representing the constant, e.g., Long for ConstantLong.
+ *
+ * @param constantPool the constant.
+ * @return object representing the constant, e.g., Long for ConstantLong.
*/
- Object getConstantValue(ConstantPool cp);
+ Object getConstantValue(ConstantPool constantPool);
}
diff --git a/src/test/java/org/apache/bcel/EnclosingMethodAttributeTestCase.java b/src/test/java/org/apache/bcel/EnclosingMethodAttributeTestCase.java
index 18e1f23949..b94a4a4c0a 100644
--- a/src/test/java/org/apache/bcel/EnclosingMethodAttributeTestCase.java
+++ b/src/test/java/org/apache/bcel/EnclosingMethodAttributeTestCase.java
@@ -31,6 +31,7 @@
import org.junit.jupiter.api.Test;
public class EnclosingMethodAttributeTestCase extends AbstractTestCase {
+
/**
* Check that we can save and load the attribute correctly.
*/
From 89b10c49598641b6834e34ba00087ca106857aa1 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 7 Jan 2024 08:38:02 -0500
Subject: [PATCH 37/46] Javadoc
---
.../apache/bcel/classfile/AccessFlags.java | 180 +++++++++++++++++-
1 file changed, 174 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/AccessFlags.java b/src/main/java/org/apache/bcel/classfile/AccessFlags.java
index 6310b7e310..9b9e93e0b6 100644
--- a/src/main/java/org/apache/bcel/classfile/AccessFlags.java
+++ b/src/main/java/org/apache/bcel/classfile/AccessFlags.java
@@ -24,7 +24,9 @@
public abstract class AccessFlags {
/**
- * @deprecated (since 6.0) will be made private; do not access directly, use getter/setter
+ * Access flags.
+ *
+ * @deprecated (since 6.0) will be made private; do not access directly, use getter/setter.
*/
@java.lang.Deprecated
protected int access_flags; // TODO not used externally at present
@@ -33,13 +35,17 @@ public AccessFlags() {
}
/**
- * @param a initial access flags
+ * Constructs a new instance.
+ *
+ * @param accessFlags initial access flags.
*/
- public AccessFlags(final int a) {
- access_flags = a;
+ public AccessFlags(final int accessFlags) {
+ access_flags = accessFlags;
}
/**
+ * Gets access flags.
+ *
* @return Access flags of the object aka. "modifiers".
*/
public final int getAccessFlags() {
@@ -47,142 +53,304 @@ public final int getAccessFlags() {
}
/**
- * @return Access flags of the object aka. "modifiers".
+ * Gets access flags.
+ *
+ * @return Access flags of the object also known as modifiers.
*/
public final int getModifiers() {
return access_flags;
}
+ /**
+ * Tests whether the abstract bit is on.
+ *
+ * @return whether the abstract bit is on.
+ */
public final boolean isAbstract() {
return (access_flags & Const.ACC_ABSTRACT) != 0;
}
+ /**
+ * Sets the abstract bit.
+ *
+ * @param flag The new value.
+ */
public final void isAbstract(final boolean flag) {
setFlag(Const.ACC_ABSTRACT, flag);
}
+ /**
+ * Tests whether the annotation bit is on.
+ *
+ * @return whether the annotation bit is on.
+ */
public final boolean isAnnotation() {
return (access_flags & Const.ACC_ANNOTATION) != 0;
}
+ /**
+ * Sets the annotation bit.
+ *
+ * @param flag The new value.
+ */
public final void isAnnotation(final boolean flag) {
setFlag(Const.ACC_ANNOTATION, flag);
}
+ /**
+ * Tests whether the enum bit is on.
+ *
+ * @return whether the enum bit is on.
+ */
public final boolean isEnum() {
return (access_flags & Const.ACC_ENUM) != 0;
}
+ /**
+ * Sets the enum bit.
+ *
+ * @param flag The new value.
+ */
public final void isEnum(final boolean flag) {
setFlag(Const.ACC_ENUM, flag);
}
+ /**
+ * Tests whether the final bit is on.
+ *
+ * @return whether the final bit is on.
+ */
public final boolean isFinal() {
return (access_flags & Const.ACC_FINAL) != 0;
}
+ /**
+ * Sets the final bit.
+ *
+ * @param flag The new value.
+ */
public final void isFinal(final boolean flag) {
setFlag(Const.ACC_FINAL, flag);
}
+ /**
+ * Tests whether the interface bit is on.
+ *
+ * @return whether the interface bit is on.
+ */
public final boolean isInterface() {
return (access_flags & Const.ACC_INTERFACE) != 0;
}
+ /**
+ * Sets the interface bit.
+ *
+ * @param flag The new value.
+ */
public final void isInterface(final boolean flag) {
setFlag(Const.ACC_INTERFACE, flag);
}
+ /**
+ * Tests whether the native bit is on.
+ *
+ * @return whether the native bit is on.
+ */
public final boolean isNative() {
return (access_flags & Const.ACC_NATIVE) != 0;
}
+ /**
+ * Sets the native bit.
+ *
+ * @param flag The new value.
+ */
public final void isNative(final boolean flag) {
setFlag(Const.ACC_NATIVE, flag);
}
+ /**
+ * Tests whether the private bit is on.
+ *
+ * @return whether the private bit is on.
+ */
public final boolean isPrivate() {
return (access_flags & Const.ACC_PRIVATE) != 0;
}
+ /**
+ * Sets the private bit.
+ *
+ * @param flag The new value.
+ */
public final void isPrivate(final boolean flag) {
setFlag(Const.ACC_PRIVATE, flag);
}
+ /**
+ * Tests whether the protected bit is on.
+ *
+ * @return whether the protected bit is on.
+ */
public final boolean isProtected() {
return (access_flags & Const.ACC_PROTECTED) != 0;
}
+ /**
+ * Sets the protected bit.
+ *
+ * @param flag The new value.
+ */
public final void isProtected(final boolean flag) {
setFlag(Const.ACC_PROTECTED, flag);
}
+ /**
+ * Tests whether the public bit is on.
+ *
+ * @return whether the public bit is on.
+ */
public final boolean isPublic() {
return (access_flags & Const.ACC_PUBLIC) != 0;
}
+ /**
+ * Sets the public bit.
+ *
+ * @param flag The new value.
+ */
public final void isPublic(final boolean flag) {
setFlag(Const.ACC_PUBLIC, flag);
}
+ /**
+ * Tests whether the static bit is on.
+ *
+ * @return whether the static bit is on.
+ */
public final boolean isStatic() {
return (access_flags & Const.ACC_STATIC) != 0;
}
+ /**
+ * Sets the static bit.
+ *
+ * @param flag The new value.
+ */
public final void isStatic(final boolean flag) {
setFlag(Const.ACC_STATIC, flag);
}
+ /**
+ * Tests whether the strict bit is on.
+ *
+ * @return whether the strict bit is on.
+ */
public final boolean isStrictfp() {
return (access_flags & Const.ACC_STRICT) != 0;
}
+ /**
+ * Sets the strict bit.
+ *
+ * @param flag The new value.
+ */
public final void isStrictfp(final boolean flag) {
setFlag(Const.ACC_STRICT, flag);
}
+ /**
+ * Tests whether the synchronized bit is on.
+ *
+ * @return whether the synchronized bit is on.
+ */
public final boolean isSynchronized() {
return (access_flags & Const.ACC_SYNCHRONIZED) != 0;
}
+ /**
+ * Sets the synchronized bit.
+ *
+ * @param flag The new value.
+ */
public final void isSynchronized(final boolean flag) {
setFlag(Const.ACC_SYNCHRONIZED, flag);
}
+ /**
+ * Tests whether the synthetic bit is on.
+ *
+ * @return whether the synthetic bit is on.
+ */
public final boolean isSynthetic() {
return (access_flags & Const.ACC_SYNTHETIC) != 0;
}
+ /**
+ * Sets the synthetic bit.
+ *
+ * @param flag The new value.
+ */
public final void isSynthetic(final boolean flag) {
setFlag(Const.ACC_SYNTHETIC, flag);
}
+ /**
+ * Tests whether the transient bit is on.
+ *
+ * @return whether the varargs bit is on.
+ */
public final boolean isTransient() {
return (access_flags & Const.ACC_TRANSIENT) != 0;
}
+ /**
+ * Sets the varargs bit.
+ *
+ * @param flag The new value.
+ */
public final void isTransient(final boolean flag) {
setFlag(Const.ACC_TRANSIENT, flag);
}
+ /**
+ * Tests whether the varargs bit is on.
+ *
+ * @return whether the varargs bit is on.
+ */
public final boolean isVarArgs() {
return (access_flags & Const.ACC_VARARGS) != 0;
}
+ /**
+ * Sets the varargs bit.
+ *
+ * @param flag The new value.
+ */
public final void isVarArgs(final boolean flag) {
setFlag(Const.ACC_VARARGS, flag);
}
+ /**
+ * Tests whether the volatile bit is on.
+ *
+ * @return whether the volatile bit is on.
+ */
public final boolean isVolatile() {
return (access_flags & Const.ACC_VOLATILE) != 0;
}
+ /**
+ * Sets the volatile bit.
+ *
+ * @param flag The new value.
+ */
public final void isVolatile(final boolean flag) {
setFlag(Const.ACC_VOLATILE, flag);
}
/**
- * Sets access flags aka "modifiers".
+ * Sets access flags also known as modifiers.
*
* @param accessFlags Access flags of the object.
*/
From add006f089b031d376f568bb8ca28855454a69eb Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 7 Jan 2024 08:38:17 -0500
Subject: [PATCH 38/46] Internal refactoring
---
.../apache/bcel/classfile/AccessFlags.java | 46 ++++++++++++-------
1 file changed, 29 insertions(+), 17 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/AccessFlags.java b/src/main/java/org/apache/bcel/classfile/AccessFlags.java
index 9b9e93e0b6..c5946f9483 100644
--- a/src/main/java/org/apache/bcel/classfile/AccessFlags.java
+++ b/src/main/java/org/apache/bcel/classfile/AccessFlags.java
@@ -31,6 +31,9 @@ public abstract class AccessFlags {
@java.lang.Deprecated
protected int access_flags; // TODO not used externally at present
+ /**
+ * Constructs a new instance.
+ */
public AccessFlags() {
}
@@ -67,7 +70,7 @@ public final int getModifiers() {
* @return whether the abstract bit is on.
*/
public final boolean isAbstract() {
- return (access_flags & Const.ACC_ABSTRACT) != 0;
+ return test(Const.ACC_ABSTRACT);
}
/**
@@ -85,7 +88,7 @@ public final void isAbstract(final boolean flag) {
* @return whether the annotation bit is on.
*/
public final boolean isAnnotation() {
- return (access_flags & Const.ACC_ANNOTATION) != 0;
+ return test(Const.ACC_ANNOTATION);
}
/**
@@ -96,14 +99,13 @@ public final boolean isAnnotation() {
public final void isAnnotation(final boolean flag) {
setFlag(Const.ACC_ANNOTATION, flag);
}
-
/**
* Tests whether the enum bit is on.
*
* @return whether the enum bit is on.
*/
public final boolean isEnum() {
- return (access_flags & Const.ACC_ENUM) != 0;
+ return test(Const.ACC_ENUM);
}
/**
@@ -121,7 +123,7 @@ public final void isEnum(final boolean flag) {
* @return whether the final bit is on.
*/
public final boolean isFinal() {
- return (access_flags & Const.ACC_FINAL) != 0;
+ return test(Const.ACC_FINAL);
}
/**
@@ -139,7 +141,7 @@ public final void isFinal(final boolean flag) {
* @return whether the interface bit is on.
*/
public final boolean isInterface() {
- return (access_flags & Const.ACC_INTERFACE) != 0;
+ return test(Const.ACC_INTERFACE);
}
/**
@@ -157,7 +159,7 @@ public final void isInterface(final boolean flag) {
* @return whether the native bit is on.
*/
public final boolean isNative() {
- return (access_flags & Const.ACC_NATIVE) != 0;
+ return test(Const.ACC_NATIVE);
}
/**
@@ -175,7 +177,7 @@ public final void isNative(final boolean flag) {
* @return whether the private bit is on.
*/
public final boolean isPrivate() {
- return (access_flags & Const.ACC_PRIVATE) != 0;
+ return test(Const.ACC_PRIVATE);
}
/**
@@ -193,7 +195,7 @@ public final void isPrivate(final boolean flag) {
* @return whether the protected bit is on.
*/
public final boolean isProtected() {
- return (access_flags & Const.ACC_PROTECTED) != 0;
+ return test(Const.ACC_PROTECTED);
}
/**
@@ -211,7 +213,7 @@ public final void isProtected(final boolean flag) {
* @return whether the public bit is on.
*/
public final boolean isPublic() {
- return (access_flags & Const.ACC_PUBLIC) != 0;
+ return test(Const.ACC_PUBLIC);
}
/**
@@ -229,7 +231,7 @@ public final void isPublic(final boolean flag) {
* @return whether the static bit is on.
*/
public final boolean isStatic() {
- return (access_flags & Const.ACC_STATIC) != 0;
+ return test(Const.ACC_STATIC);
}
/**
@@ -247,7 +249,7 @@ public final void isStatic(final boolean flag) {
* @return whether the strict bit is on.
*/
public final boolean isStrictfp() {
- return (access_flags & Const.ACC_STRICT) != 0;
+ return test(Const.ACC_STRICT);
}
/**
@@ -265,7 +267,7 @@ public final void isStrictfp(final boolean flag) {
* @return whether the synchronized bit is on.
*/
public final boolean isSynchronized() {
- return (access_flags & Const.ACC_SYNCHRONIZED) != 0;
+ return test(Const.ACC_SYNCHRONIZED);
}
/**
@@ -283,7 +285,7 @@ public final void isSynchronized(final boolean flag) {
* @return whether the synthetic bit is on.
*/
public final boolean isSynthetic() {
- return (access_flags & Const.ACC_SYNTHETIC) != 0;
+ return test(Const.ACC_SYNTHETIC);
}
/**
@@ -301,7 +303,7 @@ public final void isSynthetic(final boolean flag) {
* @return whether the varargs bit is on.
*/
public final boolean isTransient() {
- return (access_flags & Const.ACC_TRANSIENT) != 0;
+ return test(Const.ACC_TRANSIENT);
}
/**
@@ -319,7 +321,7 @@ public final void isTransient(final boolean flag) {
* @return whether the varargs bit is on.
*/
public final boolean isVarArgs() {
- return (access_flags & Const.ACC_VARARGS) != 0;
+ return test(Const.ACC_VARARGS);
}
/**
@@ -337,7 +339,7 @@ public final void isVarArgs(final boolean flag) {
* @return whether the volatile bit is on.
*/
public final boolean isVolatile() {
- return (access_flags & Const.ACC_VOLATILE) != 0;
+ return test(Const.ACC_VOLATILE);
}
/**
@@ -376,4 +378,14 @@ private void setFlag(final int flag, final boolean set) {
public final void setModifiers(final int accessFlags) {
setAccessFlags(accessFlags);
}
+
+ /**
+ * Tests whether the bit is on.
+ *
+ * @param test the bit to test.
+ * @return whether the bit is on.
+ */
+ private boolean test(final short test) {
+ return (access_flags & test) != 0;
+ }
}
From f230b0016628bef3bbfd2648d14ba4e607fb03ca Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 7 Jan 2024 12:06:12 -0500
Subject: [PATCH 39/46] BCELComparator now uses generics
Avoid NPEs in BCELComparator implementations
---
src/changes/changes.xml | 8 ++++
.../org/apache/bcel/classfile/Constant.java | 21 ++++-----
.../java/org/apache/bcel/classfile/Field.java | 25 +++++------
.../org/apache/bcel/classfile/JavaClass.java | 24 +++++-----
.../org/apache/bcel/classfile/Method.java | 25 +++++------
.../org/apache/bcel/generic/ClassGen.java | 19 ++++----
.../org/apache/bcel/generic/FieldGen.java | 27 +++++-------
.../org/apache/bcel/generic/MethodGen.java | 23 +++++-----
.../org/apache/bcel/util/BCELComparator.java | 23 +++++-----
.../apache/bcel/classfile/ConstantTest.java | 38 ++++++++++++++++
.../org/apache/bcel/classfile/FieldTest.java | 38 ++++++++++++++++
.../org/apache/bcel/generic/ClassGenTest.java | 38 ++++++++++++++++
.../org/apache/bcel/generic/FieldGenTest.java | 44 +++++++++++++++++++
13 files changed, 250 insertions(+), 103 deletions(-)
create mode 100644 src/test/java/org/apache/bcel/classfile/ConstantTest.java
create mode 100644 src/test/java/org/apache/bcel/classfile/FieldTest.java
create mode 100644 src/test/java/org/apache/bcel/generic/ClassGenTest.java
create mode 100644 src/test/java/org/apache/bcel/generic/FieldGenTest.java
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b0b8a17b9e..8f6bea689a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -68,6 +68,14 @@ The type attribute can be add,update,fix,remove.
Replace internal use of StringBuffer with StringBuilder.
CONSTANT_Dynamic is not handled in LDC #254.
+ BCELComparator now uses generics.
+ Avoid NullPointerException in ClassGen.BCELComparator#equals() and ClassGen.BCELComparator#hashCode().
+ Avoid NullPointerException in Constant.BCELComparator#equals() and Constant.BCELComparator#hashCode().
+ Avoid NullPointerException in Field.BCELComparator#equals() and Field.BCELComparator#hashCode().
+ Avoid NullPointerException in FieldGen.BCELComparator#equals() and FieldGen.BCELComparator#hashCode().
+ Avoid NullPointerException in JavaClass.BCELComparator#equals() and JavaClass.BCELComparator#hashCode().
+ Avoid NullPointerException in Method.BCELComparator#equals() and Method.BCELComparator#hashCode().
+ Avoid NullPointerException in MethodGen.BCELComparator#equals() and MethodGen.BCELComparator#hashCode().
Bump GitHub various actions for CI builds.
Bump jna.version from 5.13.0 to 5.14.0 #250.
diff --git a/src/main/java/org/apache/bcel/classfile/Constant.java b/src/main/java/org/apache/bcel/classfile/Constant.java
index a70400cd72..6ed876d058 100644
--- a/src/main/java/org/apache/bcel/classfile/Constant.java
+++ b/src/main/java/org/apache/bcel/classfile/Constant.java
@@ -30,26 +30,23 @@
*/
public abstract class Constant implements Cloneable, Node {
- private static BCELComparator bcelComparator = new BCELComparator() {
+ private static BCELComparator bcelComparator = new BCELComparator() {
@Override
- public boolean equals(final Object o1, final Object o2) {
- final Constant THIS = (Constant) o1;
- final Constant THAT = (Constant) o2;
- return Objects.equals(THIS.toString(), THAT.toString());
+ public boolean equals(final Constant a, final Constant b) {
+ return a == b || a != null && b != null && Objects.equals(a.toString(), b.toString());
}
@Override
- public int hashCode(final Object o) {
- final Constant THIS = (Constant) o;
- return THIS.toString().hashCode();
+ public int hashCode(final Constant o) {
+ return o != null ? Objects.hashCode(o.toString()) : 0;
}
};
/**
- * @return Comparison strategy object
+ * @return Comparison strategy object.
*/
- public static BCELComparator getComparator() {
+ public static BCELComparator getComparator() {
return bcelComparator;
}
@@ -107,7 +104,7 @@ public static Constant readConstant(final DataInput dataInput) throws IOExceptio
/**
* @param comparator Comparison strategy object
*/
- public static void setComparator(final BCELComparator comparator) {
+ public static void setComparator(final BCELComparator comparator) {
bcelComparator = comparator;
}
@@ -168,7 +165,7 @@ public Constant copy() {
*/
@Override
public boolean equals(final Object obj) {
- return bcelComparator.equals(this, obj);
+ return obj instanceof Constant && bcelComparator.equals(this, (Constant) obj);
}
/**
diff --git a/src/main/java/org/apache/bcel/classfile/Field.java b/src/main/java/org/apache/bcel/classfile/Field.java
index e7b967b8df..a7f002e0fa 100644
--- a/src/main/java/org/apache/bcel/classfile/Field.java
+++ b/src/main/java/org/apache/bcel/classfile/Field.java
@@ -37,19 +37,16 @@ public final class Field extends FieldOrMethod {
*/
public static final Field[] EMPTY_ARRAY = {};
- private static BCELComparator bcelComparator = new BCELComparator() {
+ private static BCELComparator bcelComparator = new BCELComparator() {
@Override
- public boolean equals(final Object o1, final Object o2) {
- final Field THIS = (Field) o1;
- final Field THAT = (Field) o2;
- return Objects.equals(THIS.getName(), THAT.getName()) && Objects.equals(THIS.getSignature(), THAT.getSignature());
+ public boolean equals(final Field a, final Field b) {
+ return a == b || a != null && b != null && Objects.equals(a.getName(), b.getName()) && Objects.equals(a.getSignature(), b.getSignature());
}
@Override
- public int hashCode(final Object o) {
- final Field THIS = (Field) o;
- return THIS.getSignature().hashCode() ^ THIS.getName().hashCode();
+ public int hashCode(final Field o) {
+ return o != null ? Objects.hash(o.getSignature(), o.getName()) : 0;
}
};
@@ -59,23 +56,23 @@ public int hashCode(final Object o) {
static final Field[] EMPTY_FIELD_ARRAY = {};
/**
- * @return Comparison strategy object
+ * @return Comparison strategy object.
*/
- public static BCELComparator getComparator() {
+ public static BCELComparator getComparator() {
return bcelComparator;
}
/**
- * @param comparator Comparison strategy object
+ * @param comparator Comparison strategy object.
*/
- public static void setComparator(final BCELComparator comparator) {
+ public static void setComparator(final BCELComparator comparator) {
bcelComparator = comparator;
}
/**
* Constructs object from file stream.
*
- * @param file Input stream
+ * @param file Input stream.
*/
Field(final DataInput file, final ConstantPool constantPool) throws IOException, ClassFormatException {
super(file, constantPool);
@@ -128,7 +125,7 @@ public Field copy(final ConstantPool constantPool) {
*/
@Override
public boolean equals(final Object obj) {
- return bcelComparator.equals(this, obj);
+ return obj instanceof Field && bcelComparator.equals(this, (Field) obj);
}
/**
diff --git a/src/main/java/org/apache/bcel/classfile/JavaClass.java b/src/main/java/org/apache/bcel/classfile/JavaClass.java
index 067a9f53c1..5bcd5c7e2c 100644
--- a/src/main/java/org/apache/bcel/classfile/JavaClass.java
+++ b/src/main/java/org/apache/bcel/classfile/JavaClass.java
@@ -65,19 +65,17 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
public static final byte FILE = 2;
public static final byte ZIP = 3;
private static final boolean debug = Boolean.getBoolean("JavaClass.debug"); // Debugging on/off
- private static BCELComparator bcelComparator = new BCELComparator() {
+
+ private static BCELComparator bcelComparator = new BCELComparator() {
@Override
- public boolean equals(final Object o1, final Object o2) {
- final JavaClass THIS = (JavaClass) o1;
- final JavaClass THAT = (JavaClass) o2;
- return Objects.equals(THIS.getClassName(), THAT.getClassName());
+ public boolean equals(final JavaClass a, final JavaClass b) {
+ return a == b || a != null && b != null && Objects.equals(a.getClassName(), b.getClassName());
}
@Override
- public int hashCode(final Object o) {
- final JavaClass THIS = (JavaClass) o;
- return THIS.getClassName().hashCode();
+ public int hashCode(final JavaClass o) {
+ return o != null ? Objects.hashCode(o.getClassName()) : 0;
}
};
@@ -91,9 +89,9 @@ static void Debug(final String str) {
}
/**
- * @return Comparison strategy object
+ * @return Comparison strategy object.
*/
- public static BCELComparator getComparator() {
+ public static BCELComparator getComparator() {
return bcelComparator;
}
@@ -107,9 +105,9 @@ private static String indent(final Object obj) {
}
/**
- * @param comparator Comparison strategy object
+ * @param comparator Comparison strategy object.
*/
- public static void setComparator(final BCELComparator comparator) {
+ public static void setComparator(final BCELComparator comparator) {
bcelComparator = comparator;
}
@@ -391,7 +389,7 @@ public void dump(final String fileName) throws IOException {
*/
@Override
public boolean equals(final Object obj) {
- return bcelComparator.equals(this, obj);
+ return obj instanceof JavaClass && bcelComparator.equals(this, (JavaClass) obj);
}
/**
diff --git a/src/main/java/org/apache/bcel/classfile/Method.java b/src/main/java/org/apache/bcel/classfile/Method.java
index b9c1e36829..84d7e4751d 100644
--- a/src/main/java/org/apache/bcel/classfile/Method.java
+++ b/src/main/java/org/apache/bcel/classfile/Method.java
@@ -36,19 +36,16 @@ public final class Method extends FieldOrMethod {
*/
public static final Method[] EMPTY_ARRAY = {};
- private static BCELComparator bcelComparator = new BCELComparator() {
+ private static BCELComparator bcelComparator = new BCELComparator() {
@Override
- public boolean equals(final Object o1, final Object o2) {
- final Method THIS = (Method) o1;
- final Method THAT = (Method) o2;
- return Objects.equals(THIS.getName(), THAT.getName()) && Objects.equals(THIS.getSignature(), THAT.getSignature());
+ public boolean equals(final Method a, final Method b) {
+ return a == b || a != null && b != null && Objects.equals(a.getName(), b.getName()) && Objects.equals(a.getSignature(), b.getSignature());
}
@Override
- public int hashCode(final Object o) {
- final Method THIS = (Method) o;
- return THIS.getSignature().hashCode() ^ THIS.getName().hashCode();
+ public int hashCode(final Method o) {
+ return o != null ? Objects.hash(o.getSignature(), o.getName()) : 0;
}
};
@@ -58,20 +55,20 @@ public int hashCode(final Object o) {
static final Method[] EMPTY_METHOD_ARRAY = {};
/**
- * @return Comparison strategy object
+ * @return Comparison strategy object.
*/
- public static BCELComparator getComparator() {
+ public static BCELComparator getComparator() {
return bcelComparator;
}
/**
- * @param comparator Comparison strategy object
+ * @param comparator Comparison strategy object.
*/
- public static void setComparator(final BCELComparator comparator) {
+ public static void setComparator(final BCELComparator comparator) {
bcelComparator = comparator;
}
- // annotations defined on the parameters of a method
+ /** Annotations defined on the parameters of a method. */
private ParameterAnnotationEntry[] parameterAnnotationEntries;
/**
@@ -138,7 +135,7 @@ public Method copy(final ConstantPool constantPool) {
*/
@Override
public boolean equals(final Object obj) {
- return bcelComparator.equals(this, obj);
+ return obj instanceof Method && bcelComparator.equals(this, (Method) obj);
}
/**
diff --git a/src/main/java/org/apache/bcel/generic/ClassGen.java b/src/main/java/org/apache/bcel/generic/ClassGen.java
index cb4ecb5e7d..b612050a93 100644
--- a/src/main/java/org/apache/bcel/generic/ClassGen.java
+++ b/src/main/java/org/apache/bcel/generic/ClassGen.java
@@ -44,33 +44,30 @@
*/
public class ClassGen extends AccessFlags implements Cloneable {
- private static BCELComparator bcelComparator = new BCELComparator() {
+ private static BCELComparator bcelComparator = new BCELComparator() {
@Override
- public boolean equals(final Object o1, final Object o2) {
- final ClassGen THIS = (ClassGen) o1;
- final ClassGen THAT = (ClassGen) o2;
- return Objects.equals(THIS.getClassName(), THAT.getClassName());
+ public boolean equals(final ClassGen a, final ClassGen b) {
+ return a == b || a != null && b != null && Objects.equals(a.getClassName(), b.getClassName());
}
@Override
- public int hashCode(final Object o) {
- final ClassGen THIS = (ClassGen) o;
- return THIS.getClassName().hashCode();
+ public int hashCode(final ClassGen o) {
+ return o != null ? Objects.hashCode(o.getClassName()) : 0;
}
};
/**
* @return Comparison strategy object
*/
- public static BCELComparator getComparator() {
+ public static BCELComparator getComparator() {
return bcelComparator;
}
/**
* @param comparator Comparison strategy object
*/
- public static void setComparator(final BCELComparator comparator) {
+ public static void setComparator(final BCELComparator comparator) {
bcelComparator = comparator;
}
@@ -279,7 +276,7 @@ public Method containsMethod(final String name, final String signature) {
*/
@Override
public boolean equals(final Object obj) {
- return bcelComparator.equals(this, obj);
+ return obj instanceof ClassGen && bcelComparator.equals(this, (ClassGen) obj);
}
// J5TODO: Should we make calling unpackAnnotations() lazy and put it in here?
diff --git a/src/main/java/org/apache/bcel/generic/FieldGen.java b/src/main/java/org/apache/bcel/generic/FieldGen.java
index 052ab4c4ed..d964d15bb5 100644
--- a/src/main/java/org/apache/bcel/generic/FieldGen.java
+++ b/src/main/java/org/apache/bcel/generic/FieldGen.java
@@ -40,33 +40,30 @@
*/
public class FieldGen extends FieldGenOrMethodGen {
- private static BCELComparator bcelComparator = new BCELComparator() {
+ private static BCELComparator bcelComparator = new BCELComparator() {
@Override
- public boolean equals(final Object o1, final Object o2) {
- final FieldGen THIS = (FieldGen) o1;
- final FieldGen THAT = (FieldGen) o2;
- return Objects.equals(THIS.getName(), THAT.getName()) && Objects.equals(THIS.getSignature(), THAT.getSignature());
+ public boolean equals(final FieldGen a, final FieldGen b) {
+ return a == b || a != null && b != null && Objects.equals(a.getName(), b.getName()) && Objects.equals(a.getSignature(), b.getSignature());
}
@Override
- public int hashCode(final Object o) {
- final FieldGen THIS = (FieldGen) o;
- return THIS.getSignature().hashCode() ^ THIS.getName().hashCode();
+ public int hashCode(final FieldGen o) {
+ return o != null ? Objects.hash(o.getSignature(), o.getName()) : 0;
}
};
/**
- * @return Comparison strategy object
+ * @return Comparison strategy object.
*/
- public static BCELComparator getComparator() {
+ public static BCELComparator getComparator() {
return bcelComparator;
}
/**
- * @param comparator Comparison strategy object
+ * @param comparator Comparison strategy object.
*/
- public static void setComparator(final BCELComparator comparator) {
+ public static void setComparator(final BCELComparator comparator) {
bcelComparator = comparator;
}
@@ -77,8 +74,8 @@ public static void setComparator(final BCELComparator comparator) {
/**
* Instantiate from existing field.
*
- * @param field Field object
- * @param cp constant pool (must contain the same entries as the field's constant pool)
+ * @param field Field object.
+ * @param cp constant pool (must contain the same entries as the field's constant pool).
*/
public FieldGen(final Field field, final ConstantPoolGen cp) {
this(field.getAccessFlags(), Type.getType(field.getSignature()), field.getName(), cp);
@@ -183,7 +180,7 @@ public FieldGen copy(final ConstantPoolGen cp) {
*/
@Override
public boolean equals(final Object obj) {
- return bcelComparator.equals(this, obj);
+ return obj instanceof FieldGen && bcelComparator.equals(this, (FieldGen) obj);
}
/**
diff --git a/src/main/java/org/apache/bcel/generic/MethodGen.java b/src/main/java/org/apache/bcel/generic/MethodGen.java
index 3cf8f7339a..1cccda44a9 100644
--- a/src/main/java/org/apache/bcel/generic/MethodGen.java
+++ b/src/main/java/org/apache/bcel/generic/MethodGen.java
@@ -99,19 +99,16 @@ static final class BranchTarget {
}
}
- private static BCELComparator bcelComparator = new BCELComparator() {
+ private static BCELComparator bcelComparator = new BCELComparator() {
@Override
- public boolean equals(final Object o1, final Object o2) {
- final FieldGenOrMethodGen THIS = (FieldGenOrMethodGen) o1;
- final FieldGenOrMethodGen THAT = (FieldGenOrMethodGen) o2;
- return Objects.equals(THIS.getName(), THAT.getName()) && Objects.equals(THIS.getSignature(), THAT.getSignature());
+ public boolean equals(final FieldGenOrMethodGen a, final FieldGenOrMethodGen b) {
+ return a == b || a != null && b != null && Objects.equals(a.getName(), b.getName()) && Objects.equals(a.getSignature(), b.getSignature());
}
@Override
- public int hashCode(final Object o) {
- final FieldGenOrMethodGen THIS = (FieldGenOrMethodGen) o;
- return THIS.getSignature().hashCode() ^ THIS.getName().hashCode();
+ public int hashCode(final FieldGenOrMethodGen o) {
+ return o != null ? Objects.hash(o.getSignature(), o.getName()) : 0;
}
};
@@ -124,9 +121,9 @@ private static byte[] getByteCodes(final Method method) {
}
/**
- * @return Comparison strategy object
+ * @return Comparison strategy object.
*/
- public static BCELComparator getComparator() {
+ public static BCELComparator getComparator() {
return bcelComparator;
}
@@ -203,9 +200,9 @@ public static int getMaxStack(final ConstantPoolGen cp, final InstructionList il
}
/**
- * @param comparator Comparison strategy object
+ * @param comparator Comparison strategy object.
*/
- public static void setComparator(final BCELComparator comparator) {
+ public static void setComparator(final BCELComparator comparator) {
bcelComparator = comparator;
}
@@ -633,7 +630,7 @@ private void ensureExistingParameterAnnotationsUnpacked() {
*/
@Override
public boolean equals(final Object obj) {
- return bcelComparator.equals(this, obj);
+ return obj instanceof FieldGenOrMethodGen && bcelComparator.equals(this, (FieldGenOrMethodGen) obj);
}
// J5TODO: Should paramAnnotations be an array of arrays? Rather than an array of lists, this
diff --git a/src/main/java/org/apache/bcel/util/BCELComparator.java b/src/main/java/org/apache/bcel/util/BCELComparator.java
index 4e0d8a4a44..98e5d50f3b 100644
--- a/src/main/java/org/apache/bcel/util/BCELComparator.java
+++ b/src/main/java/org/apache/bcel/util/BCELComparator.java
@@ -17,26 +17,27 @@
package org.apache.bcel.util;
/**
- * Used for BCEL comparison strategy
+ * Used for BCEL comparison strategy.
*
+ * @param What type we are comparing.
* @since 5.2
*/
-public interface BCELComparator {
+public interface BCELComparator {
/**
- * Compare two objects and return what THIS.equals(THAT) should return
+ * Compares two objects and return what a.equals(b) should return.
*
- * @param THIS
- * @param THAT
- * @return true if and only if THIS equals THAT
+ * @param a an object.
+ * @param b an object to be compared with {@code a} for equality.
+ * @return {@code true} if the arguments are equal to each other and {@code false} otherwise.
*/
- boolean equals(Object THIS, Object THAT);
+ boolean equals(T a, T b);
/**
- * Return hash code for THIS.hashCode()
+ * Gets the hash code for o.hashCode()
*
- * @param THIS
- * @return hash code for THIS.hashCode()
+ * @param o
+ * @return hash code for o.hashCode()
*/
- int hashCode(Object THIS);
+ int hashCode(T o);
}
diff --git a/src/test/java/org/apache/bcel/classfile/ConstantTest.java b/src/test/java/org/apache/bcel/classfile/ConstantTest.java
new file mode 100644
index 0000000000..3769b58bbd
--- /dev/null
+++ b/src/test/java/org/apache/bcel/classfile/ConstantTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link Constant}.
+ */
+public class ConstantTest {
+
+ @Test
+ public void testBCELComparator() throws Exception {
+ final Constant obj = new ConstantClass(1);
+ assertTrue(Constant.getComparator().equals(null, null));
+ assertTrue(Constant.getComparator().equals(obj, obj));
+ assertFalse(Constant.getComparator().equals(obj, null));
+ assertFalse(Constant.getComparator().equals(null, obj));
+ }
+}
diff --git a/src/test/java/org/apache/bcel/classfile/FieldTest.java b/src/test/java/org/apache/bcel/classfile/FieldTest.java
new file mode 100644
index 0000000000..3b41293f2b
--- /dev/null
+++ b/src/test/java/org/apache/bcel/classfile/FieldTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link Field}.
+ */
+public class FieldTest {
+
+ @Test
+ public void testBCELComparator() throws Exception {
+ final Field obj = new Field(1, 1, 1, null, null);
+ assertTrue(Field.getComparator().equals(null, null));
+ assertTrue(Field.getComparator().equals(obj, obj));
+ assertFalse(Field.getComparator().equals(obj, null));
+ assertFalse(Field.getComparator().equals(null, obj));
+ }
+}
diff --git a/src/test/java/org/apache/bcel/generic/ClassGenTest.java b/src/test/java/org/apache/bcel/generic/ClassGenTest.java
new file mode 100644
index 0000000000..742805b29e
--- /dev/null
+++ b/src/test/java/org/apache/bcel/generic/ClassGenTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.generic;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link ClassGen}.
+ */
+public class ClassGenTest {
+
+ @Test
+ public void testBCELComparator() throws Exception {
+ final ClassGen obj = new ClassGen("", "", "", 0, null);
+ assertTrue(ClassGen.getComparator().equals(null, null));
+ assertTrue(ClassGen.getComparator().equals(obj, obj));
+ assertFalse(ClassGen.getComparator().equals(obj, null));
+ assertFalse(ClassGen.getComparator().equals(null, obj));
+ }
+}
diff --git a/src/test/java/org/apache/bcel/generic/FieldGenTest.java b/src/test/java/org/apache/bcel/generic/FieldGenTest.java
new file mode 100644
index 0000000000..cbf366bbda
--- /dev/null
+++ b/src/test/java/org/apache/bcel/generic/FieldGenTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.generic;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.bcel.classfile.ConstantLong;
+import org.apache.bcel.classfile.ConstantPool;
+import org.apache.bcel.classfile.Field;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FieldGen}.
+ */
+public class FieldGenTest {
+
+ @Test
+ @Disabled
+ public void testBCELComparator() throws Exception {
+ final ConstantLong[] constantPool = { new ConstantLong(0), new ConstantLong(0) };
+ final FieldGen obj = new FieldGen(new Field(0, 0, 0, null, new ConstantPool(constantPool)), new ConstantPoolGen(constantPool));
+ assertTrue(FieldGen.getComparator().equals(null, null));
+ assertTrue(FieldGen.getComparator().equals(obj, obj));
+ assertFalse(FieldGen.getComparator().equals(obj, null));
+ assertFalse(FieldGen.getComparator().equals(null, obj));
+ }
+}
From c377b86c0bbf7bdc7a9524222a3105192fae59af Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 7 Jan 2024 13:50:40 -0500
Subject: [PATCH 40/46] Prepare for release candidate
---
CONTRIBUTING.md | 5 +--
README.md | 5 +--
RELEASE-NOTES.txt | 69 +++++++++++++++++++++++++++++++++
pom.xml | 6 +--
src/changes/release-notes.vm | 2 +-
src/site/xdoc/download_bcel.xml | 26 ++++++-------
src/site/xdoc/index.xml | 7 ----
7 files changed, 90 insertions(+), 30 deletions(-)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 8986d489e4..cd33383389 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -49,13 +49,13 @@ Getting Started
---------------
+ Make sure you have a [JIRA account](https://issues.apache.org/jira/).
-+ Make sure you have a [GitHub account](https://github.com/signup/free).
++ Make sure you have a [GitHub account](https://github.com/signup/free). This is not essential, but makes providing patches much easier.
+ If you're planning to implement a new feature it makes sense to discuss your changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons BCEL's scope.
+ Submit a [Jira Ticket][jira] for your issue, assuming one does not already exist.
+ Clearly describe the issue including steps to reproduce when it is a bug.
+ Make sure you fill in the earliest version that you know has the issue.
+ Find the corresponding [repository on GitHub](https://github.com/apache/?query=commons-),
-[fork](https://help.github.com/articles/fork-a-repo/) and check out your forked repository.
+[fork](https://help.github.com/articles/fork-a-repo/) and check out your forked repository. If you don't have a GitHub account, you can still clone the Commons repository.
Making Changes
--------------
@@ -109,7 +109,6 @@ Additional Resources
+ [General GitHub documentation](https://help.github.com/)
+ [GitHub pull request documentation](https://help.github.com/articles/creating-a-pull-request/)
+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
-+ `#apache-commons` IRC channel on `irc.freenode.net`
[cla]:https://www.apache.org/licenses/#clas
[jira]:https://issues.apache.org/jira/browse/BCEL
diff --git a/README.md b/README.md
index d14a423ddb..4e10557350 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@ Apache Commons BCEL
[![Java CI](https://github.com/apache/commons-bcel/actions/workflows/maven.yml/badge.svg)](https://github.com/apache/commons-bcel/actions/workflows/maven.yml)
[![Coverage Status](https://codecov.io/gh/apache/commons-bcel/branch/master/graph/badge.svg)](https://app.codecov.io/gh/apache/commons-bcel)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.bcel/bcel/badge.svg?gav=true)](https://maven-badges.herokuapp.com/maven-central/org.apache.bcel/bcel/?gav=true)
-[![Javadocs](https://javadoc.io/badge/org.apache.bcel/bcel/6.8.0.svg)](https://javadoc.io/doc/org.apache.bcel/bcel/6.8.0)
+[![Javadocs](https://javadoc.io/badge/org.apache.bcel/bcel/6.8.1.svg)](https://javadoc.io/doc/org.apache.bcel/bcel/6.8.1)
[![CodeQL](https://github.com/apache/commons-bcel/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/apache/commons-bcel/actions/workflows/codeql-analysis.yml)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/apache/commons-bcel/badge)](https://api.securityscorecards.dev/projects/github.com/apache/commons-bcel)
@@ -69,7 +69,7 @@ Alternatively, you can pull it from the central Maven repositories:
org.apache.bcel
bcel
- 6.8.0
+ 6.8.1
```
@@ -111,7 +111,6 @@ Additional Resources
+ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/BCEL)
+ [Apache Commons Slack Channel](https://the-asf.slack.com/archives/C60NVB8AD)
+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons)
-+ `#apache-commons` IRC channel on `irc.freenode.org`
Apache Commons Components
-------------------------
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index b1d0c2e91f..926f741a78 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -1,3 +1,72 @@
+ Apache Commons BCEL
+ Version 6.8.1
+ RELEASE NOTES
+
+
+INTRODUCTION:
+
+The Apache Commons BCEL team is pleased to announce the release of
+Apache Commons BCEL 6.8.1.
+
+The Byte Code Engineering Library (BCEL) is intended to give users a convenient
+way to analyze, create, and manipulate compiled .class files. Classes are
+represented by objects containing all the symbolic information of the given
+class: methods, fields, and byte code instructions.
+
+Maintenance and bug fix release.
+
+FIXED BUGS:
+===========
+
+o Replace internal use of StringBuffer with StringBuilder. Thanks to Gary Gregory.
+o BCEL-370: CONSTANT_Dynamic is not handled in LDC #254. Thanks to Gary Gregory.
+o BCELComparator now uses generics. Thanks to Gary Gregory.
+o Avoid NullPointerException in ClassGen.BCELComparator#equals() and ClassGen.BCELComparator#hashCode(). Thanks to Gary Gregory.
+o Avoid NullPointerException in Constant.BCELComparator#equals() and Constant.BCELComparator#hashCode(). Thanks to Gary Gregory.
+o Avoid NullPointerException in Field.BCELComparator#equals() and Field.BCELComparator#hashCode(). Thanks to Gary Gregory.
+o Avoid NullPointerException in FieldGen.BCELComparator#equals() and FieldGen.BCELComparator#hashCode(). Thanks to Gary Gregory.
+o Avoid NullPointerException in JavaClass.BCELComparator#equals() and JavaClass.BCELComparator#hashCode(). Thanks to Gary Gregory.
+o Avoid NullPointerException in Method.BCELComparator#equals() and Method.BCELComparator#hashCode(). Thanks to Gary Gregory.
+o Avoid NullPointerException in MethodGen.BCELComparator#equals() and MethodGen.BCELComparator#hashCode(). Thanks to Gary Gregory.
+
+CHANGES:
+========
+
+o Bump GitHub various actions for CI builds. Thanks to Dependabot.
+o Bump jna.version from 5.13.0 to 5.14.0 #250. Thanks to Dependabot.
+o Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.21 to 1.9.22 #252. Thanks to Dependabot.
+o Bump org.apache.commons:commons-exec from 1.3 to 1.4.0 #255. Thanks to Dependabot.
+
+
+Historical list of changes: https://commons.apache.org/proper/commons-bcelchanges-report.html
+
+For complete information on Apache Commons BCEL, including instructions on how to submit bug reports,
+patches, or suggestions for improvement, see the Apache Commons BCEL website:
+
+https://commons.apache.org/proper/commons-bcel
+
+Download it from https://commons.apache.org/proper/commons-bcel/download_bcel.cgi
+
+Have fun!
+-Apache Commons BCEL team
+
+Feedback
+--------
+
+Open source works best when you give feedback:
+
+ https://commons.apache.org/bcel
+
+Please direct all bug reports to JIRA:
+
+ https://issues.apache.org/jira/browse/BCEL
+
+Or subscribe to the commons-user mailing list
+
+The Apache Commons Team
+
+-----------------------------------------------------------------------------
+
Apache Commons BCEL
Version 6.8.0
RELEASE NOTES
diff --git a/pom.xml b/pom.xml
index d875b2957a..6fde3403dc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,11 +47,11 @@
1.8
bcel
org.apache.bcel
- 6.8.0
- 6.8.1
+ 6.8.1
+ 6.8.2
true
RC1
- 6.7.0
+ 6.8.0
(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/release-notes.vm b/src/changes/release-notes.vm
index 9401b57fd2..7d1bcc9a02 100644
--- a/src/changes/release-notes.vm
+++ b/src/changes/release-notes.vm
@@ -23,7 +23,7 @@
INTRODUCTION:
The ${developmentTeam} is pleased to announce the release of
-${project.name} ${version}!
+${project.name} ${version}.
The Byte Code Engineering Library (BCEL) is intended to give users a convenient
way to analyze, create, and manipulate compiled .class files. Classes are
diff --git a/src/site/xdoc/download_bcel.xml b/src/site/xdoc/download_bcel.xml
index b07a8d3e77..4d6c7b02a2 100644
--- a/src/site/xdoc/download_bcel.xml
+++ b/src/site/xdoc/download_bcel.xml
@@ -113,32 +113,32 @@ limitations under the License.
-
+
diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml
index b8a58a8958..da5692d481 100644
--- a/src/site/xdoc/index.xml
+++ b/src/site/xdoc/index.xml
@@ -24,7 +24,6 @@
Commons Documentation Team
-
The Byte Code Engineering Library (Apache Commons BCEL™) is intended to give users a
@@ -34,7 +33,6 @@
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.
@@ -43,13 +41,11 @@
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
@@ -58,7 +54,6 @@
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
@@ -69,7 +64,6 @@
browsed, or you can browse/contribute via GitHub.
-
The latest stable release of BCEL is here, you may:
-
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].
From 6537d1ac264dc063e445f4eb78e75bcec0bc9554 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 7 Jan 2024 14:47:23 -0500
Subject: [PATCH 41/46] Move less viewed sections to the bottom
---
pom.xml | 181 +++++++++++++++++++++++++-------------------------------
1 file changed, 81 insertions(+), 100 deletions(-)
diff --git a/pom.xml b/pom.xml
index 6fde3403dc..57b2bc18ae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -82,106 +82,6 @@
https://github.com/apache/commons-bcel/actions
-
-
- Dave Brosius
- dbrosius
- dbrosius at mebigfatguy.com
-
-
-
- Torsten Curdt
- tcurdt
- tcurdt at apache.org
- ASF
- http://www.apache.org/
- +1
-
-
-
- Markus Dahm
- mdahm
- m.dahm at gmx.de
- it-frameworksolutions
-
-
-
- Jason van Zyl
- jason at zenplex.com
-
-
-
- ggregory
- Gary Gregory
- ggregory at apache.org
- https://www.garygregory.com
- The Apache Software Foundation
- https://www.apache.org/
-
- PMC Member
-
- America/New_York
-
- https://people.apache.org/~ggregory/img/garydgregory80.png
-
-
-
-
-
-
-
-
- Enver Haase
- enver at convergence.de
-
-
-
- David Dixon-Peugh
- dixonpeugh at yahoo.com
-
-
-
- Patrick Beard
- beard at netscape.com
-
-
-
- Conor MacNeill
- conor at cortexbusiness.com.au
-
-
-
- Costin Manolache
- cmanolache at yahoo.com
-
-
-
- Bill Pugh
- bill.pugh at gmail.com
-
-
-
- First Hop Ltd / Torsten Rueger
-
-
-
- Jérôme Leroux
-
-
-
- Mark Roberts
-
-
-
- Sam Yoon
-
-
-
- Arturo Bernal
-
-
-
-
BCEL User List
@@ -635,4 +535,85 @@
+
+
+ Dave Brosius
+ dbrosius
+ dbrosius at mebigfatguy.com
+
+
+ Torsten Curdt
+ tcurdt
+ tcurdt at apache.org
+ ASF
+ http://www.apache.org/
+ +1
+
+
+ Markus Dahm
+ mdahm
+ m.dahm at gmx.de
+ it-frameworksolutions
+
+
+ Jason van Zyl
+ jason at zenplex.com
+
+
+ ggregory
+ Gary Gregory
+ ggregory at apache.org
+ https://www.garygregory.com
+ The Apache Software Foundation
+ https://www.apache.org/
+
+ PMC Member
+
+ America/New_York
+
+ https://people.apache.org/~ggregory/img/garydgregory80.png
+
+
+
+
+
+ Enver Haase
+ enver at convergence.de
+
+
+ David Dixon-Peugh
+ dixonpeugh at yahoo.com
+
+
+ Patrick Beard
+ beard at netscape.com
+
+
+ Conor MacNeill
+ conor at cortexbusiness.com.au
+
+
+ Costin Manolache
+ cmanolache at yahoo.com
+
+
+ Bill Pugh
+ bill.pugh at gmail.com
+
+
+ First Hop Ltd / Torsten Rueger
+
+
+ Jérôme Leroux
+
+
+ Mark Roberts
+
+
+ Sam Yoon
+
+
+ Arturo Bernal
+
+
From bf613bd34e5da35de7f707c1c3e62576ef598d60 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 7 Jan 2024 14:48:32 -0500
Subject: [PATCH 42/46] mailingLists is defined in the parent POM
---
pom.xml | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/pom.xml b/pom.xml
index 57b2bc18ae..e25e36dbd0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -82,21 +82,6 @@
https://github.com/apache/commons-bcel/actions
-
-
- BCEL User List
- user-subscribe@commons.apache.org
- user-unsubscribe@commons.apache.org
- https://mail-archives.apache.org/mod_mbox/commons-user/
-
-
- BCEL Developer List
- dev-subscribe@commons.apache.org
- dev-unsubscribe@commons.apache.org
- https://mail-archives.apache.org/mod_mbox/commons-dev/
-
-
-
jira
https://issues.apache.org/jira/browse/BCEL
From e9ef48a10a2a732ce3e10e013b413f42b3c74921 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 7 Jan 2024 14:49:32 -0500
Subject: [PATCH 43/46] Prepare for release candidate
---
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 8f6bea689a..73c30411ee 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -64,7 +64,7 @@ The type attribute can be add,update,fix,remove.
-->
-
+
Replace internal use of StringBuffer with StringBuilder.
CONSTANT_Dynamic is not handled in LDC #254.
From 6785009095d66a4a2bc01e64d25de987847eb114 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 7 Jan 2024 19:59:39 +0000
Subject: [PATCH 44/46] Prepare for the next release candidate
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index e25e36dbd0..ee3555e50e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,7 +33,7 @@
org.apache.bcel
bcel
jar
- 6.8.1-SNAPSHOT
+ 6.8.1
Apache Commons BCEL
Apache Commons Bytecode Engineering Library
From d4e2815344509d30e2a615c8d3ff32fbaec60bac Mon Sep 17 00:00:00 2001
From: Mark Roberts
Date: Wed, 17 Jan 2024 09:24:45 -0800
Subject: [PATCH 45/46] restore file deleted by accident during merge
---
README-codespecs.txt | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
create mode 100644 README-codespecs.txt
diff --git a/README-codespecs.txt b/README-codespecs.txt
new file mode 100644
index 0000000000..47f8e257d2
--- /dev/null
+++ b/README-codespecs.txt
@@ -0,0 +1,32 @@
+This is a version of Apache BCEL that contains fixes to the released version of
+Apache BCEL. It is used as an upstream master for a version of BCEL with type
+annotations in https://github.com/typetools/commons-bcel. It is this latter
+version that is released as part of Daikon via bcel-util--all.jar.
+
+If there are no local fixes needed, this repository is not needed/used for a Daikon release;
+https://github/typetools/commons-bcel can pull directly from https://github.com/apache/commons-bcel.
+
+
+To build this project
+---------------------
+
+```
+mvn verify
+```
+
+The `.jar` file is found at, for example, `target/bcel-6.2.0.1.jar`.
+
+
+To update to a newer version of the upstream library
+----------------------------------------------------
+
+At https://github.com/apache/commons-bcel/releases ,
+find the commit corresponding to a public release.
+
+Pull in that commit:
+git pull https://github.com/apache/commons-bcel
+
+Resolve any conflicts with our local changes and rebuild.
+If there is a merge conflict related to version numbers,
+use the upstream version number.
+
From 57a75645eca53ea01746b67791750218495fbf84 Mon Sep 17 00:00:00 2001
From: Mark Roberts
Date: Wed, 17 Jan 2024 09:26:05 -0800
Subject: [PATCH 46/46] improve instructions
---
README-codespecs.txt | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/README-codespecs.txt b/README-codespecs.txt
index 47f8e257d2..75b02b4b78 100644
--- a/README-codespecs.txt
+++ b/README-codespecs.txt
@@ -11,10 +11,12 @@ To build this project
---------------------
```
-mvn verify
+mvn -B clean verify
```
-The `.jar` file is found at, for example, `target/bcel-6.2.0.1.jar`.
+(You may need to add -Drat.skip=true if you have local untracked files.)
+
+The `.jar` file will be found in the target subdirectory at, for example, `target/bcel-6.8.1.jar`.
To update to a newer version of the upstream library