You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/01/16 18:28:29 UTC

[commons-bcel] branch master updated: Define and reuse constants within Commons BCEL and from Commons Lang.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4d58176  Define and reuse constants within Commons BCEL and from Commons Lang.
4d58176 is described below

commit 4d581761689b67e2305204a6a02b97532be90aab
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 16 13:28:24 2021 -0500

    Define and reuse constants within Commons BCEL and from Commons Lang.
    
    Bump minor version since we added a public element.
---
 pom.xml                                              |  7 +++----
 src/main/java/org/apache/bcel/ExceptionConst.java    |  9 +++++++++
 .../java/org/apache/bcel/ExceptionConstants.java     |  8 ++++++++
 .../java/org/apache/bcel/classfile/Attribute.java    |  7 +++++++
 src/main/java/org/apache/bcel/classfile/Code.java    | 13 +++++++------
 .../org/apache/bcel/classfile/CodeException.java     |  5 +++++
 .../org/apache/bcel/classfile/ExceptionTable.java    |  5 +++--
 src/main/java/org/apache/bcel/classfile/Field.java   |  5 +++++
 .../java/org/apache/bcel/classfile/InnerClasses.java |  9 +++++++--
 .../java/org/apache/bcel/classfile/JavaClass.java    |  9 +++++----
 src/main/java/org/apache/bcel/classfile/Method.java  |  5 +++++
 .../org/apache/bcel/classfile/MethodParameters.java  |  7 ++++++-
 .../org/apache/bcel/classfile/ModulePackages.java    |  5 +++--
 .../java/org/apache/bcel/classfile/NestMembers.java  |  5 +++--
 .../org/apache/bcel/classfile/StackMapEntry.java     | 17 +++++++++++------
 .../org/apache/bcel/generic/AnnotationEntryGen.java  |  2 +-
 .../org/apache/bcel/generic/InstructionHandle.java   | 14 +++++++++++++-
 .../org/apache/bcel/generic/InstructionList.java     |  3 ++-
 src/main/java/org/apache/bcel/generic/MethodGen.java |  2 +-
 src/main/java/org/apache/bcel/generic/Type.java      |  6 +++++-
 .../org/apache/bcel/verifier/VerifierAppFrame.java   |  9 +++++----
 .../bcel/verifier/structurals/ControlFlowGraph.java  |  5 ++---
 .../bcel/verifier/structurals/ExceptionHandlers.java | 20 +++++++++++---------
 .../bcel/verifier/structurals/Subroutines.java       |  7 +++----
 24 files changed, 130 insertions(+), 54 deletions(-)

diff --git a/pom.xml b/pom.xml
index e535918..fe3e420 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,7 +33,7 @@
   <groupId>org.apache.bcel</groupId>
   <artifactId>bcel</artifactId>
   <packaging>jar</packaging>
-  <version>6.5.1-SNAPSHOT</version>
+  <version>6.6.0-SNAPSHOT</version>
   <name>Apache Commons BCEL</name>
   <description>Apache Commons Bytecode Engineering Library</description>
 
@@ -47,10 +47,10 @@
     <maven.compiler.target>1.8</maven.compiler.target>
     <commons.componentid>bcel</commons.componentid>
     <commons.module.name>org.apache.bcel</commons.module.name>
-    <commons.release.version>6.5.0</commons.release.version>
+    <commons.release.version>6.6.0</commons.release.version>
     <commons.release.isDistModule>true</commons.release.isDistModule>
     <commons.rc.version>RC1</commons.rc.version>
-    <commons.bc.version>6.4.1</commons.bc.version>
+    <commons.bc.version>6.5.0</commons.bc.version>
     <commons.release.desc>(Java 8)</commons.release.desc>
     <commons.scmPubUrl>https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-bcel</commons.scmPubUrl>
     <commons.distSvnStagingUrl>scm:svn:https://dist.apache.org/repos/dist/dev/commons/${commons.componentid}</commons.distSvnStagingUrl>
@@ -477,7 +477,6 @@
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-lang3</artifactId>
       <version>3.11</version>
-      <scope>test</scope>
     </dependency>
     <dependency>
        <!-- BCEL-336 refers to this specific version.  -->
diff --git a/src/main/java/org/apache/bcel/ExceptionConst.java b/src/main/java/org/apache/bcel/ExceptionConst.java
index ed2c426..6cffc56 100644
--- a/src/main/java/org/apache/bcel/ExceptionConst.java
+++ b/src/main/java/org/apache/bcel/ExceptionConst.java
@@ -78,8 +78,17 @@ public final class ExceptionConst {
     private static final Class<?>[] EXCS_FIELD_AND_METHOD_RESOLUTION = {
             NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR
     }; // Chapter 5.2
+
+    /**
+     * Empty array.
+     */
     private static final Class<?>[] EXCS_INTERFACE_METHOD_RESOLUTION = new Class[0]; // Chapter 5.3 (as below)
+    
+    /**
+     * Empty array.
+     */
     private static final Class<?>[] EXCS_STRING_RESOLUTION = new Class[0];
+
     // Chapter 5.4 (no errors but the ones that _always_ could happen! How stupid.)
     private static final Class<?>[] EXCS_ARRAY_EXCEPTION = {
             NULL_POINTER_EXCEPTION, ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION
diff --git a/src/main/java/org/apache/bcel/ExceptionConstants.java b/src/main/java/org/apache/bcel/ExceptionConstants.java
index ea0e1ce..ed9c846 100644
--- a/src/main/java/org/apache/bcel/ExceptionConstants.java
+++ b/src/main/java/org/apache/bcel/ExceptionConstants.java
@@ -74,8 +74,16 @@ public interface ExceptionConstants {
     Class<?>[] EXCS_FIELD_AND_METHOD_RESOLUTION = {
             NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR
     }; // Chapter 5.2
+
+    /**
+     * Empty array.
+     */
     @Deprecated
     Class<?>[] EXCS_INTERFACE_METHOD_RESOLUTION = new Class[0]; // Chapter 5.3 (as below)
+    
+    /**
+     * Empty array.
+     */
     @Deprecated
     Class<?>[] EXCS_STRING_RESOLUTION = new Class[0];
     // Chapter 5.4 (no errors but the ones that _always_ could happen! How stupid.)
diff --git a/src/main/java/org/apache/bcel/classfile/Attribute.java b/src/main/java/org/apache/bcel/classfile/Attribute.java
index 72e5c4e..185360e 100644
--- a/src/main/java/org/apache/bcel/classfile/Attribute.java
+++ b/src/main/java/org/apache/bcel/classfile/Attribute.java
@@ -53,6 +53,13 @@ public abstract class Attribute implements Cloneable, Node {
     private static final Map<String, Object> readers = new HashMap<>();
 
     /**
+     * Empty array.
+     *
+     * @since 6.6.0
+     */
+    public static final Attribute[] EMPTY_ATTRIBUTE_ARRAY = new Attribute[0];
+
+    /**
      * Add an Attribute reader capable of parsing (user-defined) attributes
      * named "name". You should not add readers for the standard attributes such
      * as "LineNumberTable", because those are handled internally.
diff --git a/src/main/java/org/apache/bcel/classfile/Code.java b/src/main/java/org/apache/bcel/classfile/Code.java
index 5e81d21..cedc535 100644
--- a/src/main/java/org/apache/bcel/classfile/Code.java
+++ b/src/main/java/org/apache/bcel/classfile/Code.java
@@ -22,6 +22,7 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 
 import org.apache.bcel.Const;
+import org.apache.commons.lang3.ArrayUtils;
 
 /**
  * This class represents a chunk of Java byte code contained in a
@@ -112,9 +113,9 @@ public final class Code extends Attribute {
         super(Const.ATTR_CODE, name_index, length, constant_pool);
         this.maxStack = maxStack;
         this.maxLocals = maxLocals;
-        this.code = code != null ? code : new byte[0];
-        this.exceptionTable = exceptionTable != null ? exceptionTable : new CodeException[0];
-        this.attributes = attributes != null ? attributes : new Attribute[0];
+        this.code = code != null ? code : ArrayUtils.EMPTY_BYTE_ARRAY;
+        this.exceptionTable = exceptionTable != null ? exceptionTable : CodeException.EMPTY_CODE_EXCEPTION_ARRAY;
+        this.attributes = attributes != null ? attributes : EMPTY_ATTRIBUTE_ARRAY;
         super.setLength(calculateLength()); // Adjust length
     }
 
@@ -256,7 +257,7 @@ public final class Code extends Attribute {
      * @param attributes the attributes to set for this Code
      */
     public void setAttributes( final Attribute[] attributes ) {
-        this.attributes = attributes != null ? attributes : new Attribute[0];
+        this.attributes = attributes != null ? attributes : EMPTY_ATTRIBUTE_ARRAY;
         super.setLength(calculateLength()); // Adjust length
     }
 
@@ -265,7 +266,7 @@ public final class Code extends Attribute {
      * @param code byte code
      */
     public void setCode( final byte[] code ) {
-        this.code = code != null ? code : new byte[0];
+        this.code = code != null ? code : ArrayUtils.EMPTY_BYTE_ARRAY;
         super.setLength(calculateLength()); // Adjust length
     }
 
@@ -274,7 +275,7 @@ public final class Code extends Attribute {
      * @param exceptionTable exception table
      */
     public void setExceptionTable( final CodeException[] exceptionTable ) {
-        this.exceptionTable = exceptionTable != null ? exceptionTable : new CodeException[0];
+        this.exceptionTable = exceptionTable != null ? exceptionTable : CodeException.EMPTY_CODE_EXCEPTION_ARRAY;
         super.setLength(calculateLength()); // Adjust length
     }
 
diff --git a/src/main/java/org/apache/bcel/classfile/CodeException.java b/src/main/java/org/apache/bcel/classfile/CodeException.java
index d223f08..9c7cdf1 100644
--- a/src/main/java/org/apache/bcel/classfile/CodeException.java
+++ b/src/main/java/org/apache/bcel/classfile/CodeException.java
@@ -43,6 +43,11 @@ public final class CodeException implements Cloneable, Node, Constants {
      * exception class which is to be caught.
      */
 
+    /**
+     * Empty array.
+     */
+    static final CodeException[] EMPTY_CODE_EXCEPTION_ARRAY = new CodeException[0];
+
 
     /**
      * Initialize from another object.
diff --git a/src/main/java/org/apache/bcel/classfile/ExceptionTable.java b/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
index f267566..6333f2b 100644
--- a/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
+++ b/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
@@ -22,6 +22,7 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 
 import org.apache.bcel.Const;
+import org.apache.commons.lang3.ArrayUtils;
 
 /**
  * This class represents the table of exceptions that are thrown by a
@@ -56,7 +57,7 @@ public final class ExceptionTable extends Attribute {
     public ExceptionTable(final int name_index, final int length, final int[] exceptionIndexTable,
             final ConstantPool constant_pool) {
         super(Const.ATTR_EXCEPTIONS, name_index, length, constant_pool);
-        this.exceptionIndexTable = exceptionIndexTable != null ? exceptionIndexTable : new int[0];
+        this.exceptionIndexTable = exceptionIndexTable != null ? exceptionIndexTable : ArrayUtils.EMPTY_INT_ARRAY;
     }
 
 
@@ -141,7 +142,7 @@ public final class ExceptionTable extends Attribute {
      * Also redefines number_of_exceptions according to table length.
      */
     public void setExceptionIndexTable( final int[] exceptionIndexTable ) {
-        this.exceptionIndexTable = exceptionIndexTable != null ? exceptionIndexTable : new int[0];
+        this.exceptionIndexTable = exceptionIndexTable != null ? exceptionIndexTable : ArrayUtils.EMPTY_INT_ARRAY;
     }
 
 
diff --git a/src/main/java/org/apache/bcel/classfile/Field.java b/src/main/java/org/apache/bcel/classfile/Field.java
index 7dea3dd..ad0328d 100644
--- a/src/main/java/org/apache/bcel/classfile/Field.java
+++ b/src/main/java/org/apache/bcel/classfile/Field.java
@@ -50,6 +50,11 @@ public final class Field extends FieldOrMethod {
         }
     };
 
+    /**
+     * Empty array.
+     */
+    static final Field[] EMPTY_FIELD_ARRAY = new Field[0];
+
 
     /**
      * Initialize from another object. Note that both objects use the same
diff --git a/src/main/java/org/apache/bcel/classfile/InnerClasses.java b/src/main/java/org/apache/bcel/classfile/InnerClasses.java
index cb3aadc..d0518be 100644
--- a/src/main/java/org/apache/bcel/classfile/InnerClasses.java
+++ b/src/main/java/org/apache/bcel/classfile/InnerClasses.java
@@ -33,6 +33,11 @@ import org.apache.bcel.Const;
  */
 public final class InnerClasses extends Attribute {
 
+    /**
+     * Empty array.
+     */
+    private static final InnerClass[] EMPTY_INNER_CLASSE_ARRAY = new InnerClass[0];
+
     private InnerClass[] innerClasses;
 
 
@@ -54,7 +59,7 @@ public final class InnerClasses extends Attribute {
     public InnerClasses(final int name_index, final int length, final InnerClass[] innerClasses,
             final ConstantPool constant_pool) {
         super(Const.ATTR_INNER_CLASSES, name_index, length, constant_pool);
-        this.innerClasses = innerClasses != null ? innerClasses : new InnerClass[0];
+        this.innerClasses = innerClasses != null ? innerClasses : EMPTY_INNER_CLASSE_ARRAY;
     }
 
 
@@ -119,7 +124,7 @@ public final class InnerClasses extends Attribute {
      * @param innerClasses the array of inner classes
      */
     public void setInnerClasses( final InnerClass[] innerClasses ) {
-        this.innerClasses = innerClasses != null ? innerClasses : new InnerClass[0];
+        this.innerClasses = innerClasses != null ? innerClasses : EMPTY_INNER_CLASSE_ARRAY;
     }
 
 
diff --git a/src/main/java/org/apache/bcel/classfile/JavaClass.java b/src/main/java/org/apache/bcel/classfile/JavaClass.java
index 9a07272..86dab53 100644
--- a/src/main/java/org/apache/bcel/classfile/JavaClass.java
+++ b/src/main/java/org/apache/bcel/classfile/JavaClass.java
@@ -35,6 +35,7 @@ import org.apache.bcel.generic.Type;
 import org.apache.bcel.util.BCELComparator;
 import org.apache.bcel.util.ClassQueue;
 import org.apache.bcel.util.SyntheticRepository;
+import org.apache.commons.lang3.ArrayUtils;
 
 /**
  * Represents a Java class, i.e., the data structures, constant pool,
@@ -121,16 +122,16 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
             Field[] fields, Method[] methods, Attribute[] attributes, final byte source) {
         super(access_flags);
         if (interfaces == null) {
-            interfaces = new int[0];
+            interfaces = ArrayUtils.EMPTY_INT_ARRAY;
         }
         if (attributes == null) {
-            attributes = new Attribute[0];
+            attributes = Attribute.EMPTY_ATTRIBUTE_ARRAY;
         }
         if (fields == null) {
-            fields = new Field[0];
+            fields = Field.EMPTY_FIELD_ARRAY;
         }
         if (methods == null) {
-            methods = new Method[0];
+            methods = Method.EMPTY_METHOD_ARRAY;
         }
         this.classNameIndex = classNameIndex;
         this.superclassNameIndex = superclassNameIndex;
diff --git a/src/main/java/org/apache/bcel/classfile/Method.java b/src/main/java/org/apache/bcel/classfile/Method.java
index 8f9b8d6..a414de7 100644
--- a/src/main/java/org/apache/bcel/classfile/Method.java
+++ b/src/main/java/org/apache/bcel/classfile/Method.java
@@ -55,6 +55,11 @@ public final class Method extends FieldOrMethod {
     private ParameterAnnotationEntry[] parameterAnnotationEntries;
 
     /**
+     * Empty array.
+     */
+    static final Method[] EMPTY_METHOD_ARRAY = new Method[0];
+
+    /**
      * Empty constructor, all attributes have to be defined via `setXXX'
      * methods. Use at your own risk.
      */
diff --git a/src/main/java/org/apache/bcel/classfile/MethodParameters.java b/src/main/java/org/apache/bcel/classfile/MethodParameters.java
index b811436..91e2825 100644
--- a/src/main/java/org/apache/bcel/classfile/MethodParameters.java
+++ b/src/main/java/org/apache/bcel/classfile/MethodParameters.java
@@ -32,7 +32,12 @@ import org.apache.bcel.Const;
  */
 public class MethodParameters extends Attribute {
 
-    private MethodParameter[] parameters = new MethodParameter[0];
+    /**
+     * Empty array.
+     */
+    private static final MethodParameter[] EMPTY_METHOD_PARAMETER_ARRAY = new MethodParameter[0];
+
+    private MethodParameter[] parameters = EMPTY_METHOD_PARAMETER_ARRAY;
 
     MethodParameters(final int name_index, final int length, final DataInput input, final ConstantPool constant_pool) throws IOException {
         super(Const.ATTR_METHOD_PARAMETERS, name_index, length, constant_pool);
diff --git a/src/main/java/org/apache/bcel/classfile/ModulePackages.java b/src/main/java/org/apache/bcel/classfile/ModulePackages.java
index e6aa307..70fa193 100644
--- a/src/main/java/org/apache/bcel/classfile/ModulePackages.java
+++ b/src/main/java/org/apache/bcel/classfile/ModulePackages.java
@@ -21,6 +21,7 @@ import java.io.DataInput;
 import java.io.DataOutputStream;
 import java.io.IOException;
 
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.bcel.Const;
 
 /**
@@ -52,7 +53,7 @@ public final class ModulePackages extends Attribute {
     public ModulePackages(final int nameIndex, final int length, final int[] packageIndexTable,
             final ConstantPool constantPool) {
         super(Const.ATTR_MODULE_PACKAGES, nameIndex, length, constantPool);
-        this.packageIndexTable = packageIndexTable != null ? packageIndexTable : new int[0];
+        this.packageIndexTable = packageIndexTable != null ? packageIndexTable : ArrayUtils.EMPTY_INT_ARRAY;
     }
 
 
@@ -137,7 +138,7 @@ public final class ModulePackages extends Attribute {
      * Also redefines number_of_packages according to table length.
      */
     public void setPackageIndexTable( final int[] packageIndexTable ) {
-        this.packageIndexTable = packageIndexTable != null ? packageIndexTable : new int[0];
+        this.packageIndexTable = packageIndexTable != null ? packageIndexTable : ArrayUtils.EMPTY_INT_ARRAY;
     }
 
 
diff --git a/src/main/java/org/apache/bcel/classfile/NestMembers.java b/src/main/java/org/apache/bcel/classfile/NestMembers.java
index 4dbb185..a8a5ae2 100644
--- a/src/main/java/org/apache/bcel/classfile/NestMembers.java
+++ b/src/main/java/org/apache/bcel/classfile/NestMembers.java
@@ -22,6 +22,7 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 
 import org.apache.bcel.Const;
+import org.apache.commons.lang3.ArrayUtils;
 
 /**
  * This class is derived from <em>Attribute</em> and records the classes and interfaces that
@@ -53,7 +54,7 @@ public final class NestMembers extends Attribute {
     public NestMembers(final int name_index, final int length, final int[] classes,
             final ConstantPool constant_pool) {
         super(Const.ATTR_NEST_MEMBERS, name_index, length, constant_pool);
-        this.classes = classes != null ? classes : new int[0];
+        this.classes = classes != null ? classes : ArrayUtils.EMPTY_INT_ARRAY;
     }
 
 
@@ -138,7 +139,7 @@ public final class NestMembers extends Attribute {
      * Also redefines number_of_classes according to table length.
      */
     public void setClasses( final int[] classes ) {
-        this.classes = classes != null ? classes : new int[0];
+        this.classes = classes != null ? classes : ArrayUtils.EMPTY_INT_ARRAY;
     }
 
 
diff --git a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
index ef23b71..9a11104 100644
--- a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
+++ b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
@@ -33,6 +33,11 @@ import org.apache.bcel.Const;
 public final class StackMapEntry implements Node, Cloneable
 {
 
+    /**
+     * Empty array.
+     */
+    private static final StackMapType[] EMPTY_STACK_MAP_TYPE_ARRAY = new StackMapType[0];
+
     private int frameType;
     private int byteCodeOffset;
     private StackMapType[] typesOfLocals;
@@ -106,8 +111,8 @@ public final class StackMapEntry implements Node, Cloneable
             final StackMapType[] typesOfLocals, final int numberOfStackItems,
             final StackMapType[] typesOfStackItems, final ConstantPool constantPool) {
         this.byteCodeOffset = byteCodeOffset;
-        this.typesOfLocals = typesOfLocals != null ? typesOfLocals : new StackMapType[0];
-        this.typesOfStackItems = typesOfStackItems != null ? typesOfStackItems : new StackMapType[0];
+        this.typesOfLocals = typesOfLocals != null ? typesOfLocals : EMPTY_STACK_MAP_TYPE_ARRAY;
+        this.typesOfStackItems = typesOfStackItems != null ? typesOfStackItems : EMPTY_STACK_MAP_TYPE_ARRAY;
         this.constantPool = constantPool;
     }
 
@@ -125,8 +130,8 @@ public final class StackMapEntry implements Node, Cloneable
             final StackMapType[] typesOfStackItems, final ConstantPool constantPool) {
         this.frameType = tag;
         this.byteCodeOffset = byteCodeOffset;
-        this.typesOfLocals = typesOfLocals != null ? typesOfLocals : new StackMapType[0];
-        this.typesOfStackItems = typesOfStackItems != null ? typesOfStackItems : new StackMapType[0];
+        this.typesOfLocals = typesOfLocals != null ? typesOfLocals : EMPTY_STACK_MAP_TYPE_ARRAY;
+        this.typesOfStackItems = typesOfStackItems != null ? typesOfStackItems : EMPTY_STACK_MAP_TYPE_ARRAY;
         this.constantPool = constantPool;
     }
 
@@ -349,7 +354,7 @@ public final class StackMapEntry implements Node, Cloneable
 
 
     public void setTypesOfLocals( final StackMapType[] types ) {
-        typesOfLocals = types != null ? types : new StackMapType[0];
+        typesOfLocals = types != null ? types : EMPTY_STACK_MAP_TYPE_ARRAY;
     }
 
 
@@ -373,7 +378,7 @@ public final class StackMapEntry implements Node, Cloneable
 
 
     public void setTypesOfStackItems( final StackMapType[] types ) {
-        typesOfStackItems = types != null ? types : new StackMapType[0];
+        typesOfStackItems = types != null ? types : EMPTY_STACK_MAP_TYPE_ARRAY;
     }
 
 
diff --git a/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java b/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
index 016655d..5832af9 100644
--- a/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
+++ b/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
@@ -198,7 +198,7 @@ public class AnnotationEntryGen {
      */
     static Attribute[] getAnnotationAttributes(final ConstantPoolGen cp, final AnnotationEntryGen[] annotationEntryGens) {
         if (annotationEntryGens.length == 0) {
-            return new Attribute[0];
+            return Attribute.EMPTY_ATTRIBUTE_ARRAY;
         }
 
         try {
diff --git a/src/main/java/org/apache/bcel/generic/InstructionHandle.java b/src/main/java/org/apache/bcel/generic/InstructionHandle.java
index 2e68219..0441339 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionHandle.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionHandle.java
@@ -43,6 +43,18 @@ import org.apache.bcel.classfile.Utility;
  */
 public class InstructionHandle {
 
+    /**
+     * Empty array.
+     *
+     * @since 6.6.0
+     */
+    public static final InstructionHandle[] EMPTY_INSTRUCTION_HANDLE_ARRAY = new InstructionHandle[0];
+
+    /**
+     * Empty array.
+     */
+    static final InstructionTargeter[] EMPTY_INSTRUCTION_TARGETER_ARRAY = new InstructionTargeter[0];
+    
     private InstructionHandle next;
     private InstructionHandle prev;
     private Instruction instruction;
@@ -216,7 +228,7 @@ public class InstructionHandle {
      */
     public InstructionTargeter[] getTargeters() {
         if (!hasTargeters()) {
-            return new InstructionTargeter[0];
+            return EMPTY_INSTRUCTION_TARGETER_ARRAY;
         }
         final InstructionTargeter[] t = new InstructionTargeter[targeters.size()];
         targeters.toArray(t);
diff --git a/src/main/java/org/apache/bcel/generic/InstructionList.java b/src/main/java/org/apache/bcel/generic/InstructionList.java
index 9e591bf..53ce717 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionList.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionList.java
@@ -30,6 +30,7 @@ import java.util.NoSuchElementException;
 import org.apache.bcel.Const;
 import org.apache.bcel.classfile.Constant;
 import org.apache.bcel.util.ByteSequence;
+import org.apache.commons.lang3.ArrayUtils;
 
 /**
  * This class is a container for a list of <a href="Instruction.html">Instruction</a> objects. Instructions can be appended, inserted, moved, deleted, etc..
@@ -945,7 +946,7 @@ public class InstructionList implements Iterable<InstructionHandle> {
             out.flush();
         } catch (final IOException e) {
             System.err.println(e);
-            return new byte[0];
+            return ArrayUtils.EMPTY_BYTE_ARRAY;
         }
         return b.toByteArray();
     }
diff --git a/src/main/java/org/apache/bcel/generic/MethodGen.java b/src/main/java/org/apache/bcel/generic/MethodGen.java
index f744241..b127e46 100644
--- a/src/main/java/org/apache/bcel/generic/MethodGen.java
+++ b/src/main/java/org/apache/bcel/generic/MethodGen.java
@@ -640,7 +640,7 @@ public class MethodGen extends FieldGenOrMethodGen {
 
     private Attribute[] addRuntimeParameterAnnotationsAsAttribute(final ConstantPoolGen cp) {
         if (!hasParameterAnnotations) {
-            return new Attribute[0];
+            return Attribute.EMPTY_ATTRIBUTE_ARRAY;
         }
         final Attribute[] attrs = AnnotationEntryGen.getParameterAnnotationAttributes(cp, paramAnnotations);
         for (final Attribute attr : attrs) {
diff --git a/src/main/java/org/apache/bcel/generic/Type.java b/src/main/java/org/apache/bcel/generic/Type.java
index 956eda9..4c3a6ba 100644
--- a/src/main/java/org/apache/bcel/generic/Type.java
+++ b/src/main/java/org/apache/bcel/generic/Type.java
@@ -58,7 +58,11 @@ public abstract class Type {
     public static final ObjectType STRING = new ObjectType("java.lang.String");
     public static final ObjectType STRINGBUFFER = new ObjectType("java.lang.StringBuffer");
     public static final ObjectType THROWABLE = new ObjectType("java.lang.Throwable");
-    public static final Type[] NO_ARGS = new Type[0]; // EMPTY, so immutable
+
+    /**
+     * Empty array.
+     */
+    public static final Type[] NO_ARGS = new Type[0];
     public static final ReferenceType NULL = new ReferenceType() {
     };
     public static final Type UNKNOWN = new Type(Const.T_UNKNOWN, "<unknown object>") {
diff --git a/src/main/java/org/apache/bcel/verifier/VerifierAppFrame.java b/src/main/java/org/apache/bcel/verifier/VerifierAppFrame.java
index a5599aa..d17ee56 100644
--- a/src/main/java/org/apache/bcel/verifier/VerifierAppFrame.java
+++ b/src/main/java/org/apache/bcel/verifier/VerifierAppFrame.java
@@ -41,6 +41,7 @@ import javax.swing.event.ListSelectionEvent;
 
 import org.apache.bcel.Repository;
 import org.apache.bcel.classfile.JavaClass;
+import org.apache.commons.lang3.ArrayUtils;
 
 /**
  * This class implements a machine-generated frame for use with
@@ -227,10 +228,10 @@ public class VerifierAppFrame extends JFrame {
             pass2TextPane.setText("");
             pass2TextPane.setBackground(Color.yellow);
             pass3aTextPane.setText("");
-            pass3aJList.setListData(new String[0]);
+            pass3aJList.setListData(ArrayUtils.EMPTY_STRING_ARRAY);
             pass3aTextPane.setBackground(Color.yellow);
             pass3bTextPane.setText("");
-            pass3bJList.setListData(new String[0]);
+            pass3bJList.setListData(ArrayUtils.EMPTY_STRING_ARRAY);
             pass3bTextPane.setBackground(Color.yellow);
         } else { // Must be VERIFIED_OK, Pass 1 does not know VERIFIED_NOTYET
             pass1TextPane.setBackground(Color.green);
@@ -241,10 +242,10 @@ public class VerifierAppFrame extends JFrame {
                 pass2TextPane.setBackground(Color.red);
                 pass3aTextPane.setText("");
                 pass3aTextPane.setBackground(Color.yellow);
-                pass3aJList.setListData(new String[0]);
+                pass3aJList.setListData(ArrayUtils.EMPTY_STRING_ARRAY);
                 pass3bTextPane.setText("");
                 pass3bTextPane.setBackground(Color.yellow);
-                pass3bJList.setListData(new String[0]);
+                pass3bJList.setListData(ArrayUtils.EMPTY_STRING_ARRAY);
             } else { // must be Verified_OK, because Pass1 was OK (cannot be Verified_NOTYET).
                 pass2TextPane.setText(vr.getMessage());
                 pass2TextPane.setBackground(Color.green);
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/ControlFlowGraph.java b/src/main/java/org/apache/bcel/verifier/structurals/ControlFlowGraph.java
index 62c0fce..568f0e6 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/ControlFlowGraph.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/ControlFlowGraph.java
@@ -326,7 +326,6 @@ public class ControlFlowGraph{
          */
 // TODO: implement caching!
         private InstructionHandle[] _getSuccessors() {
-            final InstructionHandle[] empty = new InstructionHandle[0];
             final InstructionHandle[] single = new InstructionHandle[1];
 
             final Instruction inst = getInstruction().getInstruction();
@@ -352,13 +351,13 @@ public class ControlFlowGraph{
 
             // Terminates method normally.
             if (inst instanceof ReturnInstruction) {
-                return empty;
+                return InstructionHandle.EMPTY_INSTRUCTION_HANDLE_ARRAY;
             }
 
             // Terminates method abnormally, because JustIce mandates
             // subroutines not to be protected by exception handlers.
             if (inst instanceof ATHROW) {
-                return empty;
+                return InstructionHandle.EMPTY_INSTRUCTION_HANDLE_ARRAY;
             }
 
             // See method comment.
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 68529f2..66403f2 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java
@@ -17,7 +17,6 @@
  */
 package org.apache.bcel.verifier.structurals;
 
-
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -29,12 +28,16 @@ import org.apache.bcel.generic.MethodGen;
 
 /**
  * This class allows easy access to ExceptionHandler objects.
- *
  */
-public class ExceptionHandlers{
+public class ExceptionHandlers {
+
+    /**
+     * Empty array.
+     */
+    private static final ExceptionHandler[] EMPTY_EXCEPTION_HANDLER_ARRAY = new ExceptionHandler[0];
+
     /**
-     * The ExceptionHandler instances.
-     * Key: InstructionHandle objects, Values: HashSet<ExceptionHandler> instances.
+     * The ExceptionHandler instances. Key: InstructionHandle objects, Values: HashSet<ExceptionHandler> instances.
      */
     private final Map<InstructionHandle, Set<ExceptionHandler>> exceptionHandlers;
 
@@ -46,7 +49,7 @@ public class ExceptionHandlers{
         final CodeExceptionGen[] cegs = mg.getExceptionHandlers();
         for (final CodeExceptionGen ceg : cegs) {
             final ExceptionHandler eh = new ExceptionHandler(ceg.getCatchType(), ceg.getHandlerPC());
-            for (InstructionHandle ih=ceg.getStartPC(); ih != ceg.getEndPC().getNext(); ih=ih.getNext()) {
+            for (InstructionHandle ih = ceg.getStartPC(); ih != ceg.getEndPC().getNext(); ih = ih.getNext()) {
                 Set<ExceptionHandler> hs;
                 hs = exceptionHandlers.get(ih);
                 if (hs == null) {
@@ -59,13 +62,12 @@ public class ExceptionHandlers{
     }
 
     /**
-     * Returns all the ExceptionHandler instances representing exception
-     * handlers that protect the instruction ih.
+     * Returns all the ExceptionHandler instances representing exception handlers that protect the instruction ih.
      */
     public ExceptionHandler[] getExceptionHandlers(final InstructionHandle ih) {
         final Set<ExceptionHandler> hsSet = exceptionHandlers.get(ih);
         if (hsSet == null) {
-            return new ExceptionHandler[0];
+            return EMPTY_EXCEPTION_HANDLER_ARRAY;
         }
         return hsSet.toArray(new ExceptionHandler[hsSet.size()]);
     }
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 7247926..b5b6ba2 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
@@ -620,24 +620,23 @@ public class Subroutines{
      * (opposed to its target) as defined here.
      */
     private static InstructionHandle[] getSuccessors(final InstructionHandle instruction) {
-        final InstructionHandle[] empty = new InstructionHandle[0];
         final InstructionHandle[] single = new InstructionHandle[1];
 
         final Instruction inst = instruction.getInstruction();
 
         if (inst instanceof RET) {
-            return empty;
+            return InstructionHandle.EMPTY_INSTRUCTION_HANDLE_ARRAY;
         }
 
         // Terminates method normally.
         if (inst instanceof ReturnInstruction) {
-            return empty;
+            return InstructionHandle.EMPTY_INSTRUCTION_HANDLE_ARRAY;
         }
 
         // Terminates method abnormally, because JustIce mandates
         // subroutines not to be protected by exception handlers.
         if (inst instanceof ATHROW) {
-            return empty;
+            return InstructionHandle.EMPTY_INSTRUCTION_HANDLE_ARRAY;
         }
 
         // See method comment.