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
commit 3a743f9a4f6d42ea8b97dce76f68b7aca39f45e6 Author: Gary Gregory <[email protected]> AuthorDate: Mon Apr 1 10:56:07 2024 -0400 Avoid NullPointerException after calling org.apache.bcel.classfile.ConstantPool.setConstantPool(Constant[]) --- src/changes/changes.xml | 1 + src/main/java/org/apache/bcel/classfile/Constant.java | 2 ++ src/main/java/org/apache/bcel/classfile/ConstantPool.java | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 24803f80..a05260ba 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -80,6 +80,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="update" dev="ggregory" due-to="Gary Gregory">Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setInterfaceNames(String[]).</action> <action type="update" dev="ggregory" due-to="Gary Gregory">Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setFields(Field[]).</action> <action type="update" dev="ggregory" due-to="Gary Gregory">Avoid NullPointerException after calling org.apache.bcel.classfile.JavaClass.setAttributes(Attribute[]).</action> + <action type="update" dev="ggregory" due-to="Gary Gregory">Avoid NullPointerException after calling org.apache.bcel.classfile.ConstantPool.setConstantPool(Constant[]).</action> <!-- UPDATE --> <action type="update" dev="ggregory" due-to="Dependabot">Bump org.apache.commons:commons-parent from 66 to 67 #283.</action> <action type="update" dev="ggregory" due-to="Dependabot">Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.22 to 1.9.23 #284.</action> diff --git a/src/main/java/org/apache/bcel/classfile/Constant.java b/src/main/java/org/apache/bcel/classfile/Constant.java index 6ed876d0..c55601d8 100644 --- a/src/main/java/org/apache/bcel/classfile/Constant.java +++ b/src/main/java/org/apache/bcel/classfile/Constant.java @@ -30,6 +30,8 @@ import org.apache.bcel.util.BCELComparator; */ public abstract class Constant implements Cloneable, Node { + static final Constant[] EMPTY_ARRAY = {}; + private static BCELComparator<Constant> bcelComparator = new BCELComparator<Constant>() { @Override diff --git a/src/main/java/org/apache/bcel/classfile/ConstantPool.java b/src/main/java/org/apache/bcel/classfile/ConstantPool.java index e94f35dd..a046dc50 100644 --- a/src/main/java/org/apache/bcel/classfile/ConstantPool.java +++ b/src/main/java/org/apache/bcel/classfile/ConstantPool.java @@ -68,7 +68,7 @@ public class ConstantPool implements Cloneable, Node, Iterable<Constant> { * @param constantPool Array of constants */ public ConstantPool(final Constant[] constantPool) { - this.constantPool = constantPool; + setConstantPool(constantPool); } /** @@ -399,7 +399,7 @@ public class ConstantPool implements Cloneable, Node, Iterable<Constant> { * @return Length of constant pool. */ public int getLength() { - return constantPool == null ? 0 : constantPool.length; + return constantPool.length; } @Override @@ -418,7 +418,7 @@ public class ConstantPool implements Cloneable, Node, Iterable<Constant> { * @param constantPool */ public void setConstantPool(final Constant[] constantPool) { - this.constantPool = constantPool; + this.constantPool = constantPool != null ? constantPool : Constant.EMPTY_ARRAY; } /**
