Bug 18731 - InstructionList.copy() fails with Select instruction.
Summary: InstructionList.copy() fails with Select instruction.
Status: RESOLVED FIXED
Alias: None
Product: BCEL - Now in Jira
Classification: Unclassified
Component: Main (show other bugs)
Version: 5.0
Hardware: All Linux
: P3 normal
Target Milestone: ---
Assignee: issues@commons.apache.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-05 13:48 UTC by wombat
Modified: 2005-02-21 22:21 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description wombat 2003-04-05 13:48:07 UTC
The implementation of InstructionList.copy() works on the internal targets
fields of the select instructions:

(InstructionList.java line 1110)
	  InstructionHandle[] itargets = ((Select)bi).getTargets();
	  InstructionHandle[] ctargets = ((Select)bc).getTargets();

But because bc is created from bi by cloning bi, both refer to the same target
array.

Changing ctargets also changes itargets. 

The reason for this is, that Select does not override clone. 

The following patch fixes this problem:

Index: Select.java
===================================================================
RCS file:
/home/cvspublic/jakarta-bcel/src/java/org/apache/bcel/generic/Select.java,v
retrieving revision 1.2
diff -u -r1.2 Select.java
--- Select.java 26 Apr 2002 09:30:11 -0000      1.2
+++ Select.java 5 Apr 2003 13:37:54 -0000
@@ -227,6 +227,16 @@
     return false;
   }

+  protected Object clone() throws CloneNotSupportedException {
+      Select result = (Select) super.clone();
+
+      result.match   = (int[]) result.match.clone();
+      result.indices = (int[]) result.indices.clone();
+      result.targets = (InstructionHandle[]) result.targets.clone();
+
+      return result;
+  }
+
   /**
    * Inform targets that they're not targeted anymore.
    */
Comment 1 Dave Brosius 2005-02-22 07:21:38 UTC
Applied to SVN, thanks.