Program: 12282
Project: 12282
Buggy source:
private void modifySourceMemberAccessesInTargetClass(MethodDeclaration newMethodDeclaration){
  ExpressionExtractor extractor=new ExpressionExtractor();
  List<Expression> sourceMethodInvocations=extractor.getMethodInvocations(sourceMethod.getBody());
  List<Expression> newMethodInvocations=extractor.getMethodInvocations(newMethodDeclaration.getBody());
  List<Expression> expressionsToBeRemoved=new ArrayList<Expression>();
  int k=0;
  for (  Expression expression : sourceMethodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
      for (      MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
        if (identicalSignature(sourceMethodDeclaration,methodInvocation)) {
          MethodInvocation delegation=isDelegate(sourceMethodDeclaration);
          if (delegation != null) {
            ITypeBinding declaringClassTypeBinding=delegation.resolveMethodBinding().getDeclaringClass();
            if (declaringClassTypeBinding.getQualifiedName().equals(targetTypeDeclaration.resolveBinding().getQualifiedName())) {
              if (delegation.getExpression() != null) {
                MethodInvocation newMethodInvocation=(MethodInvocation)ASTNode.copySubtree(newMethodDeclaration.getAST(),delegation);
                targetRewriter.remove(newMethodInvocation.getExpression(),null);
                targetRewriter.replace(newMethodInvocations.get(k),newMethodInvocation,null);
              }
              expressionsToBeRemoved.add(methodInvocation);
            }
          }
        }
      }
    }
    k++;
  }
  for (  Expression expression : expressionsToBeRemoved) {
    int index=sourceMethodInvocations.indexOf(expression);
    sourceMethodInvocations.remove(index);
    newMethodInvocations.remove(index);
  }
  List<Expression> sourceFieldInstructions=extractor.getVariableInstructions(sourceMethod.getBody());
  List<Expression> newFieldInstructions=extractor.getVariableInstructions(newMethodDeclaration.getBody());
  SimpleName parameterName=null;
  int numberOfOccurences=0;
  int i=0;
  for (  Expression expression : sourceMethodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      IMethodBinding methodBinding=methodInvocation.resolveMethodBinding();
      if (methodBinding.getDeclaringClass().equals(sourceTypeDeclaration.resolveBinding())) {
        numberOfOccurences++;
        if (numberOfOccurences == 1) {
          parameterName=addSourceClassParameter(newMethodDeclaration);
        }
        MethodInvocation newMethodInvocation=(MethodInvocation)newMethodInvocations.get(i);
        targetRewriter.set(newMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,parameterName,null);
      }
    }
    i++;
  }
  int j=0;
  for (  Expression expression : sourceFieldInstructions) {
    SimpleName simpleName=(SimpleName)expression;
    IBinding binding=simpleName.resolveBinding();
    if (binding.getKind() == IBinding.VARIABLE) {
      IVariableBinding variableBinding=(IVariableBinding)binding;
      if (variableBinding.isField() && variableBinding.getDeclaringClass().equals(sourceTypeDeclaration.resolveBinding()) && (variableBinding.getModifiers() & Modifier.STATIC) == 0) {
        numberOfOccurences++;
        if (numberOfOccurences == 1) {
          parameterName=addSourceClassParameter(newMethodDeclaration);
        }
        SimpleName expressionName=(SimpleName)newFieldInstructions.get(j);
        AST ast=newMethodDeclaration.getAST();
        if (expressionName.getParent() instanceof FieldAccess) {
          SimpleName qualifier=ast.newSimpleName(parameterName.getIdentifier());
          targetRewriter.set(expressionName.getParent(),FieldAccess.EXPRESSION_PROPERTY,qualifier,null);
        }
 else {
          SimpleName newSimpleName=ast.newSimpleName(expressionName.getIdentifier());
          SimpleName qualifier=ast.newSimpleName(parameterName.getIdentifier());
          QualifiedName newQualifiedName=ast.newQualifiedName(qualifier,newSimpleName);
          targetRewriter.replace(expressionName,newQualifiedName,null);
        }
      }
    }
    j++;
  }
}

Fixed version (ground truth):
private void modifySourceMemberAccessesInTargetClass(MethodDeclaration newMethodDeclaration){
  ExpressionExtractor extractor=new ExpressionExtractor();
  List<Expression> sourceMethodInvocations=extractor.getMethodInvocations(sourceMethod.getBody());
  List<Expression> newMethodInvocations=extractor.getMethodInvocations(newMethodDeclaration.getBody());
  List<Expression> expressionsToBeRemoved=new ArrayList<Expression>();
  int k=0;
  for (  Expression expression : sourceMethodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      MethodDeclaration[] sourceMethodDeclarations=sourceTypeDeclaration.getMethods();
      for (      MethodDeclaration sourceMethodDeclaration : sourceMethodDeclarations) {
        if (identicalSignature(sourceMethodDeclaration,methodInvocation)) {
          MethodInvocation delegation=isDelegate(sourceMethodDeclaration);
          if (delegation != null) {
            ITypeBinding declaringClassTypeBinding=delegation.resolveMethodBinding().getDeclaringClass();
            if (declaringClassTypeBinding.getQualifiedName().equals(targetTypeDeclaration.resolveBinding().getQualifiedName())) {
              if (delegation.getExpression() != null) {
                MethodInvocation newMethodInvocation=(MethodInvocation)ASTNode.copySubtree(newMethodDeclaration.getAST(),delegation);
                targetRewriter.remove(newMethodInvocation.getExpression(),null);
                targetRewriter.replace(newMethodInvocations.get(k),newMethodInvocation,null);
              }
              expressionsToBeRemoved.add(methodInvocation);
            }
          }
        }
      }
    }
    k++;
  }
  for (  Expression expression : expressionsToBeRemoved) {
    int index=sourceMethodInvocations.indexOf(expression);
    sourceMethodInvocations.remove(index);
    newMethodInvocations.remove(index);
  }
  List<Expression> sourceFieldInstructions=extractor.getVariableInstructions(sourceMethod.getBody());
  List<Expression> newFieldInstructions=extractor.getVariableInstructions(newMethodDeclaration.getBody());
  SimpleName parameterName=null;
  int numberOfOccurences=0;
  int i=0;
  for (  Expression expression : sourceMethodInvocations) {
    if (expression instanceof MethodInvocation) {
      MethodInvocation methodInvocation=(MethodInvocation)expression;
      IMethodBinding methodBinding=methodInvocation.resolveMethodBinding();
      if (methodBinding.getDeclaringClass().equals(sourceTypeDeclaration.resolveBinding())) {
        numberOfOccurences++;
        if (numberOfOccurences == 1) {
          parameterName=addSourceClassParameter(newMethodDeclaration);
        }
        MethodInvocation newMethodInvocation=(MethodInvocation)newMethodInvocations.get(i);
        targetRewriter.set(newMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,parameterName,null);
      }
    }
    i++;
  }
  int j=0;
  for (  Expression expression : sourceFieldInstructions) {
    SimpleName simpleName=(SimpleName)expression;
    IBinding binding=simpleName.resolveBinding();
    if (binding.getKind() == IBinding.VARIABLE) {
      IVariableBinding variableBinding=(IVariableBinding)binding;
      if (variableBinding.isField() && variableBinding.getDeclaringClass().equals(sourceTypeDeclaration.resolveBinding()) && (variableBinding.getModifiers() & Modifier.STATIC) == 0 && !targetClassVariableNames.contains(simpleName.getIdentifier())) {
        numberOfOccurences++;
        if (numberOfOccurences == 1) {
          parameterName=addSourceClassParameter(newMethodDeclaration);
        }
        SimpleName expressionName=(SimpleName)newFieldInstructions.get(j);
        AST ast=newMethodDeclaration.getAST();
        if (expressionName.getParent() instanceof FieldAccess) {
          SimpleName qualifier=ast.newSimpleName(parameterName.getIdentifier());
          targetRewriter.set(expressionName.getParent(),FieldAccess.EXPRESSION_PROPERTY,qualifier,null);
        }
 else {
          SimpleName newSimpleName=ast.newSimpleName(expressionName.getIdentifier());
          SimpleName qualifier=ast.newSimpleName(parameterName.getIdentifier());
          QualifiedName newQualifiedName=ast.newQualifiedName(qualifier,newSimpleName);
          targetRewriter.replace(expressionName,newQualifiedName,null);
        }
      }
    }
    j++;
  }
}