Program: 12065
Project: 12065
Buggy source:
private void findLocallyAccessedFields(PDG pdg,Set<PDGNode> mappedNodes,ITypeBinding commonSuperclass,Set<AbstractVariable> directlyAccessedFields,Set<AbstractVariable> indirectlyAccessedFields,Set<MethodObject> accessedMethods,List<AbstractExpression> expressionsInDifferences,List<AbstractExpression> fieldAccessReplacedWithGetterExpressions){
  Set<MethodInvocationObject> methodInvocationsToBeExcluded=new LinkedHashSet<MethodInvocationObject>();
  for (  AbstractExpression expression : expressionsInDifferences) {
    methodInvocationsToBeExcluded.addAll(expression.getInvokedMethodsThroughThisReference());
    methodInvocationsToBeExcluded.addAll(expression.getInvokedStaticMethods());
  }
  Set<AbstractVariable> fieldsWithGetterToBeIncluded=new LinkedHashSet<AbstractVariable>();
  for (  AbstractExpression expression : fieldAccessReplacedWithGetterExpressions) {
    fieldsWithGetterToBeIncluded.addAll(expression.getUsedFieldsThroughThisReference());
  }
  Set<PlainVariable> usedLocalFields=new LinkedHashSet<PlainVariable>();
  Set<MethodInvocationObject> accessedLocalMethods=new LinkedHashSet<MethodInvocationObject>();
  for (  PDGNode pdgNode : mappedNodes) {
    AbstractStatement abstractStatement=pdgNode.getStatement();
    if (abstractStatement instanceof StatementObject) {
      StatementObject statement=(StatementObject)abstractStatement;
      usedLocalFields.addAll(statement.getUsedFieldsThroughThisReference());
      accessedLocalMethods.addAll(statement.getInvokedMethodsThroughThisReference());
      accessedLocalMethods.addAll(statement.getInvokedStaticMethods());
    }
 else     if (abstractStatement instanceof CompositeStatementObject) {
      CompositeStatementObject composite=(CompositeStatementObject)abstractStatement;
      usedLocalFields.addAll(composite.getUsedFieldsThroughThisReferenceInExpressions());
      accessedLocalMethods.addAll(composite.getInvokedMethodsThroughThisReferenceInExpressions());
      accessedLocalMethods.addAll(composite.getInvokedStaticMethodsInExpressions());
      if (composite instanceof TryStatementObject) {
        TryStatementObject tryStatement=(TryStatementObject)composite;
        List<CatchClauseObject> catchClauses=tryStatement.getCatchClauses();
        for (        CatchClauseObject catchClause : catchClauses) {
          usedLocalFields.addAll(catchClause.getBody().getUsedFieldsThroughThisReference());
          accessedLocalMethods.addAll(catchClause.getBody().getInvokedMethodsThroughThisReference());
          accessedLocalMethods.addAll(catchClause.getBody().getInvokedStaticMethods());
        }
        if (tryStatement.getFinallyClause() != null) {
          usedLocalFields.addAll(tryStatement.getFinallyClause().getUsedFieldsThroughThisReference());
          accessedLocalMethods.addAll(tryStatement.getFinallyClause().getInvokedMethodsThroughThisReference());
          accessedLocalMethods.addAll(tryStatement.getFinallyClause().getInvokedStaticMethods());
        }
      }
    }
  }
  ITypeBinding declaringClassTypeBinding=pdg.getMethod().getMethodDeclaration().resolveBinding().getDeclaringClass();
  Set<VariableDeclaration> fieldsAccessedInMethod=pdg.getFieldsAccessedInMethod();
  for (  PlainVariable variable : usedLocalFields) {
    for (    VariableDeclaration fieldDeclaration : fieldsAccessedInMethod) {
      if (variable.getVariableBindingKey().equals(fieldDeclaration.resolveBinding().getKey())) {
        ITypeBinding fieldDeclaringClassTypeBinding=fieldDeclaration.resolveBinding().getDeclaringClass();
        Set<ITypeBinding> superTypes=getAllSuperTypesUpToCommonSuperclass(declaringClassTypeBinding,commonSuperclass);
        boolean fieldFoundInSuperType=false;
        for (        ITypeBinding typeBinding : superTypes) {
          if (typeBinding.isEqualTo(fieldDeclaringClassTypeBinding)) {
            fieldFoundInSuperType=true;
            break;
          }
        }
        if (fieldDeclaringClassTypeBinding.isEqualTo(declaringClassTypeBinding) || fieldFoundInSuperType) {
          directlyAccessedFields.add(variable);
          if (fieldsWithGetterToBeIncluded.contains(variable)) {
            SystemObject system=ASTReader.getSystemObject();
            ClassObject accessedClass=system.getClassObject(fieldDeclaringClassTypeBinding.getQualifiedName());
            if (accessedClass != null) {
              ListIterator<MethodObject> it=accessedClass.getMethodIterator();
              while (it.hasNext()) {
                MethodObject method=it.next();
                FieldInstructionObject getterFieldInstruction=method.isGetter();
                if (getterFieldInstruction != null) {
                  if (variable.getVariableBindingKey().equals(getterFieldInstruction.getSimpleName().resolveBinding().getKey())) {
                    accessedMethods.add(method);
                    break;
                  }
                }
              }
            }
          }
          break;
        }
      }
    }
  }
  for (  MethodInvocationObject invocation : accessedLocalMethods) {
    ITypeBinding invokedMethodDeclaringClassTypeBinding=invocation.getMethodInvocation().resolveMethodBinding().getDeclaringClass();
    Set<ITypeBinding> superTypes=getAllSuperTypesUpToCommonSuperclass(declaringClassTypeBinding,commonSuperclass);
    boolean invokedMethodFoundInSuperType=false;
    for (    ITypeBinding typeBinding : superTypes) {
      if (typeBinding.isEqualTo(invokedMethodDeclaringClassTypeBinding)) {
        invokedMethodFoundInSuperType=true;
        break;
      }
    }
    if ((invokedMethodDeclaringClassTypeBinding.isEqualTo(declaringClassTypeBinding) || invokedMethodFoundInSuperType) && !methodInvocationsToBeExcluded.contains(invocation)) {
      if (!pdg.getMethod().getMethodDeclaration().resolveBinding().isEqualTo(invocation.getMethodInvocation().resolveMethodBinding())) {
        SystemObject system=ASTReader.getSystemObject();
        MethodObject calledMethod=system.getMethod(invocation);
        if (calledMethod != null) {
          accessedMethods.add(calledMethod);
          FieldInstructionObject getterFieldInstruction=calledMethod.isGetter();
          if (getterFieldInstruction != null) {
            Set<PlainVariable> usedFields=calledMethod.getUsedFieldsThroughThisReference();
            for (            PlainVariable plainVariable : usedFields) {
              if (plainVariable.getVariableBindingKey().equals(getterFieldInstruction.getSimpleName().resolveBinding().getKey())) {
                directlyAccessedFields.add(plainVariable);
                break;
              }
            }
          }
          ClassObject calledClass=system.getClassObject(calledMethod.getClassName());
          getAdditionalLocallyAccessedFieldsAndMethods(calledMethod,calledClass,indirectlyAccessedFields,accessedMethods);
        }
      }
    }
  }
}

Fixed version (ground truth):
private void findLocallyAccessedFields(PDG pdg,Set<PDGNode> mappedNodes,ITypeBinding commonSuperclass,Set<AbstractVariable> directlyAccessedFields,Set<AbstractVariable> indirectlyAccessedFields,Set<MethodObject> accessedMethods,List<Expression> expressionsInDifferences,List<AbstractExpression> fieldAccessReplacedWithGetterExpressions){
  Set<MethodInvocation> methodInvocationsToBeExcluded=new LinkedHashSet<MethodInvocation>();
  for (  Expression expression : expressionsInDifferences) {
    if (expression instanceof MethodInvocation) {
      methodInvocationsToBeExcluded.add((MethodInvocation)expression);
    }
  }
  Set<AbstractVariable> fieldsWithGetterToBeIncluded=new LinkedHashSet<AbstractVariable>();
  for (  AbstractExpression expression : fieldAccessReplacedWithGetterExpressions) {
    fieldsWithGetterToBeIncluded.addAll(expression.getUsedFieldsThroughThisReference());
  }
  Set<PlainVariable> usedLocalFields=new LinkedHashSet<PlainVariable>();
  Set<MethodInvocationObject> accessedLocalMethods=new LinkedHashSet<MethodInvocationObject>();
  for (  PDGNode pdgNode : mappedNodes) {
    AbstractStatement abstractStatement=pdgNode.getStatement();
    if (abstractStatement instanceof StatementObject) {
      StatementObject statement=(StatementObject)abstractStatement;
      usedLocalFields.addAll(statement.getUsedFieldsThroughThisReference());
      accessedLocalMethods.addAll(statement.getInvokedMethodsThroughThisReference());
      accessedLocalMethods.addAll(statement.getInvokedStaticMethods());
    }
 else     if (abstractStatement instanceof CompositeStatementObject) {
      CompositeStatementObject composite=(CompositeStatementObject)abstractStatement;
      usedLocalFields.addAll(composite.getUsedFieldsThroughThisReferenceInExpressions());
      accessedLocalMethods.addAll(composite.getInvokedMethodsThroughThisReferenceInExpressions());
      accessedLocalMethods.addAll(composite.getInvokedStaticMethodsInExpressions());
      if (composite instanceof TryStatementObject) {
        TryStatementObject tryStatement=(TryStatementObject)composite;
        List<CatchClauseObject> catchClauses=tryStatement.getCatchClauses();
        for (        CatchClauseObject catchClause : catchClauses) {
          usedLocalFields.addAll(catchClause.getBody().getUsedFieldsThroughThisReference());
          accessedLocalMethods.addAll(catchClause.getBody().getInvokedMethodsThroughThisReference());
          accessedLocalMethods.addAll(catchClause.getBody().getInvokedStaticMethods());
        }
        if (tryStatement.getFinallyClause() != null) {
          usedLocalFields.addAll(tryStatement.getFinallyClause().getUsedFieldsThroughThisReference());
          accessedLocalMethods.addAll(tryStatement.getFinallyClause().getInvokedMethodsThroughThisReference());
          accessedLocalMethods.addAll(tryStatement.getFinallyClause().getInvokedStaticMethods());
        }
      }
    }
  }
  ITypeBinding declaringClassTypeBinding=pdg.getMethod().getMethodDeclaration().resolveBinding().getDeclaringClass();
  Set<VariableDeclaration> fieldsAccessedInMethod=pdg.getFieldsAccessedInMethod();
  for (  PlainVariable variable : usedLocalFields) {
    for (    VariableDeclaration fieldDeclaration : fieldsAccessedInMethod) {
      if (variable.getVariableBindingKey().equals(fieldDeclaration.resolveBinding().getKey())) {
        ITypeBinding fieldDeclaringClassTypeBinding=fieldDeclaration.resolveBinding().getDeclaringClass();
        Set<ITypeBinding> superTypes=getAllSuperTypesUpToCommonSuperclass(declaringClassTypeBinding,commonSuperclass);
        boolean fieldFoundInSuperType=false;
        for (        ITypeBinding typeBinding : superTypes) {
          if (typeBinding.isEqualTo(fieldDeclaringClassTypeBinding)) {
            fieldFoundInSuperType=true;
            break;
          }
        }
        if (fieldDeclaringClassTypeBinding.isEqualTo(declaringClassTypeBinding) || fieldFoundInSuperType) {
          directlyAccessedFields.add(variable);
          if (fieldsWithGetterToBeIncluded.contains(variable)) {
            SystemObject system=ASTReader.getSystemObject();
            ClassObject accessedClass=system.getClassObject(fieldDeclaringClassTypeBinding.getQualifiedName());
            if (accessedClass != null) {
              ListIterator<MethodObject> it=accessedClass.getMethodIterator();
              while (it.hasNext()) {
                MethodObject method=it.next();
                FieldInstructionObject getterFieldInstruction=method.isGetter();
                if (getterFieldInstruction != null) {
                  if (variable.getVariableBindingKey().equals(getterFieldInstruction.getSimpleName().resolveBinding().getKey())) {
                    accessedMethods.add(method);
                    break;
                  }
                }
              }
            }
          }
          break;
        }
      }
    }
  }
  for (  MethodInvocationObject invocation : accessedLocalMethods) {
    ITypeBinding invokedMethodDeclaringClassTypeBinding=invocation.getMethodInvocation().resolveMethodBinding().getDeclaringClass();
    Set<ITypeBinding> superTypes=getAllSuperTypesUpToCommonSuperclass(declaringClassTypeBinding,commonSuperclass);
    boolean invokedMethodFoundInSuperType=false;
    for (    ITypeBinding typeBinding : superTypes) {
      if (typeBinding.isEqualTo(invokedMethodDeclaringClassTypeBinding)) {
        invokedMethodFoundInSuperType=true;
        break;
      }
    }
    if ((invokedMethodDeclaringClassTypeBinding.isEqualTo(declaringClassTypeBinding) || invokedMethodFoundInSuperType) && !methodInvocationsToBeExcluded.contains(invocation.getMethodInvocation())) {
      if (!pdg.getMethod().getMethodDeclaration().resolveBinding().isEqualTo(invocation.getMethodInvocation().resolveMethodBinding())) {
        SystemObject system=ASTReader.getSystemObject();
        MethodObject calledMethod=system.getMethod(invocation);
        if (calledMethod != null) {
          accessedMethods.add(calledMethod);
          FieldInstructionObject getterFieldInstruction=calledMethod.isGetter();
          if (getterFieldInstruction != null) {
            Set<PlainVariable> usedFields=calledMethod.getUsedFieldsThroughThisReference();
            for (            PlainVariable plainVariable : usedFields) {
              if (plainVariable.getVariableBindingKey().equals(getterFieldInstruction.getSimpleName().resolveBinding().getKey())) {
                directlyAccessedFields.add(plainVariable);
                break;
              }
            }
          }
          ClassObject calledClass=system.getClassObject(calledMethod.getClassName());
          getAdditionalLocallyAccessedFieldsAndMethods(calledMethod,calledClass,indirectlyAccessedFields,accessedMethods);
        }
      }
    }
  }
}