Program: 12284
Project: 12284
Buggy source:
private void replaceExtractedCodeWithMethodInvocation(ASTRewrite rewriter){
  ASTNode parent=extractStatementList.get(0).getParent();
  Assignment assignment=parent.getAST().newAssignment();
  rewriter.set(assignment,Assignment.LEFT_HAND_SIDE_PROPERTY,variableDeclarationFragment.getName(),null);
  if (variableDeclarationStatement.getType().isPrimitiveType() && parent != variableDeclarationStatement.getParent() && isLoop(parent))   rewriter.set(assignment,Assignment.OPERATOR_PROPERTY,Assignment.Operator.PLUS_ASSIGN,null);
 else   rewriter.set(assignment,Assignment.OPERATOR_PROPERTY,Assignment.Operator.ASSIGN,null);
  MethodInvocation methodInvocation=assignment.getAST().newMethodInvocation();
  rewriter.set(methodInvocation,MethodInvocation.NAME_PROPERTY,variableDeclarationFragment.getName(),null);
  ListRewrite argumentRewrite=rewriter.getListRewrite(methodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
  for (  VariableDeclarationStatement statement : variableDeclarationStatementList) {
    List<VariableDeclarationFragment> fragmentList=statement.fragments();
    for (    VariableDeclarationFragment fragment : fragmentList) {
      if (!fragment.getName().getIdentifier().equals(variableDeclarationFragment.getName().getIdentifier()))       argumentRewrite.insertLast(fragment.getName(),null);
    }
  }
  rewriter.set(assignment,Assignment.RIGHT_HAND_SIDE_PROPERTY,methodInvocation,null);
  ExpressionStatement expressionStatement=parent.getAST().newExpressionStatement(assignment);
  for (int i=0; i < extractStatementList.size(); i++) {
    Statement statement=extractStatementList.get(i);
    ListRewrite bodyRewrite=rewriter.getListRewrite(statement.getParent(),Block.STATEMENTS_PROPERTY);
    if (i == extractStatementList.size() - 1)     bodyRewrite.replace(statement,expressionStatement,null);
 else     bodyRewrite.remove(statement,null);
  }
}

Fixed version (ground truth):
private void replaceExtractedCodeWithMethodInvocation(List<SimpleName> extractedMethodArguments){
  ASTNode parent=extractStatementList.get(0).getParent();
  Assignment assignment=parent.getAST().newAssignment();
  sourceRewriter.set(assignment,Assignment.LEFT_HAND_SIDE_PROPERTY,variableDeclarationFragment.getName(),null);
  if (variableDeclarationStatement.getType().isPrimitiveType() && parent != variableDeclarationStatement.getParent() && isLoop(parent))   sourceRewriter.set(assignment,Assignment.OPERATOR_PROPERTY,Assignment.Operator.PLUS_ASSIGN,null);
 else   sourceRewriter.set(assignment,Assignment.OPERATOR_PROPERTY,Assignment.Operator.ASSIGN,null);
  MethodInvocation methodInvocation=assignment.getAST().newMethodInvocation();
  sourceRewriter.set(methodInvocation,MethodInvocation.NAME_PROPERTY,variableDeclarationFragment.getName(),null);
  ListRewrite argumentRewrite=sourceRewriter.getListRewrite(methodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
  for (  SimpleName argument : extractedMethodArguments) {
    argumentRewrite.insertLast(argument,null);
  }
  sourceRewriter.set(assignment,Assignment.RIGHT_HAND_SIDE_PROPERTY,methodInvocation,null);
  ExpressionStatement expressionStatement=parent.getAST().newExpressionStatement(assignment);
  for (int i=0; i < extractStatementList.size(); i++) {
    Statement statement=extractStatementList.get(i);
    ListRewrite bodyRewrite=sourceRewriter.getListRewrite(statement.getParent(),Block.STATEMENTS_PROPERTY);
    if (i == extractStatementList.size() - 1)     bodyRewrite.replace(statement,expressionStatement,null);
 else     bodyRewrite.remove(statement,null);
  }
}