Program: 12152
Project: 12152
Buggy source:
private void modifySourceMethod(){
  AST ast=sourceMethodDeclaration.getAST();
  MethodInvocation extractedMethodInvocation=ast.newMethodInvocation();
  sourceRewriter.set(extractedMethodInvocation,MethodInvocation.NAME_PROPERTY,ast.newSimpleName(slice.getExtractedMethodName()),null);
  ListRewrite argumentRewrite=sourceRewriter.getListRewrite(extractedMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
  for (  VariableDeclaration variableDeclaration : slice.getPassedParameters()) {
    argumentRewrite.insertLast(variableDeclaration.getName(),null);
  }
  if (slice.declarationOfVariableCriterionBelongsToSliceNodes() && slice.declarationOfVariableCriterionBelongsToRemovableNodes()) {
    VariableDeclaration returnedVariableDeclaration=slice.getLocalVariableCriterion();
    VariableDeclarationFragment initializationFragment=ast.newVariableDeclarationFragment();
    sourceRewriter.set(initializationFragment,VariableDeclarationFragment.NAME_PROPERTY,returnedVariableDeclaration.getName(),null);
    sourceRewriter.set(initializationFragment,VariableDeclarationFragment.INITIALIZER_PROPERTY,extractedMethodInvocation,null);
    VariableDeclarationStatement initializationVariableDeclarationStatement=ast.newVariableDeclarationStatement(initializationFragment);
    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(initializationVariableDeclarationStatement,VariableDeclarationStatement.TYPE_PROPERTY,returnedVariableType,null);
    Statement extractedMethodInvocationInsertionStatement=slice.getExtractedMethodInvocationInsertionStatement();
    Block parentStatement=(Block)extractedMethodInvocationInsertionStatement.getParent();
    ListRewrite blockRewrite=sourceRewriter.getListRewrite(parentStatement,Block.STATEMENTS_PROPERTY);
    blockRewrite.insertBefore(initializationVariableDeclarationStatement,extractedMethodInvocationInsertionStatement,null);
  }
 else   if (slice.declarationOfVariableCriterionBelongsToSliceNodes() && !slice.declarationOfVariableCriterionBelongsToRemovableNodes()) {
    VariableDeclaration returnedVariableDeclaration=slice.getLocalVariableCriterion();
    if (returnedVariableDeclaration instanceof VariableDeclarationFragment) {
      VariableDeclarationFragment initializationFragment=(VariableDeclarationFragment)returnedVariableDeclaration;
      sourceRewriter.set(initializationFragment,VariableDeclarationFragment.INITIALIZER_PROPERTY,extractedMethodInvocation,null);
    }
  }
 else {
    Assignment assignment=ast.newAssignment();
    sourceRewriter.set(assignment,Assignment.LEFT_HAND_SIDE_PROPERTY,slice.getLocalVariableCriterion().getName(),null);
    sourceRewriter.set(assignment,Assignment.RIGHT_HAND_SIDE_PROPERTY,extractedMethodInvocation,null);
    ExpressionStatement expressionStatement=ast.newExpressionStatement(assignment);
    Statement extractedMethodInvocationInsertionStatement=slice.getExtractedMethodInvocationInsertionStatement();
    Block parentStatement=(Block)extractedMethodInvocationInsertionStatement.getParent();
    ListRewrite blockRewrite=sourceRewriter.getListRewrite(parentStatement,Block.STATEMENTS_PROPERTY);
    blockRewrite.insertBefore(expressionStatement,extractedMethodInvocationInsertionStatement,null);
  }
  for (  Statement removableStatement : slice.getRemovableStatements()) {
    sourceRewriter.remove(removableStatement,null);
  }
}

Fixed version (ground truth):
private void modifySourceMethod(){
  AST ast=sourceMethodDeclaration.getAST();
  MethodInvocation extractedMethodInvocation=ast.newMethodInvocation();
  sourceRewriter.set(extractedMethodInvocation,MethodInvocation.NAME_PROPERTY,ast.newSimpleName(slice.getExtractedMethodName()),null);
  ListRewrite argumentRewrite=sourceRewriter.getListRewrite(extractedMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
  for (  VariableDeclaration variableDeclaration : slice.getPassedParameters()) {
    argumentRewrite.insertLast(variableDeclaration.getName(),null);
  }
  if (slice.declarationOfVariableCriterionBelongsToSliceNodes() && slice.declarationOfVariableCriterionBelongsToRemovableNodes()) {
    VariableDeclaration returnedVariableDeclaration=slice.getLocalVariableCriterion();
    VariableDeclarationFragment initializationFragment=ast.newVariableDeclarationFragment();
    sourceRewriter.set(initializationFragment,VariableDeclarationFragment.NAME_PROPERTY,returnedVariableDeclaration.getName(),null);
    sourceRewriter.set(initializationFragment,VariableDeclarationFragment.INITIALIZER_PROPERTY,extractedMethodInvocation,null);
    VariableDeclarationStatement initializationVariableDeclarationStatement=ast.newVariableDeclarationStatement(initializationFragment);
    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(initializationVariableDeclarationStatement,VariableDeclarationStatement.TYPE_PROPERTY,returnedVariableType,null);
    Statement extractedMethodInvocationInsertionStatement=slice.getExtractedMethodInvocationInsertionStatement();
    Block parentStatement=(Block)extractedMethodInvocationInsertionStatement.getParent();
    ListRewrite blockRewrite=sourceRewriter.getListRewrite(parentStatement,Block.STATEMENTS_PROPERTY);
    blockRewrite.insertBefore(initializationVariableDeclarationStatement,extractedMethodInvocationInsertionStatement,null);
  }
 else   if (slice.declarationOfVariableCriterionBelongsToSliceNodes() && !slice.declarationOfVariableCriterionBelongsToRemovableNodes()) {
    VariableDeclaration returnedVariableDeclaration=slice.getLocalVariableCriterion();
    if (returnedVariableDeclaration instanceof VariableDeclarationFragment) {
      VariableDeclarationFragment oldInitializationFragment=(VariableDeclarationFragment)returnedVariableDeclaration;
      VariableDeclarationFragment newInitializationFragment=ast.newVariableDeclarationFragment();
      sourceRewriter.set(newInitializationFragment,VariableDeclarationFragment.NAME_PROPERTY,returnedVariableDeclaration.getName(),null);
      sourceRewriter.set(newInitializationFragment,VariableDeclarationFragment.INITIALIZER_PROPERTY,extractedMethodInvocation,null);
      if (oldInitializationFragment.getParent() instanceof VariableDeclarationStatement) {
        VariableDeclarationStatement oldVariableDeclarationStatement=(VariableDeclarationStatement)oldInitializationFragment.getParent();
        List<VariableDeclarationFragment> oldFragments=oldVariableDeclarationStatement.fragments();
        VariableDeclarationStatement newVariableDeclarationStatement=ast.newVariableDeclarationStatement(newInitializationFragment);
        sourceRewriter.set(newVariableDeclarationStatement,VariableDeclarationStatement.TYPE_PROPERTY,oldVariableDeclarationStatement.getType(),null);
        ListRewrite fragmentRewrite=sourceRewriter.getListRewrite(newVariableDeclarationStatement,VariableDeclarationStatement.FRAGMENTS_PROPERTY);
        for (int i=0; i < oldFragments.size(); i++) {
          if (!oldInitializationFragment.equals(oldFragments.get(i)))           fragmentRewrite.insertLast(oldFragments.get(i),null);
        }
        sourceRewriter.replace(oldVariableDeclarationStatement,newVariableDeclarationStatement,null);
      }
    }
  }
 else {
    Assignment assignment=ast.newAssignment();
    sourceRewriter.set(assignment,Assignment.LEFT_HAND_SIDE_PROPERTY,slice.getLocalVariableCriterion().getName(),null);
    sourceRewriter.set(assignment,Assignment.RIGHT_HAND_SIDE_PROPERTY,extractedMethodInvocation,null);
    ExpressionStatement expressionStatement=ast.newExpressionStatement(assignment);
    Statement extractedMethodInvocationInsertionStatement=slice.getExtractedMethodInvocationInsertionStatement();
    Block parentStatement=(Block)extractedMethodInvocationInsertionStatement.getParent();
    ListRewrite blockRewrite=sourceRewriter.getListRewrite(parentStatement,Block.STATEMENTS_PROPERTY);
    blockRewrite.insertBefore(expressionStatement,extractedMethodInvocationInsertionStatement,null);
  }
  for (  Statement removableStatement : slice.getRemovableStatements()) {
    sourceRewriter.remove(removableStatement,null);
  }
}