Program: 12197
Project: 12197
Buggy source:
private void modifyClient(){
  AST clientAST=sourceTypeDeclaration.getAST();
  MethodDeclaration typeCheckMethod=typeCheckElimination.getTypeCheckMethod();
  Block typeCheckCodeFragmentParentBlock=(Block)typeCheckElimination.getTypeCheckCodeFragment().getParent();
  ListRewrite typeCheckCodeFragmentParentBlockStatementsRewrite=sourceRewriter.getListRewrite(typeCheckCodeFragmentParentBlock,Block.STATEMENTS_PROPERTY);
  Type typeCheckMethodReturnType=typeCheckMethod.getReturnType2();
  if (typeCheckMethodReturnType.isPrimitiveType() && ((PrimitiveType)typeCheckMethodReturnType).getPrimitiveTypeCode().equals(PrimitiveType.VOID)) {
    MethodInvocation abstractMethodInvocation=clientAST.newMethodInvocation();
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.NAME_PROPERTY,clientAST.newSimpleName(abstractMethodName),null);
    SimpleName typeVariableName=null;
    if (typeCheckElimination.getTypeField() != null) {
      typeVariableName=typeCheckElimination.getTypeField().getName();
    }
 else     if (typeCheckElimination.getTypeLocalVariable() != null) {
      typeVariableName=typeCheckElimination.getTypeLocalVariable();
    }
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,typeVariableName,null);
    ListRewrite methodInvocationArgumentsRewrite=sourceRewriter.getListRewrite(abstractMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
    for (    SingleVariableDeclaration abstractMethodParameter : typeCheckElimination.getAccessedParameters()) {
      methodInvocationArgumentsRewrite.insertLast(abstractMethodParameter.getName(),null);
    }
    for (    VariableDeclarationFragment fragment : typeCheckElimination.getAccessedLocalVariables()) {
      if (!fragment.equals(returnedVariable)) {
        methodInvocationArgumentsRewrite.insertLast(fragment.getName(),null);
      }
    }
    if (typeCheckElimination.getAccessedFields().size() > 0 || typeCheckElimination.getAssignedFields().size() > 0 || typeCheckElimination.getAccessedMethods().size() > 0 || typeCheckElimination.getSuperAccessedMethods().size() > 0) {
      methodInvocationArgumentsRewrite.insertLast(clientAST.newThisExpression(),null);
    }
    ExpressionStatement expressionStatement=clientAST.newExpressionStatement(abstractMethodInvocation);
    typeCheckCodeFragmentParentBlockStatementsRewrite.replace(typeCheckElimination.getTypeCheckCodeFragment(),expressionStatement,null);
  }
 else {
    MethodInvocation abstractMethodInvocation=clientAST.newMethodInvocation();
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.NAME_PROPERTY,clientAST.newSimpleName(abstractMethodName),null);
    SimpleName typeVariableName=null;
    if (typeCheckElimination.getTypeField() != null) {
      typeVariableName=typeCheckElimination.getTypeField().getName();
    }
 else     if (typeCheckElimination.getTypeLocalVariable() != null) {
      typeVariableName=typeCheckElimination.getTypeLocalVariable();
    }
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,typeVariableName,null);
    ListRewrite methodInvocationArgumentsRewrite=sourceRewriter.getListRewrite(abstractMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
    for (    SingleVariableDeclaration abstractMethodParameter : typeCheckElimination.getAccessedParameters()) {
      methodInvocationArgumentsRewrite.insertLast(abstractMethodParameter.getName(),null);
    }
    for (    VariableDeclarationFragment fragment : typeCheckElimination.getAccessedLocalVariables()) {
      if (!fragment.equals(returnedVariable)) {
        methodInvocationArgumentsRewrite.insertLast(fragment.getName(),null);
      }
    }
    if (typeCheckElimination.getAccessedFields().size() > 0 || typeCheckElimination.getAssignedFields().size() > 0 || typeCheckElimination.getAccessedMethods().size() > 0 || typeCheckElimination.getSuperAccessedMethods().size() > 0) {
      methodInvocationArgumentsRewrite.insertLast(clientAST.newThisExpression(),null);
    }
    if (returnedVariable != null) {
      Assignment assignment=clientAST.newAssignment();
      sourceRewriter.set(assignment,Assignment.OPERATOR_PROPERTY,Assignment.Operator.ASSIGN,null);
      sourceRewriter.set(assignment,Assignment.LEFT_HAND_SIDE_PROPERTY,returnedVariable.getName(),null);
      sourceRewriter.set(assignment,Assignment.RIGHT_HAND_SIDE_PROPERTY,abstractMethodInvocation,null);
      ExpressionStatement expressionStatement=clientAST.newExpressionStatement(assignment);
      typeCheckCodeFragmentParentBlockStatementsRewrite.replace(typeCheckElimination.getTypeCheckCodeFragment(),expressionStatement,null);
    }
 else {
      ReturnStatement returnStatement=clientAST.newReturnStatement();
      sourceRewriter.set(returnStatement,ReturnStatement.EXPRESSION_PROPERTY,abstractMethodInvocation,null);
      typeCheckCodeFragmentParentBlockStatementsRewrite.replace(typeCheckElimination.getTypeCheckCodeFragment(),returnStatement,null);
    }
  }
  generateGettersForAccessedFields();
  generateSettersForAssignedFields();
  setPublicModifierToAccessedMethods();
  ITextFileBufferManager bufferManager=FileBuffers.getTextFileBufferManager();
  ITextFileBuffer sourceTextFileBuffer=bufferManager.getTextFileBuffer(sourceFile.getFullPath(),LocationKind.IFILE);
  IDocument sourceDocument=sourceTextFileBuffer.getDocument();
  TextEdit sourceEdit=sourceRewriter.rewriteAST(sourceDocument,null);
  try {
    UndoEdit sourceUndoEdit=sourceEdit.apply(sourceDocument,UndoEdit.CREATE_UNDO);
    undoRefactoring.put(sourceFile,sourceDocument,sourceUndoEdit);
  }
 catch (  MalformedTreeException e) {
    e.printStackTrace();
  }
catch (  BadLocationException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
private void modifyClient(){
  AST clientAST=sourceTypeDeclaration.getAST();
  Block typeCheckCodeFragmentParentBlock=(Block)typeCheckElimination.getTypeCheckCodeFragment().getParent();
  ListRewrite typeCheckCodeFragmentParentBlockStatementsRewrite=sourceRewriter.getListRewrite(typeCheckCodeFragmentParentBlock,Block.STATEMENTS_PROPERTY);
  if (returnedVariable == null && !typeCheckElimination.typeCheckCodeFragmentContainsReturnStatement()) {
    MethodInvocation abstractMethodInvocation=clientAST.newMethodInvocation();
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.NAME_PROPERTY,clientAST.newSimpleName(abstractMethodName),null);
    SimpleName typeVariableName=null;
    if (typeCheckElimination.getTypeField() != null) {
      typeVariableName=typeCheckElimination.getTypeField().getName();
    }
 else     if (typeCheckElimination.getTypeLocalVariable() != null) {
      typeVariableName=typeCheckElimination.getTypeLocalVariable();
    }
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,typeVariableName,null);
    ListRewrite methodInvocationArgumentsRewrite=sourceRewriter.getListRewrite(abstractMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
    for (    SingleVariableDeclaration abstractMethodParameter : typeCheckElimination.getAccessedParameters()) {
      methodInvocationArgumentsRewrite.insertLast(abstractMethodParameter.getName(),null);
    }
    for (    VariableDeclarationFragment fragment : typeCheckElimination.getAccessedLocalVariables()) {
      if (!fragment.equals(returnedVariable)) {
        methodInvocationArgumentsRewrite.insertLast(fragment.getName(),null);
      }
    }
    if (typeCheckElimination.getAccessedFields().size() > 0 || typeCheckElimination.getAssignedFields().size() > 0 || typeCheckElimination.getAccessedMethods().size() > 0 || typeCheckElimination.getSuperAccessedMethods().size() > 0) {
      methodInvocationArgumentsRewrite.insertLast(clientAST.newThisExpression(),null);
    }
    ExpressionStatement expressionStatement=clientAST.newExpressionStatement(abstractMethodInvocation);
    typeCheckCodeFragmentParentBlockStatementsRewrite.replace(typeCheckElimination.getTypeCheckCodeFragment(),expressionStatement,null);
  }
 else {
    MethodInvocation abstractMethodInvocation=clientAST.newMethodInvocation();
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.NAME_PROPERTY,clientAST.newSimpleName(abstractMethodName),null);
    SimpleName typeVariableName=null;
    if (typeCheckElimination.getTypeField() != null) {
      typeVariableName=typeCheckElimination.getTypeField().getName();
    }
 else     if (typeCheckElimination.getTypeLocalVariable() != null) {
      typeVariableName=typeCheckElimination.getTypeLocalVariable();
    }
    sourceRewriter.set(abstractMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,typeVariableName,null);
    ListRewrite methodInvocationArgumentsRewrite=sourceRewriter.getListRewrite(abstractMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
    for (    SingleVariableDeclaration abstractMethodParameter : typeCheckElimination.getAccessedParameters()) {
      methodInvocationArgumentsRewrite.insertLast(abstractMethodParameter.getName(),null);
    }
    for (    VariableDeclarationFragment fragment : typeCheckElimination.getAccessedLocalVariables()) {
      if (!fragment.equals(returnedVariable)) {
        methodInvocationArgumentsRewrite.insertLast(fragment.getName(),null);
      }
    }
    if (typeCheckElimination.getAccessedFields().size() > 0 || typeCheckElimination.getAssignedFields().size() > 0 || typeCheckElimination.getAccessedMethods().size() > 0 || typeCheckElimination.getSuperAccessedMethods().size() > 0) {
      methodInvocationArgumentsRewrite.insertLast(clientAST.newThisExpression(),null);
    }
    if (returnedVariable != null) {
      Assignment assignment=clientAST.newAssignment();
      sourceRewriter.set(assignment,Assignment.OPERATOR_PROPERTY,Assignment.Operator.ASSIGN,null);
      sourceRewriter.set(assignment,Assignment.LEFT_HAND_SIDE_PROPERTY,returnedVariable.getName(),null);
      sourceRewriter.set(assignment,Assignment.RIGHT_HAND_SIDE_PROPERTY,abstractMethodInvocation,null);
      ExpressionStatement expressionStatement=clientAST.newExpressionStatement(assignment);
      typeCheckCodeFragmentParentBlockStatementsRewrite.replace(typeCheckElimination.getTypeCheckCodeFragment(),expressionStatement,null);
    }
 else {
      ReturnStatement returnStatement=clientAST.newReturnStatement();
      sourceRewriter.set(returnStatement,ReturnStatement.EXPRESSION_PROPERTY,abstractMethodInvocation,null);
      typeCheckCodeFragmentParentBlockStatementsRewrite.replace(typeCheckElimination.getTypeCheckCodeFragment(),returnStatement,null);
    }
  }
  generateGettersForAccessedFields();
  generateSettersForAssignedFields();
  setPublicModifierToAccessedMethods();
  ITextFileBufferManager bufferManager=FileBuffers.getTextFileBufferManager();
  ITextFileBuffer sourceTextFileBuffer=bufferManager.getTextFileBuffer(sourceFile.getFullPath(),LocationKind.IFILE);
  IDocument sourceDocument=sourceTextFileBuffer.getDocument();
  TextEdit sourceEdit=sourceRewriter.rewriteAST(sourceDocument,null);
  try {
    UndoEdit sourceUndoEdit=sourceEdit.apply(sourceDocument,UndoEdit.CREATE_UNDO);
    undoRefactoring.put(sourceFile,sourceDocument,sourceUndoEdit);
  }
 catch (  MalformedTreeException e) {
    e.printStackTrace();
  }
catch (  BadLocationException e) {
    e.printStackTrace();
  }
}