DO NOT REPLY [Bug 18731] New: - InstructionList.copy() fails with Select instruction.

[email protected]
Newsgroups gmane.comp.jakarta.bcel.devel
Message-ID <[email protected]>
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18731>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18731

InstructionList.copy() fails with Select instruction.

           Summary: InstructionList.copy() fails with Select instruction.
           Product: BCEL
           Version: 5.0RC1
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Main
        AssignedTo: [email protected]
        ReportedBy: [email protected]


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.
    */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.