Program: 12029
Project: 12029
Buggy source:
private void extractMethod(MultiTextEdit root){
  ASTRewrite sourceRewriter=ASTRewrite.create(sourceTypeDeclaration.getAST());
  AST ast=sourceTypeDeclaration.getAST();
  MethodDeclaration newMethodDeclaration=ast.newMethodDeclaration();
  VariableDeclaration returnedVariableDeclaration=slice.getLocalVariableCriterion();
  SimpleName returnedVariableSimpleName=returnedVariableDeclaration.getName();
  ITypeBinding returnedVariableTypeBinding=extractTypeBinding(returnedVariableDeclaration);
  Type returnedVariableType=RefactoringUtility.generateTypeFromTypeBinding(returnedVariableTypeBinding,ast,sourceRewriter);
  sourceRewriter.set(newMethodDeclaration,MethodDeclaration.NAME_PROPERTY,ast.newSimpleName(slice.getExtractedMethodName()),null);
  IVariableBinding returnedVariableBinding=returnedVariableDeclaration.resolveBinding();
  if (slice.isObjectSlice() && (returnedVariableBinding.isField() || returnedVariableBinding.isParameter() || !slice.declarationOfVariableCriterionBelongsToSliceNodes()))   sourceRewriter.set(newMethodDeclaration,MethodDeclaration.RETURN_TYPE2_PROPERTY,ast.newPrimitiveType(PrimitiveType.VOID),null);
 else   sourceRewriter.set(newMethodDeclaration,MethodDeclaration.RETURN_TYPE2_PROPERTY,returnedVariableType,null);
  ListRewrite modifierRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.MODIFIERS2_PROPERTY);
  Modifier accessModifier=newMethodDeclaration.getAST().newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD);
  modifierRewrite.insertLast(accessModifier,null);
  if ((sourceMethodDeclaration.getModifiers() & Modifier.STATIC) != 0) {
    Modifier staticModifier=newMethodDeclaration.getAST().newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD);
    modifierRewrite.insertLast(staticModifier,null);
  }
  ListRewrite parameterRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.PARAMETERS_PROPERTY);
  for (  VariableDeclaration variableDeclaration : slice.getPassedParameters()) {
    ITypeBinding variableTypeBinding=extractTypeBinding(variableDeclaration);
    Type variableType=RefactoringUtility.generateTypeFromTypeBinding(variableTypeBinding,ast,sourceRewriter);
    if (!variableDeclaration.resolveBinding().isField()) {
      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);
    }
  }
  ListRewrite thrownExceptionRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.THROWN_EXCEPTIONS_PROPERTY);
  for (  ITypeBinding thrownExceptionType : exceptionTypesThatShouldBeThrownByExtractedMethod) {
    thrownExceptionRewrite.insertLast(ast.newName(thrownExceptionType.getQualifiedName()),null);
  }
  Block newMethodBody=newMethodDeclaration.getAST().newBlock();
  ListRewrite methodBodyRewrite=sourceRewriter.getListRewrite(newMethodBody,Block.STATEMENTS_PROPERTY);
  List<PDGNode> sliceNodes=new ArrayList<PDGNode>(slice.getSliceNodes());
  while (!sliceNodes.isEmpty()) {
    ListRewrite bodyRewrite=methodBodyRewrite;
    PDGNode node=sliceNodes.get(0);
    PDGControlPredicateNode doLoopPredicateNode=isInsideDoLoop(node);
    if (doLoopPredicateNode != null) {
      bodyRewrite=createTryStatementIfNeeded(sourceRewriter,ast,bodyRewrite,doLoopPredicateNode);
      if (sliceNodes.contains(doLoopPredicateNode)) {
        bodyRewrite.insertLast(processPredicateNode(doLoopPredicateNode,ast,sourceRewriter,sliceNodes),null);
      }
    }
 else {
      bodyRewrite=createTryStatementIfNeeded(sourceRewriter,ast,bodyRewrite,node);
      if (node instanceof PDGControlPredicateNode) {
        PDGControlPredicateNode predicateNode=(PDGControlPredicateNode)node;
        bodyRewrite.insertLast(processPredicateNode(predicateNode,ast,sourceRewriter,sliceNodes),null);
      }
 else       if (node instanceof PDGTryNode) {
        sliceNodes.remove(node);
      }
 else {
        bodyRewrite.insertLast(node.getASTStatement(),null);
        sliceNodes.remove(node);
      }
    }
  }
  if (!slice.isObjectSlice() || (!returnedVariableBinding.isField() && !returnedVariableBinding.isParameter() && slice.declarationOfVariableCriterionBelongsToSliceNodes())) {
    ReturnStatement returnStatement=newMethodBody.getAST().newReturnStatement();
    sourceRewriter.set(returnStatement,ReturnStatement.EXPRESSION_PROPERTY,returnedVariableSimpleName,null);
    methodBodyRewrite.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);
  try {
    TextEdit sourceEdit=sourceRewriter.rewriteAST();
    root.addChild(sourceEdit);
    compilationUnitChange.addTextEditGroup(new TextEditGroup("String_Node_Str",new TextEdit[]{sourceEdit}));
  }
 catch (  JavaModelException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
private void extractMethod(MultiTextEdit root){
  ASTRewrite sourceRewriter=ASTRewrite.create(sourceTypeDeclaration.getAST());
  AST ast=sourceTypeDeclaration.getAST();
  MethodDeclaration newMethodDeclaration=ast.newMethodDeclaration();
  VariableDeclaration returnedVariableDeclaration=slice.getLocalVariableCriterion();
  SimpleName returnedVariableSimpleName=returnedVariableDeclaration.getName();
  ITypeBinding returnedVariableTypeBinding=extractTypeBinding(returnedVariableDeclaration);
  Type returnedVariableType=RefactoringUtility.generateTypeFromTypeBinding(returnedVariableTypeBinding,ast,sourceRewriter);
  sourceRewriter.set(newMethodDeclaration,MethodDeclaration.NAME_PROPERTY,ast.newSimpleName(slice.getExtractedMethodName()),null);
  IVariableBinding returnedVariableBinding=returnedVariableDeclaration.resolveBinding();
  if (slice.isObjectSlice() && (returnedVariableBinding.isField() || returnedVariableBinding.isParameter() || !slice.declarationOfVariableCriterionBelongsToSliceNodes()))   sourceRewriter.set(newMethodDeclaration,MethodDeclaration.RETURN_TYPE2_PROPERTY,ast.newPrimitiveType(PrimitiveType.VOID),null);
 else   sourceRewriter.set(newMethodDeclaration,MethodDeclaration.RETURN_TYPE2_PROPERTY,returnedVariableType,null);
  ListRewrite modifierRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.MODIFIERS2_PROPERTY);
  Modifier accessModifier=newMethodDeclaration.getAST().newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD);
  modifierRewrite.insertLast(accessModifier,null);
  if ((sourceMethodDeclaration.getModifiers() & Modifier.STATIC) != 0) {
    Modifier staticModifier=newMethodDeclaration.getAST().newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD);
    modifierRewrite.insertLast(staticModifier,null);
  }
  ListRewrite parameterRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.PARAMETERS_PROPERTY);
  Set<ITypeBinding> requiredTypeParameterBindings=new LinkedHashSet<ITypeBinding>();
  for (  VariableDeclaration variableDeclaration : slice.getPassedParameters()) {
    ITypeBinding variableTypeBinding=extractTypeBinding(variableDeclaration);
    TypeVisitor typeVisitor=new TypeVisitor();
    variableDeclaration.accept(typeVisitor);
    Set<ITypeBinding> typeBindings=typeVisitor.getTypeBindings();
    for (    ITypeBinding typeBinding : typeBindings) {
      if (typeBinding.isTypeVariable()) {
        requiredTypeParameterBindings.add(typeBinding);
      }
    }
    Type variableType=RefactoringUtility.generateTypeFromTypeBinding(variableTypeBinding,ast,sourceRewriter);
    if (!variableDeclaration.resolveBinding().isField()) {
      SingleVariableDeclaration parameter=ast.newSingleVariableDeclaration();
      sourceRewriter.set(parameter,SingleVariableDeclaration.NAME_PROPERTY,variableDeclaration.getName(),null);
      sourceRewriter.set(parameter,SingleVariableDeclaration.TYPE_PROPERTY,variableType,null);
      if ((variableDeclaration.resolveBinding().getModifiers() & Modifier.FINAL) != 0) {
        Modifier finalModifier=newMethodDeclaration.getAST().newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD);
        ListRewrite parameterModifierRewrite=sourceRewriter.getListRewrite(parameter,SingleVariableDeclaration.MODIFIERS2_PROPERTY);
        parameterModifierRewrite.insertLast(finalModifier,null);
      }
      parameterRewrite.insertLast(parameter,null);
    }
  }
  ListRewrite typeParameterRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.TYPE_PARAMETERS_PROPERTY);
  for (  ITypeBinding typeParameterBinding : requiredTypeParameterBindings) {
    TypeParameter typeParameter=ast.newTypeParameter();
    sourceRewriter.set(typeParameter,TypeParameter.NAME_PROPERTY,ast.newSimpleName(typeParameterBinding.getName()),null);
    ITypeBinding[] typeBounds=typeParameterBinding.getTypeBounds();
    if (typeBounds.length > 0) {
      ListRewrite typeBoundsRewrite=sourceRewriter.getListRewrite(typeParameter,TypeParameter.TYPE_BOUNDS_PROPERTY);
      for (      ITypeBinding typeBoundBinding : typeBounds) {
        Type typeBound=RefactoringUtility.generateTypeFromTypeBinding(typeBoundBinding,ast,sourceRewriter);
        typeBoundsRewrite.insertLast(typeBound,null);
      }
    }
    typeParameterRewrite.insertLast(typeParameter,null);
  }
  ListRewrite thrownExceptionRewrite=sourceRewriter.getListRewrite(newMethodDeclaration,MethodDeclaration.THROWN_EXCEPTIONS_PROPERTY);
  for (  ITypeBinding thrownExceptionType : exceptionTypesThatShouldBeThrownByExtractedMethod) {
    thrownExceptionRewrite.insertLast(ast.newName(thrownExceptionType.getQualifiedName()),null);
  }
  Block newMethodBody=newMethodDeclaration.getAST().newBlock();
  ListRewrite methodBodyRewrite=sourceRewriter.getListRewrite(newMethodBody,Block.STATEMENTS_PROPERTY);
  List<PDGNode> sliceNodes=new ArrayList<PDGNode>(slice.getSliceNodes());
  while (!sliceNodes.isEmpty()) {
    ListRewrite bodyRewrite=methodBodyRewrite;
    PDGNode node=sliceNodes.get(0);
    PDGControlPredicateNode doLoopPredicateNode=isInsideDoLoop(node);
    if (doLoopPredicateNode != null) {
      bodyRewrite=createTryStatementIfNeeded(sourceRewriter,ast,bodyRewrite,doLoopPredicateNode);
      if (sliceNodes.contains(doLoopPredicateNode)) {
        bodyRewrite.insertLast(processPredicateNode(doLoopPredicateNode,ast,sourceRewriter,sliceNodes),null);
      }
    }
 else {
      bodyRewrite=createTryStatementIfNeeded(sourceRewriter,ast,bodyRewrite,node);
      if (node instanceof PDGControlPredicateNode) {
        PDGControlPredicateNode predicateNode=(PDGControlPredicateNode)node;
        bodyRewrite.insertLast(processPredicateNode(predicateNode,ast,sourceRewriter,sliceNodes),null);
      }
 else       if (node instanceof PDGTryNode) {
        sliceNodes.remove(node);
      }
 else {
        bodyRewrite.insertLast(node.getASTStatement(),null);
        sliceNodes.remove(node);
      }
    }
  }
  if (!slice.isObjectSlice() || (!returnedVariableBinding.isField() && !returnedVariableBinding.isParameter() && slice.declarationOfVariableCriterionBelongsToSliceNodes())) {
    ReturnStatement returnStatement=newMethodBody.getAST().newReturnStatement();
    sourceRewriter.set(returnStatement,ReturnStatement.EXPRESSION_PROPERTY,returnedVariableSimpleName,null);
    methodBodyRewrite.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);
  try {
    TextEdit sourceEdit=sourceRewriter.rewriteAST();
    root.addChild(sourceEdit);
    compilationUnitChange.addTextEditGroup(new TextEditGroup("String_Node_Str",new TextEdit[]{sourceEdit}));
  }
 catch (  JavaModelException e) {
    e.printStackTrace();
  }
}