Program: 12271
Project: 12271
Buggy source:
public List<ExtractAndMoveMethodCandidateRefactoring> getExtractAndMoveMethodCandidateRefactorings(){
  List<ExtractAndMoveMethodCandidateRefactoring> extractMethodCandidateRefactoringList=new ArrayList<ExtractAndMoveMethodCandidateRefactoring>();
  Set<String> extractedMethodNames=new LinkedHashSet<String>();
  Iterator<MyClass> classIt=system.getClassIterator();
  while (classIt.hasNext()) {
    MyClass myClass=classIt.next();
    ListIterator<MyMethod> methodIterator=myClass.getMethodIterator();
    while (methodIterator.hasNext()) {
      MyMethod method=methodIterator.next();
      if (method.getMethodObject().getMethodBody() != null) {
        List<ExtractionBlock> extractionBlockList=method.getMethodObject().getMethodBody().generateExtractionBlocks();
        for (        ExtractionBlock block : extractionBlockList) {
          if (extractedMethodNames.contains(block.getExtractedMethodName())) {
            block.setExtractedMethodName(block.getReturnVariableDeclaration().getName() + method.getMethodName().replace(method.getMethodName().charAt(0),Character.toUpperCase(method.getMethodName().charAt(0))));
          }
 else {
            extractedMethodNames.add(block.getExtractedMethodName());
          }
          ExtractAndMoveMethodCandidateRefactoring candidate=new ExtractAndMoveMethodCandidateRefactoring(system,myClass,myClass,method,block);
          extractMethodCandidateRefactoringList.add(candidate);
        }
      }
    }
  }
  Double[][] blockDistanceMatrix=new Double[extractMethodCandidateRefactoringList.size()][classList.size()];
  for (int i=0; i < extractMethodCandidateRefactoringList.size(); i++) {
    ExtractAndMoveMethodCandidateRefactoring candidate=extractMethodCandidateRefactoringList.get(i);
    for (int j=0; j < classList.size(); j++) {
      blockDistanceMatrix[i][j]=DistanceCalculator.getDistance(candidate.getEntitySet(),classMap.get(classNames[j]));
    }
  }
  List<ExtractAndMoveMethodCandidateRefactoring> candidateRefactoringList=new ArrayList<ExtractAndMoveMethodCandidateRefactoring>();
  ;
  Map<Integer,Double> minValueMap=new LinkedHashMap<Integer,Double>();
  for (int i=0; i < blockDistanceMatrix.length; i++) {
    double minValue=1;
    for (int j=0; j < blockDistanceMatrix[i].length; j++) {
      if (blockDistanceMatrix[i][j] < minValue) {
        minValue=blockDistanceMatrix[i][j];
      }
    }
    minValueMap.put(i,minValue);
  }
  for (  Integer i : minValueMap.keySet()) {
    double minValue=minValueMap.get(i);
    ExtractAndMoveMethodCandidateRefactoring candidate=extractMethodCandidateRefactoringList.get(i);
    String rowClass=candidate.getSourceClass().getName();
    if (minValue != 1) {
      for (int j=0; j < blockDistanceMatrix[i].length; j++) {
        if (blockDistanceMatrix[i][j] == minValue) {
          if (!rowClass.equals(classNames[j])) {
            MyClass targetClass=classList.get(j);
            ExtractAndMoveMethodCandidateRefactoring newCandidate=new ExtractAndMoveMethodCandidateRefactoring(system,candidate.getSourceClass(),targetClass,candidate.getSourceMethod(),candidate.getExtractionBlock());
            boolean applicable=newCandidate.apply();
            if (applicable)             candidateRefactoringList.add(newCandidate);
          }
        }
      }
    }
  }
  return candidateRefactoringList;
}

Fixed version (ground truth):
public List<ExtractAndMoveMethodCandidateRefactoring> getExtractAndMoveMethodCandidateRefactorings(){
  List<ExtractAndMoveMethodCandidateRefactoring> extractMethodCandidateRefactoringList=new ArrayList<ExtractAndMoveMethodCandidateRefactoring>();
  Map<String,ArrayList<ExtractAndMoveMethodCandidateRefactoring>> extractedMethodNameMap=new LinkedHashMap<String,ArrayList<ExtractAndMoveMethodCandidateRefactoring>>();
  Iterator<MyClass> classIt=system.getClassIterator();
  while (classIt.hasNext()) {
    MyClass myClass=classIt.next();
    ListIterator<MyMethod> methodIterator=myClass.getMethodIterator();
    while (methodIterator.hasNext()) {
      MyMethod method=methodIterator.next();
      if (method.getMethodObject().getMethodBody() != null) {
        List<ExtractionBlock> extractionBlockList=method.getMethodObject().getMethodBody().generateExtractionBlocks();
        for (        ExtractionBlock block : extractionBlockList) {
          ExtractAndMoveMethodCandidateRefactoring candidate=new ExtractAndMoveMethodCandidateRefactoring(system,myClass,myClass,method,block);
          extractMethodCandidateRefactoringList.add(candidate);
          if (!extractedMethodNameMap.containsKey(block.getExtractedMethodName())) {
            ArrayList<ExtractAndMoveMethodCandidateRefactoring> list=new ArrayList<ExtractAndMoveMethodCandidateRefactoring>();
            list.add(candidate);
            extractedMethodNameMap.put(block.getExtractedMethodName(),list);
          }
 else {
            ArrayList<ExtractAndMoveMethodCandidateRefactoring> list=extractedMethodNameMap.get(block.getExtractedMethodName());
            list.add(candidate);
          }
        }
      }
    }
  }
  for (  String extractedMethodName : extractedMethodNameMap.keySet()) {
    List<ExtractAndMoveMethodCandidateRefactoring> list=extractedMethodNameMap.get(extractedMethodName);
    if (list.size() > 1) {
      for (      ExtractAndMoveMethodCandidateRefactoring candidate : list) {
        candidate.setDistinctExtractedMethodName();
      }
    }
  }
  Double[][] blockDistanceMatrix=new Double[extractMethodCandidateRefactoringList.size()][classList.size()];
  for (int i=0; i < extractMethodCandidateRefactoringList.size(); i++) {
    ExtractAndMoveMethodCandidateRefactoring candidate=extractMethodCandidateRefactoringList.get(i);
    for (int j=0; j < classList.size(); j++) {
      blockDistanceMatrix[i][j]=DistanceCalculator.getDistance(candidate.getEntitySet(),classMap.get(classNames[j]));
    }
  }
  List<ExtractAndMoveMethodCandidateRefactoring> candidateRefactoringList=new ArrayList<ExtractAndMoveMethodCandidateRefactoring>();
  ;
  Map<Integer,Double> minValueMap=new LinkedHashMap<Integer,Double>();
  for (int i=0; i < blockDistanceMatrix.length; i++) {
    double minValue=1;
    for (int j=0; j < blockDistanceMatrix[i].length; j++) {
      if (blockDistanceMatrix[i][j] < minValue) {
        minValue=blockDistanceMatrix[i][j];
      }
    }
    minValueMap.put(i,minValue);
  }
  for (  Integer i : minValueMap.keySet()) {
    double minValue=minValueMap.get(i);
    ExtractAndMoveMethodCandidateRefactoring candidate=extractMethodCandidateRefactoringList.get(i);
    String rowClass=candidate.getSourceClass().getName();
    if (minValue != 1) {
      for (int j=0; j < blockDistanceMatrix[i].length; j++) {
        if (blockDistanceMatrix[i][j] == minValue) {
          if (!rowClass.equals(classNames[j])) {
            MyClass targetClass=classList.get(j);
            ExtractAndMoveMethodCandidateRefactoring newCandidate=new ExtractAndMoveMethodCandidateRefactoring(system,candidate.getSourceClass(),targetClass,candidate.getSourceMethod(),candidate.getExtractionBlock());
            boolean applicable=newCandidate.apply();
            if (applicable)             candidateRefactoringList.add(newCandidate);
          }
        }
      }
    }
  }
  return candidateRefactoringList;
}