Program: 186715
Project: 186715
Buggy source:
/** 
 * Replace instructions in this code with an instruction list or a part of it. If the number of instructions to replace differs from the number of source instructions, instruction handles will be removed or inserted appropriately and the targets will be updated. <p> Instruction handles will be reused, so attached values and targets will not be lost if the new length is not shorter than the old length. Else instruction handles are removed and the targeters to removed instructions are updated to the instruction after the next instruction after the deleted instructions. </p>
 * @param replaceStart the first instruction in this code to replace
 * @param replaceCount the number of instructions in this code to replace
 * @param sourceInfo the MethodInfo containing the source instruction. If non-null, the instructions will be copiedusing the constant pool from the given MethodInfo. If null, the instructions will not be copied.
 * @param source the instructions to use as replacement.
 * @param sourceStart the first instruction in the source list to use for replacing the code.
 * @param sourceCount the number of instructions to use from the source.
 * @param copyCustomValues if true copy the custom values from the source.
 * @return the first handle in the target list after the inserted code, or null if the last instruction in thislist has been replaced.
 */
public InstructionHandle replace(InstructionHandle replaceStart,int replaceCount,MethodInfo sourceInfo,InstructionList source,InstructionHandle sourceStart,int sourceCount,boolean copyCustomValues){
  InstructionList il=getInstructionList();
  InstructionHandle current=replaceStart;
  InstructionHandle currSource=sourceStart;
  int cnt=Math.min(replaceCount,sourceCount);
  for (int i=0; i < cnt; i++) {
    Instruction instr;
    if (sourceInfo != null) {
      instr=copyFrom(sourceInfo.getClassInfo(),currSource.getInstruction());
    }
 else {
      instr=currSource.getInstruction();
    }
    current.setInstruction(instr);
    if (copyCustomValues) {
      copyCustomValues(sourceInfo,current,currSource);
    }
    current=current.getNext();
    currSource=currSource.getNext();
  }
  InstructionHandle next=current;
  if (replaceCount > sourceCount) {
    int rest=replaceCount - sourceCount;
    for (int i=1; i < rest; i++) {
      next=next.getNext();
    }
    InstructionHandle end=next;
    next=next.getNext();
    try {
      il.delete(current,end);
    }
 catch (    TargetLostException e) {
      retarget(e,next);
    }
  }
  if (replaceCount < sourceCount) {
    int rest=sourceCount - replaceCount;
    for (int i=0; i < rest; i++) {
      Instruction instr;
      if (sourceInfo != null) {
        instr=copyFrom(sourceInfo.getClassInfo(),currSource.getInstruction());
      }
 else {
        instr=currSource.getInstruction();
      }
      if (next == null) {
        current=il.append(instr);
      }
 else {
        current=il.insert(next,instr);
      }
      if (copyCustomValues) {
        copyCustomValues(sourceInfo,current,currSource);
      }
      currSource=currSource.getNext();
    }
  }
  return next;
}

Fixed version (ground truth):
/** 
 * Replace instructions in this code with an instruction list or a part of it. If the number of instructions to replace differs from the number of source instructions, instruction handles will be removed or inserted appropriately and the targets will be updated. <p> Instruction handles will be reused, so attached values and targets will not be lost if the new length is not shorter than the old length. Else instruction handles are removed and the targeters to removed instructions are updated to the instruction after the next instruction after the deleted instructions. </p>
 * @param replaceStart the first instruction in this code to replace
 * @param replaceCount the number of instructions in this code to replace
 * @param sourceInfo the MethodInfo containing the source instruction. If non-null, the instructions will be copiedusing the constant pool from the given MethodInfo. If null, the instructions will not be copied.
 * @param sourceStart the first instruction in the source list to use for replacing the code.
 * @param sourceCount the number of instructions to use from the source.
 * @param copyCustomValues if true copy the custom values from the source.
 * @return the first handle in the target list after the inserted code, or null if the last instruction in thislist has been replaced.
 */
public InstructionHandle replace(InstructionHandle replaceStart,int replaceCount,MethodInfo sourceInfo,InstructionHandle sourceStart,int sourceCount,boolean copyCustomValues){
  InstructionList il=getInstructionList();
  InstructionHandle current=replaceStart;
  InstructionHandle currSource=sourceStart;
  int cnt=Math.min(replaceCount,sourceCount);
  for (int i=0; i < cnt; i++) {
    Instruction instr;
    if (sourceInfo != null) {
      instr=copyFrom(sourceInfo.getClassInfo(),currSource.getInstruction());
    }
 else {
      instr=currSource.getInstruction();
    }
    current.setInstruction(instr);
    if (copyCustomValues) {
      copyCustomValues(sourceInfo,current,currSource);
    }
    current=current.getNext();
    currSource=currSource.getNext();
  }
  InstructionHandle next=current;
  if (replaceCount > sourceCount) {
    int rest=replaceCount - sourceCount;
    for (int i=1; i < rest; i++) {
      next=next.getNext();
    }
    InstructionHandle end=next;
    next=next.getNext();
    try {
      il.delete(current,end);
    }
 catch (    TargetLostException e) {
      retarget(e,next);
    }
  }
  if (replaceCount < sourceCount) {
    int rest=sourceCount - replaceCount;
    for (int i=0; i < rest; i++) {
      Instruction instr;
      if (sourceInfo != null) {
        instr=copyFrom(sourceInfo.getClassInfo(),currSource.getInstruction());
      }
 else {
        instr=currSource.getInstruction();
      }
      if (next == null) {
        current=il.append(instr);
      }
 else {
        current=il.insert(next,instr);
      }
      if (copyCustomValues) {
        copyCustomValues(sourceInfo,current,currSource);
      }
      currSource=currSource.getNext();
    }
  }
  return next;
}