Program: 12087
Project: 12087
Buggy source:
private void modifyTypeFieldAssignmentsInContextClass(boolean modify){
  ExpressionExtractor expressionExtractor=new ExpressionExtractor();
  Set<MethodDeclaration> contextMethods=getAllMethodDeclarationsInSourceClass();
  List<SimpleName> staticFields=typeCheckElimination.getStaticFields();
  MethodDeclaration typeFieldSetterMethod=typeCheckElimination.getTypeFieldSetterMethod();
  for (  MethodDeclaration methodDeclaration : contextMethods) {
    if (!methodDeclaration.equals(typeFieldSetterMethod)) {
      Block methodBody=methodDeclaration.getBody();
      if (methodBody != null) {
        List<Statement> statements=methodBody.statements();
        for (        Statement statement : statements) {
          List<Expression> assignments=expressionExtractor.getAssignments(statement);
          for (          Expression expression : assignments) {
            Assignment assignment=(Assignment)expression;
            Expression leftHandSide=assignment.getLeftHandSide();
            SimpleName assignedVariable=null;
            Expression invoker=null;
            if (leftHandSide instanceof SimpleName) {
              assignedVariable=(SimpleName)leftHandSide;
            }
 else             if (leftHandSide instanceof QualifiedName) {
              QualifiedName qualifiedName=(QualifiedName)leftHandSide;
              assignedVariable=qualifiedName.getName();
              invoker=qualifiedName.getQualifier();
            }
 else             if (leftHandSide instanceof FieldAccess) {
              FieldAccess fieldAccess=(FieldAccess)leftHandSide;
              assignedVariable=fieldAccess.getName();
              invoker=fieldAccess.getExpression();
            }
            Expression rightHandSide=assignment.getRightHandSide();
            List<Expression> accessedVariables=expressionExtractor.getVariableInstructions(rightHandSide);
            ASTRewrite sourceRewriter=ASTRewrite.create(sourceTypeDeclaration.getAST());
            AST contextAST=sourceTypeDeclaration.getAST();
            boolean rewriteAST=false;
            if (assignedVariable != null) {
              IBinding leftHandBinding=assignedVariable.resolveBinding();
              if (leftHandBinding != null && leftHandBinding.getKind() == IBinding.VARIABLE) {
                IVariableBinding assignedVariableBinding=(IVariableBinding)leftHandBinding;
                if (assignedVariableBinding.isField() && typeCheckElimination.getTypeField().resolveBinding().isEqualTo(assignedVariableBinding)) {
                  if (modify && !nodeExistsInsideTypeCheckCodeFragment(assignment)) {
                    MethodInvocation setterMethodInvocation=contextAST.newMethodInvocation();
                    if (typeCheckElimination.getTypeFieldSetterMethod() != null) {
                      sourceRewriter.set(setterMethodInvocation,MethodInvocation.NAME_PROPERTY,typeCheckElimination.getTypeFieldSetterMethod().getName(),null);
                    }
 else {
                      sourceRewriter.set(setterMethodInvocation,MethodInvocation.NAME_PROPERTY,contextAST.newSimpleName("String_Node_Str" + abstractClassName),null);
                    }
                    ListRewrite setterMethodInvocationArgumentsRewrite=sourceRewriter.getListRewrite(setterMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
                    setterMethodInvocationArgumentsRewrite.insertLast(assignment.getRightHandSide(),null);
                    if (invoker != null) {
                      sourceRewriter.set(setterMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,invoker,null);
                    }
                    sourceRewriter.replace(assignment,setterMethodInvocation,null);
                    rewriteAST=true;
                  }
                  for (                  Expression expression2 : accessedVariables) {
                    SimpleName accessedVariable=(SimpleName)expression2;
                    IBinding rightHandBinding=accessedVariable.resolveBinding();
                    if (rightHandBinding != null && rightHandBinding.getKind() == IBinding.VARIABLE) {
                      IVariableBinding accessedVariableBinding=(IVariableBinding)rightHandBinding;
                      if (accessedVariableBinding.isField() && (accessedVariableBinding.getModifiers() & Modifier.STATIC) != 0 && !containsVariable(staticFields,accessedVariable) && accessedVariableBinding.getType().isEqualTo(assignedVariableBinding.getType())) {
                        if (!containsStaticFieldKey(accessedVariable) && !modify)                         additionalStaticFieldMap.put(accessedVariable,generateSubclassName(accessedVariable));
                      }
                    }
                  }
                }
              }
            }
            for (            Expression expression2 : accessedVariables) {
              SimpleName accessedVariable=(SimpleName)expression2;
              IBinding rightHandBinding=accessedVariable.resolveBinding();
              if (rightHandBinding != null && rightHandBinding.getKind() == IBinding.VARIABLE) {
                IVariableBinding accessedVariableBinding=(IVariableBinding)rightHandBinding;
                if (accessedVariableBinding.isField() && typeCheckElimination.getTypeField().resolveBinding().isEqualTo(accessedVariableBinding)) {
                  if (modify && !nodeExistsInsideTypeCheckCodeFragment(accessedVariable)) {
                    MethodInvocation getterMethodInvocation=contextAST.newMethodInvocation();
                    if (typeCheckElimination.getTypeFieldGetterMethod() != null) {
                      sourceRewriter.set(getterMethodInvocation,MethodInvocation.NAME_PROPERTY,typeCheckElimination.getTypeFieldGetterMethod().getName(),null);
                    }
 else {
                      sourceRewriter.set(getterMethodInvocation,MethodInvocation.NAME_PROPERTY,contextAST.newSimpleName("String_Node_Str" + abstractClassName),null);
                    }
                    sourceRewriter.replace(accessedVariable,getterMethodInvocation,null);
                    rewriteAST=true;
                  }
                }
              }
            }
            if (rewriteAST) {
              try {
                TextEdit sourceEdit=sourceRewriter.rewriteAST();
                ICompilationUnit sourceICompilationUnit=(ICompilationUnit)sourceCompilationUnit.getJavaElement();
                CompilationUnitChange change=compilationUnitChanges.get(sourceICompilationUnit);
                change.getEdit().addChild(sourceEdit);
                change.addTextEditGroup(new TextEditGroup("String_Node_Str",new TextEdit[]{sourceEdit}));
              }
 catch (              JavaModelException e) {
                e.printStackTrace();
              }
            }
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
private void modifyTypeFieldAssignmentsInContextClass(boolean modify){
  ExpressionExtractor expressionExtractor=new ExpressionExtractor();
  Set<MethodDeclaration> contextMethods=getAllMethodDeclarationsInSourceClass();
  List<SimpleName> staticFields=typeCheckElimination.getStaticFields();
  MethodDeclaration typeFieldSetterMethod=typeCheckElimination.getTypeFieldSetterMethod();
  for (  MethodDeclaration methodDeclaration : contextMethods) {
    if (!methodDeclaration.equals(typeFieldSetterMethod)) {
      Block methodBody=methodDeclaration.getBody();
      if (methodBody != null) {
        List<Statement> statements=methodBody.statements();
        for (        Statement statement : statements) {
          List<Expression> assignments=expressionExtractor.getAssignments(statement);
          for (          Expression expression : assignments) {
            Assignment assignment=(Assignment)expression;
            Expression leftHandSide=assignment.getLeftHandSide();
            SimpleName assignedVariable=null;
            Expression invoker=null;
            if (leftHandSide instanceof SimpleName) {
              assignedVariable=(SimpleName)leftHandSide;
            }
 else             if (leftHandSide instanceof QualifiedName) {
              QualifiedName qualifiedName=(QualifiedName)leftHandSide;
              assignedVariable=qualifiedName.getName();
              invoker=qualifiedName.getQualifier();
            }
 else             if (leftHandSide instanceof FieldAccess) {
              FieldAccess fieldAccess=(FieldAccess)leftHandSide;
              assignedVariable=fieldAccess.getName();
              invoker=fieldAccess.getExpression();
            }
            Expression rightHandSide=assignment.getRightHandSide();
            List<Expression> accessedVariables=expressionExtractor.getVariableInstructions(rightHandSide);
            ASTRewrite sourceRewriter=ASTRewrite.create(sourceTypeDeclaration.getAST());
            AST contextAST=sourceTypeDeclaration.getAST();
            boolean rewriteAST=false;
            if (assignedVariable != null) {
              IBinding leftHandBinding=assignedVariable.resolveBinding();
              if (leftHandBinding != null && leftHandBinding.getKind() == IBinding.VARIABLE) {
                IVariableBinding assignedVariableBinding=(IVariableBinding)leftHandBinding;
                if (assignedVariableBinding.isField() && typeCheckElimination.getTypeField().resolveBinding().isEqualTo(assignedVariableBinding)) {
                  if (modify && !nodeExistsInsideTypeCheckCodeFragment(assignment)) {
                    MethodInvocation setterMethodInvocation=contextAST.newMethodInvocation();
                    if (typeCheckElimination.getTypeFieldSetterMethod() != null) {
                      sourceRewriter.set(setterMethodInvocation,MethodInvocation.NAME_PROPERTY,typeCheckElimination.getTypeFieldSetterMethod().getName(),null);
                    }
 else {
                      sourceRewriter.set(setterMethodInvocation,MethodInvocation.NAME_PROPERTY,contextAST.newSimpleName(setterMethodName()),null);
                    }
                    ListRewrite setterMethodInvocationArgumentsRewrite=sourceRewriter.getListRewrite(setterMethodInvocation,MethodInvocation.ARGUMENTS_PROPERTY);
                    setterMethodInvocationArgumentsRewrite.insertLast(assignment.getRightHandSide(),null);
                    if (invoker != null) {
                      sourceRewriter.set(setterMethodInvocation,MethodInvocation.EXPRESSION_PROPERTY,invoker,null);
                    }
                    sourceRewriter.replace(assignment,setterMethodInvocation,null);
                    rewriteAST=true;
                  }
                  for (                  Expression expression2 : accessedVariables) {
                    SimpleName accessedVariable=(SimpleName)expression2;
                    IBinding rightHandBinding=accessedVariable.resolveBinding();
                    if (rightHandBinding != null && rightHandBinding.getKind() == IBinding.VARIABLE) {
                      IVariableBinding accessedVariableBinding=(IVariableBinding)rightHandBinding;
                      if (accessedVariableBinding.isField() && (accessedVariableBinding.getModifiers() & Modifier.STATIC) != 0 && !containsVariable(staticFields,accessedVariable) && accessedVariableBinding.getType().isEqualTo(assignedVariableBinding.getType())) {
                        if (!containsStaticFieldKey(accessedVariable) && !modify)                         additionalStaticFieldMap.put(accessedVariable,generateSubclassName(accessedVariable));
                      }
                    }
                  }
                }
              }
            }
            for (            Expression expression2 : accessedVariables) {
              SimpleName accessedVariable=(SimpleName)expression2;
              IBinding rightHandBinding=accessedVariable.resolveBinding();
              if (rightHandBinding != null && rightHandBinding.getKind() == IBinding.VARIABLE) {
                IVariableBinding accessedVariableBinding=(IVariableBinding)rightHandBinding;
                if (accessedVariableBinding.isField() && typeCheckElimination.getTypeField().resolveBinding().isEqualTo(accessedVariableBinding)) {
                  if (modify && !nodeExistsInsideTypeCheckCodeFragment(accessedVariable)) {
                    MethodInvocation getterMethodInvocation=contextAST.newMethodInvocation();
                    if (typeCheckElimination.getTypeFieldGetterMethod() != null) {
                      sourceRewriter.set(getterMethodInvocation,MethodInvocation.NAME_PROPERTY,typeCheckElimination.getTypeFieldGetterMethod().getName(),null);
                    }
 else {
                      sourceRewriter.set(getterMethodInvocation,MethodInvocation.NAME_PROPERTY,contextAST.newSimpleName("String_Node_Str" + abstractClassName),null);
                    }
                    sourceRewriter.replace(accessedVariable,getterMethodInvocation,null);
                    rewriteAST=true;
                  }
                }
              }
            }
            if (rewriteAST) {
              try {
                TextEdit sourceEdit=sourceRewriter.rewriteAST();
                ICompilationUnit sourceICompilationUnit=(ICompilationUnit)sourceCompilationUnit.getJavaElement();
                CompilationUnitChange change=compilationUnitChanges.get(sourceICompilationUnit);
                change.getEdit().addChild(sourceEdit);
                change.addTextEditGroup(new TextEditGroup("String_Node_Str",new TextEdit[]{sourceEdit}));
              }
 catch (              JavaModelException e) {
                e.printStackTrace();
              }
            }
          }
        }
      }
    }
  }
}