Program: 12164
Project: 12164
Buggy source:
private void extractMethod(){
  AST ast=sourceTypeDeclaration.getAST();
  MethodDeclaration newMethodDeclaration=ast.newMethodDeclaration();
  VariableDeclaration returnedVariableDeclaration=slice.getLocalVariableCriterion();
  SimpleName returnedVariableSimpleName=returnedVariableDeclaration.getName();
  Type returnedVariableType=null;
  if (returnedVariableDeclaration instanceof SingleVariableDeclaration) {
    SingleVariableDeclaration singleVariableDeclaration=(SingleVariableDeclaration)returnedVariableDeclaration;
    returnedVariableType=singleVariableDeclaration.getType();
  }
 else   if (returnedVariableDeclaration instanceof VariableDeclarationFragment) {
    VariableDeclarationFragment fragment=(VariableDeclarationFragment)returnedVariableDeclaration;
    VariableDeclarationStatement variableDeclarationStatement=(VariableDeclarationStatement)fragment.getParent();
    returnedVariableType=variableDeclarationStatement.getType();
  }
  sourceRewriter.set(newMethodDeclaration,MethodDeclaration.NAME_PROPERTY,ast.newSimpleName(slice.getExtractedMethodName()),null);
  sourceRewriter.set(newMethodDeclaration,MethodDeclaration.RETURN_TYPE2_PROPERTY,returnedVariableType,null);
  ListRewrite modifierRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.MODIFIERS2_PROPERTY);
  Modifier modifier=newMethodDeclaration.getAST().newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD);
  modifierRewrite.insertLast(modifier,null);
  ListRewrite parameterRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.PARAMETERS_PROPERTY);
  for (  VariableDeclaration variableDeclaration : slice.getPassedParameters()) {
    Type variableType=null;
    if (variableDeclaration instanceof SingleVariableDeclaration) {
      SingleVariableDeclaration singleVariableDeclaration=(SingleVariableDeclaration)variableDeclaration;
      variableType=singleVariableDeclaration.getType();
    }
 else     if (variableDeclaration instanceof VariableDeclarationFragment) {
      VariableDeclarationFragment fragment=(VariableDeclarationFragment)variableDeclaration;
      VariableDeclarationStatement variableDeclarationStatement=(VariableDeclarationStatement)fragment.getParent();
      variableType=variableDeclarationStatement.getType();
    }
    SingleVariableDeclaration parameter=ast.newSingleVariableDeclaration();
    sourceRewriter.set(parameter,SingleVariableDeclaration.NAME_PROPERTY,variableDeclaration.getName(),null);
    sourceRewriter.set(parameter,SingleVariableDeclaration.TYPE_PROPERTY,variableType,null);
    parameterRewrite.insertLast(parameter,null);
  }
  Block newMethodBody=newMethodDeclaration.getAST().newBlock();
  ListRewrite bodyRewrite=sourceRewriter.getListRewrite(newMethodBody,Block.STATEMENTS_PROPERTY);
  List<PDGNode> sliceNodes=new ArrayList<PDGNode>(slice.getSliceNodes());
  while (!sliceNodes.isEmpty()) {
    PDGNode node=sliceNodes.get(0);
    if (node instanceof PDGStatementNode) {
      bodyRewrite.insertLast(node.getASTStatement(),null);
      sliceNodes.remove(node);
    }
 else     if (node instanceof PDGControlPredicateNode) {
      PDGControlPredicateNode predicateNode=(PDGControlPredicateNode)node;
      bodyRewrite.insertLast(processPredicateNode(predicateNode,ast,sliceNodes),null);
    }
  }
  ReturnStatement returnStatement=newMethodBody.getAST().newReturnStatement();
  sourceRewriter.set(returnStatement,ReturnStatement.EXPRESSION_PROPERTY,returnedVariableSimpleName,null);
  bodyRewrite.insertLast(returnStatement,null);
  sourceRewriter.set(newMethodDeclaration,MethodDeclaration.BODY_PROPERTY,newMethodBody,null);
  ListRewrite methodDeclarationRewrite=sourceRewriter.getListRewrite(sourceTypeDeclaration,TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
  methodDeclarationRewrite.insertAfter(newMethodDeclaration,sourceMethodDeclaration,null);
}

Fixed version (ground truth):
private void extractMethod(){
  AST ast=sourceTypeDeclaration.getAST();
  MethodDeclaration newMethodDeclaration=ast.newMethodDeclaration();
  VariableDeclaration returnedVariableDeclaration=slice.getLocalVariableCriterion();
  SimpleName returnedVariableSimpleName=returnedVariableDeclaration.getName();
  Type returnedVariableType=null;
  if (returnedVariableDeclaration instanceof SingleVariableDeclaration) {
    SingleVariableDeclaration singleVariableDeclaration=(SingleVariableDeclaration)returnedVariableDeclaration;
    returnedVariableType=singleVariableDeclaration.getType();
  }
 else   if (returnedVariableDeclaration instanceof VariableDeclarationFragment) {
    VariableDeclarationFragment fragment=(VariableDeclarationFragment)returnedVariableDeclaration;
    VariableDeclarationStatement variableDeclarationStatement=(VariableDeclarationStatement)fragment.getParent();
    returnedVariableType=variableDeclarationStatement.getType();
  }
  sourceRewriter.set(newMethodDeclaration,MethodDeclaration.NAME_PROPERTY,ast.newSimpleName(slice.getExtractedMethodName()),null);
  sourceRewriter.set(newMethodDeclaration,MethodDeclaration.RETURN_TYPE2_PROPERTY,returnedVariableType,null);
  ListRewrite modifierRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.MODIFIERS2_PROPERTY);
  Modifier modifier=newMethodDeclaration.getAST().newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD);
  modifierRewrite.insertLast(modifier,null);
  ListRewrite parameterRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.PARAMETERS_PROPERTY);
  for (  VariableDeclaration variableDeclaration : slice.getPassedParameters()) {
    Type variableType=null;
    if (variableDeclaration instanceof SingleVariableDeclaration) {
      SingleVariableDeclaration singleVariableDeclaration=(SingleVariableDeclaration)variableDeclaration;
      variableType=singleVariableDeclaration.getType();
    }
 else     if (variableDeclaration instanceof VariableDeclarationFragment) {
      VariableDeclarationFragment fragment=(VariableDeclarationFragment)variableDeclaration;
      VariableDeclarationStatement variableDeclarationStatement=(VariableDeclarationStatement)fragment.getParent();
      variableType=variableDeclarationStatement.getType();
    }
    SingleVariableDeclaration parameter=ast.newSingleVariableDeclaration();
    sourceRewriter.set(parameter,SingleVariableDeclaration.NAME_PROPERTY,variableDeclaration.getName(),null);
    sourceRewriter.set(parameter,SingleVariableDeclaration.TYPE_PROPERTY,variableType,null);
    parameterRewrite.insertLast(parameter,null);
  }
  Block newMethodBody=newMethodDeclaration.getAST().newBlock();
  ListRewrite bodyRewrite=sourceRewriter.getListRewrite(newMethodBody,Block.STATEMENTS_PROPERTY);
  List<PDGNode> sliceNodes=new ArrayList<PDGNode>(slice.getSliceNodes());
  List<CFGBranchDoLoopNode> doLoopNodes=new ArrayList<CFGBranchDoLoopNode>();
  for (  PDGNode pdgNode : sliceNodes) {
    CFGNode cfgNode=pdgNode.getCFGNode();
    if (cfgNode instanceof CFGBranchDoLoopNode) {
      CFGBranchDoLoopNode cfgDoLoopNode=(CFGBranchDoLoopNode)cfgNode;
      doLoopNodes.add(cfgDoLoopNode);
    }
  }
  while (!sliceNodes.isEmpty()) {
    PDGNode node=sliceNodes.get(0);
    if (node instanceof PDGStatementNode) {
      boolean nodeIsInsideDoLoop=false;
      for (      CFGBranchDoLoopNode doLoopNode : doLoopNodes) {
        if (node.getId() >= doLoopNode.getJoinNode().getId() && node.getId() < doLoopNode.getId()) {
          nodeIsInsideDoLoop=true;
          PDGControlPredicateNode predicateNode=(PDGControlPredicateNode)doLoopNode.getPDGNode();
          if (sliceNodes.contains(predicateNode)) {
            bodyRewrite.insertLast(processPredicateNode(predicateNode,ast,sliceNodes),null);
            break;
          }
        }
      }
      if (!nodeIsInsideDoLoop) {
        bodyRewrite.insertLast(node.getASTStatement(),null);
        sliceNodes.remove(node);
      }
    }
 else     if (node instanceof PDGControlPredicateNode) {
      PDGControlPredicateNode predicateNode=(PDGControlPredicateNode)node;
      bodyRewrite.insertLast(processPredicateNode(predicateNode,ast,sliceNodes),null);
    }
  }
  ReturnStatement returnStatement=newMethodBody.getAST().newReturnStatement();
  sourceRewriter.set(returnStatement,ReturnStatement.EXPRESSION_PROPERTY,returnedVariableSimpleName,null);
  bodyRewrite.insertLast(returnStatement,null);
  sourceRewriter.set(newMethodDeclaration,MethodDeclaration.BODY_PROPERTY,newMethodBody,null);
  ListRewrite methodDeclarationRewrite=sourceRewriter.getListRewrite(sourceTypeDeclaration,TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
  methodDeclarationRewrite.insertAfter(newMethodDeclaration,sourceMethodDeclaration,null);
}