Program: 12126
Project: 12126
Buggy source:
public TypeCheckEliminationResults generateTypeCheckEliminations(){
  TypeCheckEliminationResults typeCheckEliminationResults=new TypeCheckEliminationResults();
  Map<TypeCheckElimination,List<SimpleName>> staticFieldMap=new LinkedHashMap<TypeCheckElimination,List<SimpleName>>();
  Map<Integer,ArrayList<TypeCheckElimination>> staticFieldRankMap=new TreeMap<Integer,ArrayList<TypeCheckElimination>>();
  Map<String,ArrayList<TypeCheckElimination>> inheritanceTreeMap=new LinkedHashMap<String,ArrayList<TypeCheckElimination>>();
  CompleteInheritanceDetection inheritanceDetection=new CompleteInheritanceDetection(this);
  for (  ClassObject classObject : classList) {
    List<TypeCheckElimination> eliminations=classObject.generateTypeCheckEliminations();
    for (    TypeCheckElimination elimination : eliminations) {
      List<SimpleName> staticFields=elimination.getStaticFields();
      if (!staticFields.isEmpty()) {
        if (allStaticFieldsWithinSystemBoundary(staticFields)) {
          inheritanceHierarchyMatchingWithStaticTypes(elimination,inheritanceDetection);
          boolean isValid=false;
          if (elimination.getTypeField() != null) {
            IVariableBinding typeFieldBinding=elimination.getTypeField().resolveBinding();
            ITypeBinding typeFieldTypeBinding=typeFieldBinding.getType();
            if (typeFieldTypeBinding.isPrimitive() || typeFieldTypeBinding.isEnum()) {
              isValid=true;
            }
          }
 else           if (elimination.getTypeLocalVariable() != null) {
            IVariableBinding typeLocalVariableBinding=elimination.getTypeLocalVariable().resolveBinding();
            ITypeBinding typeLocalVariableTypeBinding=typeLocalVariableBinding.getType();
            if (typeLocalVariableTypeBinding.isPrimitive() || typeLocalVariableTypeBinding.isEnum()) {
              isValid=true;
            }
          }
 else           if (elimination.getTypeMethodInvocation() != null) {
            MethodInvocation typeMethodInvocation=elimination.getTypeMethodInvocation();
            IMethodBinding typeMethodInvocationBinding=typeMethodInvocation.resolveMethodBinding();
            ITypeBinding typeMethodInvocationDeclaringClass=typeMethodInvocationBinding.getDeclaringClass();
            ITypeBinding typeMethodInvocationReturnType=typeMethodInvocationBinding.getReturnType();
            ClassObject declaringClassObject=getClassObject(typeMethodInvocationDeclaringClass.getQualifiedName());
            if ((typeMethodInvocationReturnType.isPrimitive() || typeMethodInvocationReturnType.isEnum()) && declaringClassObject != null) {
              MethodDeclaration invokedMethodDeclaration=null;
              ListIterator<MethodObject> methodIterator=declaringClassObject.getMethodIterator();
              while (methodIterator.hasNext()) {
                MethodObject methodObject=methodIterator.next();
                MethodDeclaration methodDeclaration=methodObject.getMethodDeclaration();
                if (typeMethodInvocationBinding.isEqualTo(methodDeclaration.resolveBinding())) {
                  invokedMethodDeclaration=methodDeclaration;
                  break;
                }
              }
              SimpleName fieldInstruction=MethodDeclarationUtility.isGetter(invokedMethodDeclaration);
              if (fieldInstruction != null) {
                ListIterator<FieldObject> fieldIterator=declaringClassObject.getFieldIterator();
                while (fieldIterator.hasNext()) {
                  FieldObject fieldObject=fieldIterator.next();
                  VariableDeclarationFragment fragment=fieldObject.getVariableDeclarationFragment();
                  if (fieldInstruction.resolveBinding().isEqualTo(fragment.resolveBinding())) {
                    elimination.setForeignTypeField(fragment);
                    break;
                  }
                }
                isValid=true;
              }
 else               if (invokedMethodDeclaration.getBody() == null) {
                InheritanceTree tree=elimination.getInheritanceTreeMatchingWithStaticTypes();
                ITypeBinding invokerTypeBinding=handleTypeMethodInvocation(typeMethodInvocation,elimination);
                if (invokerTypeBinding != null) {
                  if (tree != null) {
                    if (invokerTypeBinding.getQualifiedName().equals(tree.getRootNode().getUserObject())) {
                      elimination.setExistingInheritanceTree(tree);
                      if (inheritanceTreeMap.containsKey(tree.getRootNode().getUserObject())) {
                        ArrayList<TypeCheckElimination> typeCheckEliminations=inheritanceTreeMap.get(tree.getRootNode().getUserObject());
                        typeCheckEliminations.add(elimination);
                      }
 else {
                        ArrayList<TypeCheckElimination> typeCheckEliminations=new ArrayList<TypeCheckElimination>();
                        typeCheckEliminations.add(elimination);
                        inheritanceTreeMap.put((String)tree.getRootNode().getUserObject(),typeCheckEliminations);
                      }
                    }
                  }
 else {
                    InheritanceTree tree2=inheritanceDetection.getTree(invokerTypeBinding.getQualifiedName());
                    if (tree2 != null) {
                      elimination.setExistingInheritanceTree(tree2);
                      if (inheritanceTreeMap.containsKey(tree2.getRootNode().getUserObject())) {
                        ArrayList<TypeCheckElimination> typeCheckEliminations=inheritanceTreeMap.get(tree2.getRootNode().getUserObject());
                        typeCheckEliminations.add(elimination);
                      }
 else {
                        ArrayList<TypeCheckElimination> typeCheckEliminations=new ArrayList<TypeCheckElimination>();
                        typeCheckEliminations.add(elimination);
                        inheritanceTreeMap.put((String)tree2.getRootNode().getUserObject(),typeCheckEliminations);
                      }
                    }
                  }
                }
              }
            }
          }
          if (isValid) {
            staticFieldMap.put(elimination,staticFields);
            int size=staticFields.size();
            if (staticFieldRankMap.containsKey(size)) {
              ArrayList<TypeCheckElimination> rank=staticFieldRankMap.get(size);
              rank.add(elimination);
            }
 else {
              ArrayList<TypeCheckElimination> rank=new ArrayList<TypeCheckElimination>();
              rank.add(elimination);
              staticFieldRankMap.put(size,rank);
            }
          }
        }
      }
 else {
        if (elimination.getTypeField() != null) {
          IVariableBinding typeFieldBinding=elimination.getTypeField().resolveBinding();
          ITypeBinding typeFieldTypeBinding=typeFieldBinding.getType();
          InheritanceTree tree=inheritanceDetection.getTree(typeFieldTypeBinding.getQualifiedName());
          elimination.setExistingInheritanceTree(tree);
        }
 else         if (elimination.getTypeLocalVariable() != null) {
          IVariableBinding typeLocalVariableBinding=elimination.getTypeLocalVariable().resolveBinding();
          ITypeBinding typeLocalVariableTypeBinding=typeLocalVariableBinding.getType();
          InheritanceTree tree=inheritanceDetection.getTree(typeLocalVariableTypeBinding.getQualifiedName());
          elimination.setExistingInheritanceTree(tree);
        }
 else         if (elimination.getTypeMethodInvocation() != null) {
          MethodInvocation typeMethodInvocation=elimination.getTypeMethodInvocation();
          IMethodBinding typeMethodInvocationBinding=typeMethodInvocation.resolveMethodBinding();
          if (typeMethodInvocationBinding.getDeclaringClass().getQualifiedName().equals("String_Node_Str") && typeMethodInvocationBinding.getName().equals("String_Node_Str")) {
            ITypeBinding invokerTypeBinding=handleTypeMethodInvocation(typeMethodInvocation,elimination);
            if (invokerTypeBinding != null) {
              InheritanceTree tree=inheritanceDetection.getTree(invokerTypeBinding.getQualifiedName());
              elimination.setExistingInheritanceTree(tree);
            }
          }
 else {
            ITypeBinding typeMethodInvocationReturnType=typeMethodInvocationBinding.getReturnType();
            InheritanceTree tree=inheritanceDetection.getTree(typeMethodInvocationReturnType.getQualifiedName());
            elimination.setExistingInheritanceTree(tree);
          }
        }
        if (elimination.getExistingInheritanceTree() != null) {
          InheritanceTree tree=elimination.getExistingInheritanceTree();
          if (inheritanceTreeMap.containsKey(tree.getRootNode().getUserObject())) {
            ArrayList<TypeCheckElimination> typeCheckEliminations=inheritanceTreeMap.get(tree.getRootNode().getUserObject());
            typeCheckEliminations.add(elimination);
          }
 else {
            ArrayList<TypeCheckElimination> typeCheckEliminations=new ArrayList<TypeCheckElimination>();
            typeCheckEliminations.add(elimination);
            inheritanceTreeMap.put((String)tree.getRootNode().getUserObject(),typeCheckEliminations);
          }
        }
      }
    }
  }
  for (  String rootNode : inheritanceTreeMap.keySet()) {
    ArrayList<TypeCheckElimination> typeCheckEliminations=inheritanceTreeMap.get(rootNode);
    typeCheckEliminationResults.addGroup(typeCheckEliminations);
  }
  List<TypeCheckElimination> sortedEliminations=new ArrayList<TypeCheckElimination>();
  List<Integer> keyList=new ArrayList<Integer>(staticFieldRankMap.keySet());
  ListIterator<Integer> keyListIterator=keyList.listIterator(keyList.size());
  while (keyListIterator.hasPrevious()) {
    Integer states=keyListIterator.previous();
    sortedEliminations.addAll(staticFieldRankMap.get(states));
  }
  while (!sortedEliminations.isEmpty()) {
    TypeCheckElimination selectedElimination=sortedEliminations.get(0);
    List<TypeCheckElimination> affectedEliminations=new ArrayList<TypeCheckElimination>();
    affectedEliminations.add(selectedElimination);
    List<SimpleName> staticFieldUnion=staticFieldMap.get(selectedElimination);
    boolean staticFieldUnionIncreased=true;
    while (staticFieldUnionIncreased) {
      staticFieldUnionIncreased=false;
      for (      TypeCheckElimination elimination : sortedEliminations) {
        List<SimpleName> staticFields=staticFieldMap.get(elimination);
        if (!affectedEliminations.contains(elimination) && nonEmptyIntersection(staticFieldUnion,staticFields)) {
          staticFieldUnion=constructUnion(staticFieldUnion,staticFields);
          affectedEliminations.add(elimination);
          staticFieldUnionIncreased=true;
        }
      }
    }
    if (affectedEliminations.size() > 1) {
      for (      TypeCheckElimination elimination : affectedEliminations) {
        List<SimpleName> staticFields=staticFieldMap.get(elimination);
        for (        SimpleName simpleName1 : staticFieldUnion) {
          boolean isContained=false;
          for (          SimpleName simpleName2 : staticFields) {
            if (simpleName1.resolveBinding().isEqualTo(simpleName2.resolveBinding())) {
              isContained=true;
              break;
            }
          }
          if (!isContained)           elimination.addAdditionalStaticField(simpleName1);
        }
      }
    }
    ArrayList<TypeCheckElimination> typeCheckEliminations=new ArrayList<TypeCheckElimination>();
    for (    TypeCheckElimination elimination : affectedEliminations) {
      if (!elimination.isTypeCheckMethodStateSetter())       typeCheckEliminations.add(elimination);
    }
    typeCheckEliminationResults.addGroup(typeCheckEliminations);
    sortedEliminations.removeAll(affectedEliminations);
  }
  identifySuperFieldAccessorMethods(typeCheckEliminationResults.getTypeCheckEliminations());
  return typeCheckEliminationResults;
}

Fixed version (ground truth):
public TypeCheckEliminationResults generateTypeCheckEliminations(IProgressMonitor monitor){
  monitor.beginTask("String_Node_Str",classList.size());
  TypeCheckEliminationResults typeCheckEliminationResults=new TypeCheckEliminationResults();
  Map<TypeCheckElimination,List<SimpleName>> staticFieldMap=new LinkedHashMap<TypeCheckElimination,List<SimpleName>>();
  Map<Integer,ArrayList<TypeCheckElimination>> staticFieldRankMap=new TreeMap<Integer,ArrayList<TypeCheckElimination>>();
  Map<String,ArrayList<TypeCheckElimination>> inheritanceTreeMap=new LinkedHashMap<String,ArrayList<TypeCheckElimination>>();
  CompleteInheritanceDetection inheritanceDetection=new CompleteInheritanceDetection(this);
  for (  ClassObject classObject : classList) {
    List<TypeCheckElimination> eliminations=classObject.generateTypeCheckEliminations();
    for (    TypeCheckElimination elimination : eliminations) {
      List<SimpleName> staticFields=elimination.getStaticFields();
      if (!staticFields.isEmpty()) {
        if (allStaticFieldsWithinSystemBoundary(staticFields)) {
          inheritanceHierarchyMatchingWithStaticTypes(elimination,inheritanceDetection);
          boolean isValid=false;
          if (elimination.getTypeField() != null) {
            IVariableBinding typeFieldBinding=elimination.getTypeField().resolveBinding();
            ITypeBinding typeFieldTypeBinding=typeFieldBinding.getType();
            if (typeFieldTypeBinding.isPrimitive() || typeFieldTypeBinding.isEnum()) {
              isValid=true;
            }
          }
 else           if (elimination.getTypeLocalVariable() != null) {
            IVariableBinding typeLocalVariableBinding=elimination.getTypeLocalVariable().resolveBinding();
            ITypeBinding typeLocalVariableTypeBinding=typeLocalVariableBinding.getType();
            if (typeLocalVariableTypeBinding.isPrimitive() || typeLocalVariableTypeBinding.isEnum()) {
              isValid=true;
            }
          }
 else           if (elimination.getTypeMethodInvocation() != null) {
            MethodInvocation typeMethodInvocation=elimination.getTypeMethodInvocation();
            IMethodBinding typeMethodInvocationBinding=typeMethodInvocation.resolveMethodBinding();
            ITypeBinding typeMethodInvocationDeclaringClass=typeMethodInvocationBinding.getDeclaringClass();
            ITypeBinding typeMethodInvocationReturnType=typeMethodInvocationBinding.getReturnType();
            ClassObject declaringClassObject=getClassObject(typeMethodInvocationDeclaringClass.getQualifiedName());
            if ((typeMethodInvocationReturnType.isPrimitive() || typeMethodInvocationReturnType.isEnum()) && declaringClassObject != null) {
              MethodDeclaration invokedMethodDeclaration=null;
              ListIterator<MethodObject> methodIterator=declaringClassObject.getMethodIterator();
              while (methodIterator.hasNext()) {
                MethodObject methodObject=methodIterator.next();
                MethodDeclaration methodDeclaration=methodObject.getMethodDeclaration();
                if (typeMethodInvocationBinding.isEqualTo(methodDeclaration.resolveBinding())) {
                  invokedMethodDeclaration=methodDeclaration;
                  break;
                }
              }
              SimpleName fieldInstruction=MethodDeclarationUtility.isGetter(invokedMethodDeclaration);
              if (fieldInstruction != null) {
                ListIterator<FieldObject> fieldIterator=declaringClassObject.getFieldIterator();
                while (fieldIterator.hasNext()) {
                  FieldObject fieldObject=fieldIterator.next();
                  VariableDeclarationFragment fragment=fieldObject.getVariableDeclarationFragment();
                  if (fieldInstruction.resolveBinding().isEqualTo(fragment.resolveBinding())) {
                    elimination.setForeignTypeField(fragment);
                    break;
                  }
                }
                isValid=true;
              }
 else               if (invokedMethodDeclaration.getBody() == null) {
                InheritanceTree tree=elimination.getInheritanceTreeMatchingWithStaticTypes();
                ITypeBinding invokerTypeBinding=handleTypeMethodInvocation(typeMethodInvocation,elimination);
                if (invokerTypeBinding != null) {
                  if (tree != null) {
                    if (invokerTypeBinding.getQualifiedName().equals(tree.getRootNode().getUserObject())) {
                      elimination.setExistingInheritanceTree(tree);
                      if (inheritanceTreeMap.containsKey(tree.getRootNode().getUserObject())) {
                        ArrayList<TypeCheckElimination> typeCheckEliminations=inheritanceTreeMap.get(tree.getRootNode().getUserObject());
                        typeCheckEliminations.add(elimination);
                      }
 else {
                        ArrayList<TypeCheckElimination> typeCheckEliminations=new ArrayList<TypeCheckElimination>();
                        typeCheckEliminations.add(elimination);
                        inheritanceTreeMap.put((String)tree.getRootNode().getUserObject(),typeCheckEliminations);
                      }
                    }
                  }
 else {
                    InheritanceTree tree2=inheritanceDetection.getTree(invokerTypeBinding.getQualifiedName());
                    if (tree2 != null) {
                      elimination.setExistingInheritanceTree(tree2);
                      if (inheritanceTreeMap.containsKey(tree2.getRootNode().getUserObject())) {
                        ArrayList<TypeCheckElimination> typeCheckEliminations=inheritanceTreeMap.get(tree2.getRootNode().getUserObject());
                        typeCheckEliminations.add(elimination);
                      }
 else {
                        ArrayList<TypeCheckElimination> typeCheckEliminations=new ArrayList<TypeCheckElimination>();
                        typeCheckEliminations.add(elimination);
                        inheritanceTreeMap.put((String)tree2.getRootNode().getUserObject(),typeCheckEliminations);
                      }
                    }
                  }
                }
              }
            }
          }
          if (isValid) {
            staticFieldMap.put(elimination,staticFields);
            int size=staticFields.size();
            if (staticFieldRankMap.containsKey(size)) {
              ArrayList<TypeCheckElimination> rank=staticFieldRankMap.get(size);
              rank.add(elimination);
            }
 else {
              ArrayList<TypeCheckElimination> rank=new ArrayList<TypeCheckElimination>();
              rank.add(elimination);
              staticFieldRankMap.put(size,rank);
            }
          }
        }
      }
 else {
        if (elimination.getTypeField() != null) {
          IVariableBinding typeFieldBinding=elimination.getTypeField().resolveBinding();
          ITypeBinding typeFieldTypeBinding=typeFieldBinding.getType();
          InheritanceTree tree=inheritanceDetection.getTree(typeFieldTypeBinding.getQualifiedName());
          elimination.setExistingInheritanceTree(tree);
        }
 else         if (elimination.getTypeLocalVariable() != null) {
          IVariableBinding typeLocalVariableBinding=elimination.getTypeLocalVariable().resolveBinding();
          ITypeBinding typeLocalVariableTypeBinding=typeLocalVariableBinding.getType();
          InheritanceTree tree=inheritanceDetection.getTree(typeLocalVariableTypeBinding.getQualifiedName());
          elimination.setExistingInheritanceTree(tree);
        }
 else         if (elimination.getTypeMethodInvocation() != null) {
          MethodInvocation typeMethodInvocation=elimination.getTypeMethodInvocation();
          IMethodBinding typeMethodInvocationBinding=typeMethodInvocation.resolveMethodBinding();
          if (typeMethodInvocationBinding.getDeclaringClass().getQualifiedName().equals("String_Node_Str") && typeMethodInvocationBinding.getName().equals("String_Node_Str")) {
            ITypeBinding invokerTypeBinding=handleTypeMethodInvocation(typeMethodInvocation,elimination);
            if (invokerTypeBinding != null) {
              InheritanceTree tree=inheritanceDetection.getTree(invokerTypeBinding.getQualifiedName());
              elimination.setExistingInheritanceTree(tree);
            }
          }
 else {
            ITypeBinding typeMethodInvocationReturnType=typeMethodInvocationBinding.getReturnType();
            InheritanceTree tree=inheritanceDetection.getTree(typeMethodInvocationReturnType.getQualifiedName());
            elimination.setExistingInheritanceTree(tree);
          }
        }
        if (elimination.getExistingInheritanceTree() != null) {
          InheritanceTree tree=elimination.getExistingInheritanceTree();
          if (inheritanceTreeMap.containsKey(tree.getRootNode().getUserObject())) {
            ArrayList<TypeCheckElimination> typeCheckEliminations=inheritanceTreeMap.get(tree.getRootNode().getUserObject());
            typeCheckEliminations.add(elimination);
          }
 else {
            ArrayList<TypeCheckElimination> typeCheckEliminations=new ArrayList<TypeCheckElimination>();
            typeCheckEliminations.add(elimination);
            inheritanceTreeMap.put((String)tree.getRootNode().getUserObject(),typeCheckEliminations);
          }
        }
      }
    }
    monitor.worked(1);
  }
  for (  String rootNode : inheritanceTreeMap.keySet()) {
    ArrayList<TypeCheckElimination> typeCheckEliminations=inheritanceTreeMap.get(rootNode);
    typeCheckEliminationResults.addGroup(typeCheckEliminations);
  }
  List<TypeCheckElimination> sortedEliminations=new ArrayList<TypeCheckElimination>();
  List<Integer> keyList=new ArrayList<Integer>(staticFieldRankMap.keySet());
  ListIterator<Integer> keyListIterator=keyList.listIterator(keyList.size());
  while (keyListIterator.hasPrevious()) {
    Integer states=keyListIterator.previous();
    sortedEliminations.addAll(staticFieldRankMap.get(states));
  }
  while (!sortedEliminations.isEmpty()) {
    TypeCheckElimination selectedElimination=sortedEliminations.get(0);
    List<TypeCheckElimination> affectedEliminations=new ArrayList<TypeCheckElimination>();
    affectedEliminations.add(selectedElimination);
    List<SimpleName> staticFieldUnion=staticFieldMap.get(selectedElimination);
    boolean staticFieldUnionIncreased=true;
    while (staticFieldUnionIncreased) {
      staticFieldUnionIncreased=false;
      for (      TypeCheckElimination elimination : sortedEliminations) {
        List<SimpleName> staticFields=staticFieldMap.get(elimination);
        if (!affectedEliminations.contains(elimination) && nonEmptyIntersection(staticFieldUnion,staticFields)) {
          staticFieldUnion=constructUnion(staticFieldUnion,staticFields);
          affectedEliminations.add(elimination);
          staticFieldUnionIncreased=true;
        }
      }
    }
    if (affectedEliminations.size() > 1) {
      for (      TypeCheckElimination elimination : affectedEliminations) {
        List<SimpleName> staticFields=staticFieldMap.get(elimination);
        for (        SimpleName simpleName1 : staticFieldUnion) {
          boolean isContained=false;
          for (          SimpleName simpleName2 : staticFields) {
            if (simpleName1.resolveBinding().isEqualTo(simpleName2.resolveBinding())) {
              isContained=true;
              break;
            }
          }
          if (!isContained)           elimination.addAdditionalStaticField(simpleName1);
        }
      }
    }
    ArrayList<TypeCheckElimination> typeCheckEliminations=new ArrayList<TypeCheckElimination>();
    for (    TypeCheckElimination elimination : affectedEliminations) {
      if (!elimination.isTypeCheckMethodStateSetter())       typeCheckEliminations.add(elimination);
    }
    typeCheckEliminationResults.addGroup(typeCheckEliminations);
    sortedEliminations.removeAll(affectedEliminations);
  }
  identifySuperFieldAccessorMethods(typeCheckEliminationResults.getTypeCheckEliminations());
  monitor.done();
  return typeCheckEliminationResults;
}