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 2023/06/17 17:15:48 UTC

[commons-bcel] branch master updated: * Changed TestJira368 to call InstructionList#toString instead of Code#toString so that the test can reveal the defect in Select#toString(boolean) described in issue 368. (#229)

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 f4907ff7 * Changed TestJira368 to call InstructionList#toString instead of Code#toString so that the test can reveal the defect in Select#toString(boolean) described in issue 368. (#229)
f4907ff7 is described below

commit f4907ff7eb654021bca275e0b691b832fedc94cf
Author: katherine-hough <32...@users.noreply.github.com>
AuthorDate: Sat Jun 17 13:15:43 2023 -0400

    * Changed TestJira368 to call InstructionList#toString instead of Code#toString so that the test can reveal the defect in Select#toString(boolean) described in issue 368. (#229)
    
    * Fixed issue with Select#toString(boolean) throwing a java.lang.StackOverflowError when there is a self-reference in targets. The message "<points to itself>" (chosen to be consistent with BranchInstruction#toString) is used to represent the self-reference.
---
 src/main/java/org/apache/bcel/generic/Select.java   |  6 +++++-
 .../java/org/apache/bcel/classfile/TestJira368.java | 21 +++++++++++++--------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/bcel/generic/Select.java b/src/main/java/org/apache/bcel/generic/Select.java
index 18b95c99..5cee7398 100644
--- a/src/main/java/org/apache/bcel/generic/Select.java
+++ b/src/main/java/org/apache/bcel/generic/Select.java
@@ -310,7 +310,11 @@ public abstract class Select extends BranchInstruction implements VariableLength
             for (int i = 0; i < match_length; i++) {
                 String s = "null";
                 if (targets[i] != null) {
-                    s = targets[i].getInstruction().toString();
+                    if (targets[i].getInstruction() == this) {
+                        s = "<points to itself>";
+                    } else {
+                        s = targets[i].getInstruction().toString();
+                    }
                 }
                 buf.append("(").append(match[i]).append(", ").append(s).append(" = {").append(indices[i]).append("})");
             }
diff --git a/src/test/java/org/apache/bcel/classfile/TestJira368.java b/src/test/java/org/apache/bcel/classfile/TestJira368.java
index f3491d7f..83cc510e 100644
--- a/src/test/java/org/apache/bcel/classfile/TestJira368.java
+++ b/src/test/java/org/apache/bcel/classfile/TestJira368.java
@@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 import java.io.IOException;
 
+import org.apache.bcel.generic.InstructionList;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -33,20 +34,24 @@ public class TestJira368 {
     }
 
     @Test
-    public void testMethodCodeStringBrief() throws Exception {
+    public void testInstructionListStringBrief() throws Exception {
         for (Method method : parseJavaClass().getMethods()) {
-            final String string = method.getCode().toString(false);
-            // System.out.println(string);
-            assertNotNull(string);
+            if (!method.isAbstract() && !method.isNative()) {
+                final InstructionList instructionList = new InstructionList(method.getCode().getCode());
+                final String string = instructionList.toString(false);
+                assertNotNull(string);
+            }
         }
     }
 
     @Test
-    public void testMethodCodeStringVerbose() throws Exception {
+    public void testInstructionListStringVerbose() throws Exception {
         for (Method method : parseJavaClass().getMethods()) {
-            final String string = method.getCode().toString(true);
-            // System.out.println(string);
-            assertNotNull(string);
+            if (!method.isAbstract() && !method.isNative()) {
+                final InstructionList instructionList = new InstructionList(method.getCode().getCode());
+                final String string = instructionList.toString(true);
+                assertNotNull(string);
+            }
         }
     }