Program: 99729
Project: 99729
Buggy source:
/** 
 * When adding an edge from source to target, it is possible that certain exception-handling code needs to be executed before the control is actually transfered to target. This method determines if this is the case, and if so, it generates the exception handler blocks and adds an appropriate edge to the target. It returns the basic block that should be the target of the edge from source (target itself if there is no exception-handling code, the initial catch block otherwise)
 */
public PreBasicBlock findOrCreateCode(PreBasicBlock source,PreBasicBlock target,final boolean exception){
  UnwindState sourceContext=unwindData.get(source);
  final CAstNode dummy=exception ? (new CAstImpl()).makeNode(CAstNode.EMPTY) : null;
  if (sourceContext == null)   return target;
  WalkContext astContext=sourceContext.astContext;
  UnwindState targetContext=null;
  if (target != null)   targetContext=unwindData.get(target);
  if (targetContext != null && targetContext.covers(sourceContext))   return target;
  Pair<UnwindState,Pair<PreBasicBlock,Boolean>> key=Pair.make(sourceContext,Pair.make(target,exception));
  if (code.containsKey(key)) {
    return code.get(key);
  }
 else {
    int e=-1;
    PreBasicBlock currentBlock=getCurrentBlock();
    if (!isDeadBlock(currentBlock)) {
      addInstruction(insts.GotoInstruction());
      newBlock(false);
    }
    PreBasicBlock startBlock=getCurrentBlock();
    if (exception) {
      setCurrentBlockAsHandler();
      e=sourceContext.astContext.currentScope().allocateTempValue();
      addInstruction(insts.GetCaughtExceptionInstruction(startBlock.getNumber(),e));
      sourceContext.astContext.setCatchType(startBlock.getNumber(),defaultCatchType());
    }
    while (sourceContext != null && (targetContext == null || !targetContext.covers(sourceContext))) {
      final CAstRewriter.Rewrite ast=(new CAstCloner(new CAstImpl()){
        protected CAstNode flowOutTo(        Map<Pair<CAstNode,NoKey>,CAstNode> nodeMap,        CAstNode oldSource,        Object label,        CAstNode oldTarget,        CAstControlFlowMap orig,        CAstSourcePositionMap src){
          if (exception && !isExceptionLabel(label)) {
            return dummy;
          }
 else {
            return oldTarget;
          }
        }
      }
).copy(sourceContext.unwindAst,sourceContext.astContext.getControlFlow(),sourceContext.astContext.getSourceMap(),sourceContext.astContext.top().getNodeTypeMap(),sourceContext.astContext.top().getAllScopedEntities());
      sourceContext.astVisitor.visit(ast.newRoot(),new DelegatingContext(sourceContext.astContext){
        public CAstSourcePositionMap getSourceMap(){
          return ast.newPos();
        }
        public CAstControlFlowMap getControlFlow(){
          return ast.newCfg();
        }
      }
,sourceContext.astVisitor);
      sourceContext=sourceContext.getParent();
    }
    PreBasicBlock endBlock=getCurrentBlock();
    if (exception) {
      addPreNode(dummy);
      doThrow(astContext,e);
    }
 else {
      addInstruction(insts.GotoInstruction());
    }
    newBlock(false);
    addEdge(currentBlock,getCurrentBlock());
    if (target != null) {
      addEdge(endBlock,target);
    }
 else {
      addDelayedEdge(endBlock,exitMarker,exception);
    }
    code.put(key,startBlock);
    return startBlock;
  }
}

Fixed version (ground truth):
/** 
 * When adding an edge from source to target, it is possible that certain exception-handling code needs to be executed before the control is actually transfered to target. This method determines if this is the case, and if so, it generates the exception handler blocks and adds an appropriate edge to the target. It returns the basic block that should be the target of the edge from source (target itself if there is no exception-handling code, the initial catch block otherwise)
 */
public PreBasicBlock findOrCreateCode(PreBasicBlock source,PreBasicBlock target,final boolean exception){
  UnwindState sourceContext=unwindData.get(source);
  final CAstNode dummy=exception ? (new CAstImpl()).makeNode(CAstNode.EMPTY) : null;
  if (sourceContext == null)   return target;
  WalkContext astContext=sourceContext.astContext;
  UnwindState targetContext=null;
  if (target != null)   targetContext=unwindData.get(target);
  if (targetContext != null && targetContext.covers(sourceContext))   return target;
  Pair<UnwindState,Pair<PreBasicBlock,Boolean>> key=Pair.make(sourceContext,Pair.make(target,exception));
  if (code.containsKey(key)) {
    return code.get(key);
  }
 else {
    int e=-1;
    PreBasicBlock currentBlock=getCurrentBlock();
    if (!isDeadBlock(currentBlock)) {
      addInstruction(insts.GotoInstruction());
      newBlock(false);
    }
    PreBasicBlock startBlock=getCurrentBlock();
    if (exception) {
      setCurrentBlockAsHandler();
      e=sourceContext.astContext.currentScope().allocateTempValue();
      addInstruction(insts.GetCaughtExceptionInstruction(startBlock.getNumber(),e));
      sourceContext.astContext.setCatchType(startBlock,defaultCatchType());
    }
    while (sourceContext != null && (targetContext == null || !targetContext.covers(sourceContext))) {
      final CAstRewriter.Rewrite ast=(new CAstCloner(new CAstImpl()){
        protected CAstNode flowOutTo(        Map<Pair<CAstNode,NoKey>,CAstNode> nodeMap,        CAstNode oldSource,        Object label,        CAstNode oldTarget,        CAstControlFlowMap orig,        CAstSourcePositionMap src){
          if (exception && !isExceptionLabel(label)) {
            return dummy;
          }
 else {
            return oldTarget;
          }
        }
      }
).copy(sourceContext.unwindAst,sourceContext.astContext.getControlFlow(),sourceContext.astContext.getSourceMap(),sourceContext.astContext.top().getNodeTypeMap(),sourceContext.astContext.top().getAllScopedEntities());
      sourceContext.astVisitor.visit(ast.newRoot(),new DelegatingContext(sourceContext.astContext){
        public CAstSourcePositionMap getSourceMap(){
          return ast.newPos();
        }
        public CAstControlFlowMap getControlFlow(){
          return ast.newCfg();
        }
      }
,sourceContext.astVisitor);
      sourceContext=sourceContext.getParent();
    }
    PreBasicBlock endBlock=getCurrentBlock();
    if (exception) {
      addPreNode(dummy);
      doThrow(astContext,e);
    }
 else {
      addInstruction(insts.GotoInstruction());
    }
    newBlock(false);
    addEdge(currentBlock,getCurrentBlock());
    if (target != null) {
      addEdge(endBlock,target);
    }
 else {
      addDelayedEdge(endBlock,exitMarker,exception);
    }
    code.put(key,startBlock);
    return startBlock;
  }
}