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 511a7787d4298082872ef1b36995f7247d0fea4d
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Mon Apr 1 11:21:26 2024 -0400

    Avoid NullPointerException calling
    
org.apache.bcel.generic.InstructionList.redirectLocalVariables(LocalVariableGen[],
    InstructionHandle, InstructionHandle) with null
---
 src/changes/changes.xml                                    |  1 +
 src/main/java/org/apache/bcel/generic/InstructionList.java | 11 +++++------
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index e6541f74..bbf421d3 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -89,6 +89,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.BootstrapMethod.setBootstrapArguments(int[]) with 
null.</action>
       <action                  type="update" dev="ggregory" due-to="Gary 
Gregory">Avoid NullPointerException after calling 
org.apache.bcel.classfile.BootstrapMethods.BootstrapMethods(int, int, 
BootstrapMethod[], ConstantPool) with null.</action>
       <action                  type="update" dev="ggregory" due-to="Gary 
Gregory">Avoid NullPointerException after calling 
org.apache.bcel.classfile.BootstrapMethods.setBootstrapMethods(BootstrapMethod[])
 with null.</action>
+      <action                  type="update" dev="ggregory" due-to="Gary 
Gregory">Avoid NullPointerException calling 
org.apache.bcel.generic.InstructionList.redirectLocalVariables(LocalVariableGen[],
 InstructionHandle, InstructionHandle) with null.</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/generic/InstructionList.java 
b/src/main/java/org/apache/bcel/generic/InstructionList.java
index ca053e44..2f8c11aa 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionList.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionList.java
@@ -31,6 +31,7 @@ import org.apache.bcel.Const;
 import org.apache.bcel.classfile.Constant;
 import org.apache.bcel.util.ByteSequence;
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.stream.Streams;
 
 /**
  * This class is a container for a list of <a 
href="Instruction.html">Instruction</a> objects. Instructions can be
@@ -978,16 +979,14 @@ public class InstructionList implements 
Iterable<InstructionHandle> {
      * @see MethodGen
      */
     public void redirectLocalVariables(final LocalVariableGen[] lg, final 
InstructionHandle oldTarget, final InstructionHandle newTarget) {
-        for (final LocalVariableGen element : lg) {
-            final InstructionHandle start = element.getStart();
-            final InstructionHandle end = element.getEnd();
-            if (start == oldTarget) {
+        Streams.of(lg).forEach(element -> {
+            if (element.getStart() == oldTarget) {
                 element.setStart(newTarget);
             }
-            if (end == oldTarget) {
+            if (element.getEnd() == oldTarget) {
                 element.setEnd(newTarget);
             }
-        }
+        });
     }
 
     /**

Reply via email to