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. */
Applied to SVN, thanks.