Program: 25785
Project: 25785
Buggy source:
/** 
 * Inserts bytecode at the end of the body. The bytecode is inserted just before every return insturction.
 * @param src       the source code representing the inserted bytecode.It must be a single statement or block.
 * @param asFinally         true if the inserted bytecode is executednot only when the control normally returns but also when an exception is thrown.
 */
public void insertAfter(String src,boolean asFinally) throws CannotCompileException {
  declaringClass.checkModify();
  ConstPool pool=methodInfo.getConstPool();
  CodeAttribute ca=methodInfo.getCodeAttribute();
  if (ca == null)   throw new CannotCompileException("String_Node_Str");
  CodeIterator iterator=ca.iterator();
  int retAddr=ca.getMaxLocals();
  Bytecode b=new Bytecode(pool,0,retAddr + 1);
  b.setStackDepth(ca.getMaxStack() + 1);
  Javac jv=new Javac(b,declaringClass);
  try {
    int nvars=jv.recordParams(getParameterTypes(),Modifier.isStatic(getModifiers()));
    jv.recordParamNames(ca,nvars);
    CtClass rtype=getReturnType0();
    int varNo=jv.recordReturnType(rtype,true);
    int handlerLen=insertAfterHandler(asFinally,b,rtype,varNo);
    byte[] save=makeSaveCode(pool,rtype,varNo);
    byte[] restore=makeRestoreCode(b,pool,rtype,varNo);
    b.addAstore(retAddr);
    jv.compileStmnt(src);
    b.addRet(retAddr);
    ca.setMaxStack(b.getMaxStack());
    ca.setMaxLocals(b.getMaxLocals());
    int gapPos=iterator.append(b.get());
    iterator.append(b.getExceptionTable(),gapPos);
    if (asFinally)     ca.getExceptionTable().add(0,gapPos,gapPos,0);
    int gapLen=iterator.getCodeLength() - gapPos - handlerLen;
    int subr=iterator.getCodeLength() - gapLen;
    while (iterator.hasNext()) {
      int pos=iterator.next();
      if (pos >= subr)       break;
      int c=iterator.byteAt(pos);
      if (c == Opcode.ARETURN || c == Opcode.IRETURN || c == Opcode.FRETURN || c == Opcode.LRETURN || c == Opcode.DRETURN || c == Opcode.RETURN) {
        insertJSR(iterator,subr,pos,save,restore);
        subr=iterator.getCodeLength() - gapLen;
      }
    }
  }
 catch (  NotFoundException e) {
    throw new CannotCompileException(e);
  }
catch (  CompileError e) {
    throw new CannotCompileException(e);
  }
catch (  BadBytecode e) {
    throw new CannotCompileException(e);
  }
}

Fixed version (ground truth):
/** 
 * Inserts bytecode at the end of the body. The bytecode is inserted just before every return insturction.
 * @param src       the source code representing the inserted bytecode.It must be a single statement or block.
 * @param asFinally         true if the inserted bytecode is executednot only when the control normally returns but also when an exception is thrown.
 */
public void insertAfter(String src,boolean asFinally) throws CannotCompileException {
  declaringClass.checkModify();
  ConstPool pool=methodInfo.getConstPool();
  CodeAttribute ca=methodInfo.getCodeAttribute();
  if (ca == null)   throw new CannotCompileException("String_Node_Str");
  CodeIterator iterator=ca.iterator();
  int retAddr=ca.getMaxLocals();
  Bytecode b=new Bytecode(pool,0,retAddr + 1);
  b.setStackDepth(ca.getMaxStack() + 1);
  Javac jv=new Javac(b,declaringClass);
  try {
    int nvars=jv.recordParams(getParameterTypes(),Modifier.isStatic(getModifiers()));
    jv.recordParamNames(ca,nvars);
    CtClass rtype=getReturnType0();
    int varNo=jv.recordReturnType(rtype,true);
    jv.recordLocalVariables(ca,0);
    int handlerLen=insertAfterHandler(asFinally,b,rtype,varNo);
    byte[] save=makeSaveCode(pool,rtype,varNo);
    byte[] restore=makeRestoreCode(b,pool,rtype,varNo);
    b.addAstore(retAddr);
    jv.compileStmnt(src);
    b.addRet(retAddr);
    ca.setMaxStack(b.getMaxStack());
    ca.setMaxLocals(b.getMaxLocals());
    int gapPos=iterator.append(b.get());
    iterator.append(b.getExceptionTable(),gapPos);
    if (asFinally)     ca.getExceptionTable().add(0,gapPos,gapPos,0);
    int gapLen=iterator.getCodeLength() - gapPos - handlerLen;
    int subr=iterator.getCodeLength() - gapLen;
    while (iterator.hasNext()) {
      int pos=iterator.next();
      if (pos >= subr)       break;
      int c=iterator.byteAt(pos);
      if (c == Opcode.ARETURN || c == Opcode.IRETURN || c == Opcode.FRETURN || c == Opcode.LRETURN || c == Opcode.DRETURN || c == Opcode.RETURN) {
        insertJSR(iterator,subr,pos,save,restore);
        subr=iterator.getCodeLength() - gapLen;
      }
    }
  }
 catch (  NotFoundException e) {
    throw new CannotCompileException(e);
  }
catch (  CompileError e) {
    throw new CannotCompileException(e);
  }
catch (  BadBytecode e) {
    throw new CannotCompileException(e);
  }
}