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 82bd20aaa6fae62df8e714e839876d914c3022ee
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Mon Apr 1 10:59:20 2024 -0400

    Avoid NullPointerException after calling
    org.apache.bcel.classfile.FieldOrMethod.setAttributes(Attribute[])
---
 src/changes/changes.xml                                    |  1 +
 src/main/java/org/apache/bcel/classfile/FieldOrMethod.java | 10 ++++------
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a05260ba..1bf0a6d0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -81,6 +81,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.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>
+      <action                  type="update" dev="ggregory" due-to="Gary 
Gregory">Avoid NullPointerException after calling 
org.apache.bcel.classfile.FieldOrMethod.setAttributes(Attribute[]).</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/FieldOrMethod.java 
b/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java
index 76f30617..1b2081ed 100644
--- a/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java
+++ b/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java
@@ -147,10 +147,8 @@ public abstract class FieldOrMethod extends AccessFlags 
implements Cloneable, No
         file.writeShort(name_index);
         file.writeShort(signature_index);
         file.writeShort(attributes_count);
-        if (attributes != null) {
-            for (final Attribute attribute : attributes) {
-                attribute.dump(file);
-            }
+        for (final Attribute attribute : attributes) {
+            attribute.dump(file);
         }
     }
 
@@ -233,8 +231,8 @@ public abstract class FieldOrMethod extends AccessFlags 
implements Cloneable, No
      * @param attributes Collection of object attributes.
      */
     public final void setAttributes(final Attribute[] attributes) {
-        this.attributes = attributes;
-        this.attributes_count = attributes != null ? attributes.length : 0; // 
init deprecated field
+        this.attributes = attributes != null ? attributes : 
Attribute.EMPTY_ARRAY;
+        this.attributes_count = this.attributes.length; // init deprecated 
field
     }
 
     /**

Reply via email to