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 2586ee0b0b689fd323bf677256d931c025630826
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Apr 1 11:02:33 2024 -0400

    Avoid NullPointerException after calling
    org.apache.bcel.classfile.Annotations.setAnnotationTable(AnnotationEntry[])
---
 src/changes/changes.xml                                  |  1 +
 src/main/java/org/apache/bcel/classfile/Annotations.java | 10 ++--------
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1bf0a6d0..4fe51ede 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -82,6 +82,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.setAttributes(Attribute[]).</action>
       <action                  type="update" dev="ggregory" due-to="Gary 
Gregory">Avoid NullPointerException after calling 
org.apache.bcel.classfile.ConstantPool.setConstantPool(Constant[]).</action>
       <action                  type="update" dev="ggregory" due-to="Gary 
Gregory">Avoid NullPointerException after calling 
org.apache.bcel.classfile.FieldOrMethod.setAttributes(Attribute[]).</action>
+      <action                  type="update" dev="ggregory" due-to="Gary 
Gregory">Avoid NullPointerException after calling 
org.apache.bcel.classfile.Annotations.setAnnotationTable(AnnotationEntry[]).</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/Annotations.java 
b/src/main/java/org/apache/bcel/classfile/Annotations.java
index 6ca224a9..fab5d612 100644
--- a/src/main/java/org/apache/bcel/classfile/Annotations.java
+++ b/src/main/java/org/apache/bcel/classfile/Annotations.java
@@ -47,7 +47,7 @@ public abstract class Annotations extends Attribute 
implements Iterable<Annotati
     public Annotations(final byte annotationType, final int nameIndex, final 
int length, final AnnotationEntry[] annotationTable,
             final ConstantPool constantPool, final boolean isRuntimeVisible) {
         super(annotationType, nameIndex, length, constantPool);
-        this.annotationTable = annotationTable;
+        setAnnotationTable(annotationTable);
         this.isRuntimeVisible = isRuntimeVisible;
     }
 
@@ -103,9 +103,6 @@ public abstract class Annotations extends Attribute 
implements Iterable<Annotati
      * @return the number of annotation entries in this annotation
      */
     public final int getNumAnnotations() {
-        if (annotationTable == null) {
-            return 0;
-        }
         return annotationTable.length;
     }
 
@@ -124,7 +121,7 @@ public abstract class Annotations extends Attribute 
implements Iterable<Annotati
      * @param annotationTable the entries to set in this annotation
      */
     public final void setAnnotationTable(final AnnotationEntry[] 
annotationTable) {
-        this.annotationTable = annotationTable;
+        this.annotationTable = annotationTable != null ? annotationTable : 
AnnotationEntry.EMPTY_ARRAY;
     }
 
     /**
@@ -146,9 +143,6 @@ public abstract class Annotations extends Attribute 
implements Iterable<Annotati
     }
 
     protected void writeAnnotations(final DataOutputStream dos) throws 
IOException {
-        if (annotationTable == null) {
-            return;
-        }
         dos.writeShort(annotationTable.length);
         for (final AnnotationEntry element : annotationTable) {
             element.dump(dos);

Reply via email to