Program: 12265
Project: 12265
Buggy source:
public List<ExtractionBlock> generateExtractionBlocks(){
  Map<LocalVariableDeclarationObject,List<AbstractStatement>> assignmentMap=new LinkedHashMap<LocalVariableDeclarationObject,List<AbstractStatement>>();
  for (  LocalVariableDeclarationObject lvdo : getLocalVariableDeclarations()) {
    List<AbstractStatement> localVariableAssignments=compositeStatement.getLocalVariableAssignments(lvdo);
    if (localVariableAssignments.size() > 0)     assignmentMap.put(lvdo,localVariableAssignments);
  }
  List<ExtractionBlock> extractionBlockList=new ArrayList<ExtractionBlock>();
  for (  LocalVariableDeclarationObject variableDeclaration : assignmentMap.keySet()) {
    List<AbstractStatement> localVariableAssignments=assignmentMap.get(variableDeclaration);
    List<String> assignmentOperators=new ArrayList<String>();
    Set<LocalVariableInstructionObject> localVariableInstructionsFoundInAssignments=new HashSet<LocalVariableInstructionObject>();
    for (    AbstractStatement localVariableAssignment : localVariableAssignments) {
      assignmentOperators.add(getAssignmentOperator(localVariableAssignment));
      List<LocalVariableInstructionObject> instructions=localVariableAssignment.getLocalVariableInstructions();
      for (      LocalVariableInstructionObject instruction : instructions) {
        if (assignmentMap.containsKey(instruction.generateLocalVariableDeclaration()))         localVariableInstructionsFoundInAssignments.add(instruction);
      }
    }
    Set<LocalVariableDeclarationObject> nonAcceptedVariableAssignments=new HashSet<LocalVariableDeclarationObject>(assignmentMap.keySet());
    for (    LocalVariableInstructionObject variableInstruction : localVariableInstructionsFoundInAssignments) {
      LocalVariableDeclarationObject lvdo=variableInstruction.generateLocalVariableDeclaration();
      nonAcceptedVariableAssignments.remove(lvdo);
    }
    List<AbstractStatement> newLocalVariableAssignments=new ArrayList<AbstractStatement>();
    for (    AbstractStatement statement : localVariableAssignments) {
      CompositeStatementObject parent=statement.getParent();
      AbstractStatement current=statement;
      while (parent != null && parent.getLocalVariableAssignments(nonAcceptedVariableAssignments).size() == 0 && removeExceptionVariableDeclarations(parent.getLocalVariableDeclarations()).size() == 0 && !parent.containsLocalVariableInstruction(nonAcceptedVariableAssignments)) {
        current=parent;
        parent=current.getParent();
      }
      if (!newLocalVariableAssignments.contains(current) && current.getParent() != null)       newLocalVariableAssignments.add(current);
    }
    AbstractStatement currentStatement=newLocalVariableAssignments.get(0);
    AbstractStatement parent=currentStatement.getParent();
    if (parent.getParent() == null) {
      boolean onlyLocalVariableDeclarationsFound=true;
      AbstractStatement previousStatement=compositeStatement.getPreviousStatement(currentStatement);
      while (previousStatement != null) {
        if (!(previousStatement.getStatement() instanceof VariableDeclarationStatement)) {
          onlyLocalVariableDeclarationsFound=false;
          break;
        }
        previousStatement=compositeStatement.getPreviousStatement(previousStatement);
      }
      if (onlyLocalVariableDeclarationsFound)       newLocalVariableAssignments.clear();
    }
    if ((newLocalVariableAssignments.size() > 1 && belongToTheSameBlock(newLocalVariableAssignments) && consecutive(newLocalVariableAssignments)) || (newLocalVariableAssignments.size() == 1 && !(newLocalVariableAssignments.get(0) instanceof StatementObject))) {
      ExtractionBlock block=new ExtractionBlock(variableDeclaration,getVariableDeclarationStatement(variableDeclaration),newLocalVariableAssignments,assignmentOperators);
      for (      LocalVariableInstructionObject variableInstruction : localVariableInstructionsFoundInAssignments) {
        LocalVariableDeclarationObject lvdo=variableInstruction.generateLocalVariableDeclaration();
        if (!lvdo.equals(variableDeclaration) && !hasAssignmentBeforeStatement(lvdo,newLocalVariableAssignments.get(0))) {
          VariableDeclarationStatement variableDeclarationStatement=getVariableDeclarationStatement(lvdo);
          if (variableDeclarationStatement != null)           block.addRequiredVariableDeclarationStatement(lvdo,variableDeclarationStatement);
        }
      }
      extractionBlockList.add(block);
    }
 else     if (newLocalVariableAssignments.size() > 1) {
      AbstractStatement parentStatement=haveRecursivelyTheSameParent(newLocalVariableAssignments);
      if (parentStatement != null && !(parentStatement.getStatement() instanceof Block)) {
        List<AbstractStatement> tempLocalVariableAssignments=new ArrayList<AbstractStatement>(newLocalVariableAssignments);
        for (        AbstractStatement statement : tempLocalVariableAssignments) {
          int index=newLocalVariableAssignments.indexOf(statement);
          AbstractStatement previousStatement=this.compositeStatement.getPreviousStatement(statement);
          while (previousStatement != null) {
            if (previousStatement instanceof StatementObject) {
              StatementObject previousStatementObject=(StatementObject)previousStatement;
              if (!previousStatementObject.isLocalVariableAssignment(nonAcceptedVariableAssignments)) {
                if (!(previousStatementObject.getStatement() instanceof EmptyStatement)) {
                  newLocalVariableAssignments.add(index,previousStatement);
                  index=newLocalVariableAssignments.indexOf(previousStatement);
                }
                previousStatement=this.compositeStatement.getPreviousStatement(previousStatement);
              }
 else {
                break;
              }
            }
 else             if (previousStatement instanceof CompositeStatementObject) {
              CompositeStatementObject previousCompositeStatement=(CompositeStatementObject)previousStatement;
              if (previousCompositeStatement.getLocalVariableAssignments(nonAcceptedVariableAssignments).size() == 0) {
                newLocalVariableAssignments.add(index,previousStatement);
                index=newLocalVariableAssignments.indexOf(previousStatement);
                previousStatement=this.compositeStatement.getPreviousStatement(previousStatement);
              }
 else {
                break;
              }
            }
          }
        }
        ExtractionBlock block=new ExtractionBlock(variableDeclaration,getVariableDeclarationStatement(variableDeclaration),newLocalVariableAssignments,assignmentOperators);
        for (        LocalVariableInstructionObject variableInstruction : localVariableInstructionsFoundInAssignments) {
          LocalVariableDeclarationObject lvdo=variableInstruction.generateLocalVariableDeclaration();
          if (!lvdo.equals(variableDeclaration) && !hasAssignmentBeforeStatement(lvdo,newLocalVariableAssignments.get(0))) {
            VariableDeclarationStatement variableDeclarationStatement=getVariableDeclarationStatement(lvdo);
            if (variableDeclarationStatement != null)             block.addRequiredVariableDeclarationStatement(lvdo,variableDeclarationStatement);
          }
        }
        block.setParentStatementForCopy(parentStatement);
        extractionBlockList.add(block);
      }
    }
  }
  return extractionBlockList;
}

Fixed version (ground truth):
public List<ExtractionBlock> generateExtractionBlocks(){
  Map<LocalVariableDeclarationObject,List<AbstractStatement>> assignmentMap=new LinkedHashMap<LocalVariableDeclarationObject,List<AbstractStatement>>();
  for (  LocalVariableDeclarationObject lvdo : getLocalVariableDeclarations()) {
    List<AbstractStatement> localVariableAssignments=compositeStatement.getLocalVariableAssignments(lvdo);
    if (localVariableAssignments.size() > 0)     assignmentMap.put(lvdo,localVariableAssignments);
  }
  List<ExtractionBlock> extractionBlockList=new ArrayList<ExtractionBlock>();
  for (  LocalVariableDeclarationObject variableDeclaration : assignmentMap.keySet()) {
    List<AbstractStatement> localVariableAssignments=assignmentMap.get(variableDeclaration);
    List<String> assignmentOperators=new ArrayList<String>();
    Set<LocalVariableInstructionObject> localVariableInstructionsFoundInAssignments=new HashSet<LocalVariableInstructionObject>();
    for (    AbstractStatement localVariableAssignment : localVariableAssignments) {
      assignmentOperators.add(getAssignmentOperator(localVariableAssignment));
      List<LocalVariableInstructionObject> instructions=localVariableAssignment.getLocalVariableInstructions();
      for (      LocalVariableInstructionObject instruction : instructions) {
        if (assignmentMap.containsKey(instruction.generateLocalVariableDeclaration()))         localVariableInstructionsFoundInAssignments.add(instruction);
      }
    }
    Set<LocalVariableDeclarationObject> nonAcceptedVariableAssignments=new HashSet<LocalVariableDeclarationObject>(assignmentMap.keySet());
    for (    LocalVariableInstructionObject variableInstruction : localVariableInstructionsFoundInAssignments) {
      LocalVariableDeclarationObject lvdo=variableInstruction.generateLocalVariableDeclaration();
      nonAcceptedVariableAssignments.remove(lvdo);
    }
    List<AbstractStatement> newLocalVariableAssignments=new ArrayList<AbstractStatement>();
    for (    AbstractStatement statement : localVariableAssignments) {
      CompositeStatementObject parent=statement.getParent();
      AbstractStatement current=statement;
      while (parent != null && parent.getLocalVariableAssignments(nonAcceptedVariableAssignments).size() == 0 && removeExceptionVariableDeclarations(parent.getLocalVariableDeclarations()).size() == 0 && !parent.containsLocalVariableInstruction(nonAcceptedVariableAssignments)) {
        current=parent;
        parent=current.getParent();
      }
      if (!newLocalVariableAssignments.contains(current) && current.getParent() != null)       newLocalVariableAssignments.add(current);
    }
    AbstractStatement currentStatement=newLocalVariableAssignments.get(0);
    AbstractStatement parent=currentStatement.getParent();
    if (parent.getParent() == null) {
      boolean onlyLocalVariableDeclarationsFound=true;
      AbstractStatement previousStatement=compositeStatement.getPreviousStatement(currentStatement);
      while (previousStatement != null) {
        if (!(previousStatement.getStatement() instanceof VariableDeclarationStatement)) {
          onlyLocalVariableDeclarationsFound=false;
          break;
        }
        previousStatement=compositeStatement.getPreviousStatement(previousStatement);
      }
      if (onlyLocalVariableDeclarationsFound)       newLocalVariableAssignments.clear();
    }
    if ((newLocalVariableAssignments.size() > 1 && belongToTheSameBlock(newLocalVariableAssignments) && consecutive(newLocalVariableAssignments)) || (newLocalVariableAssignments.size() == 1 && !(newLocalVariableAssignments.get(0) instanceof StatementObject))) {
      ExtractionBlock block=new ExtractionBlock(variableDeclaration,getVariableDeclarationStatement(variableDeclaration),newLocalVariableAssignments,assignmentOperators);
      for (      LocalVariableInstructionObject variableInstruction : localVariableInstructionsFoundInAssignments) {
        LocalVariableDeclarationObject lvdo=variableInstruction.generateLocalVariableDeclaration();
        if (!lvdo.equals(variableDeclaration) && !hasAssignmentBeforeStatement(lvdo,newLocalVariableAssignments.get(0))) {
          VariableDeclarationStatement variableDeclarationStatement=getVariableDeclarationStatement(lvdo);
          if (variableDeclarationStatement != null)           block.addRequiredVariableDeclarationStatement(lvdo,variableDeclarationStatement);
        }
      }
      extractionBlockList.add(block);
    }
 else     if (newLocalVariableAssignments.size() > 1) {
      CompositeStatementObject parentStatement=haveRecursivelyTheSameParent(newLocalVariableAssignments);
      if (parentStatement != null && !(parentStatement.getStatement() instanceof Block)) {
        List<AbstractStatement> tempLocalVariableAssignments=new ArrayList<AbstractStatement>(newLocalVariableAssignments);
        for (        AbstractStatement statement : tempLocalVariableAssignments) {
          int index=newLocalVariableAssignments.indexOf(statement);
          AbstractStatement previousStatement=this.compositeStatement.getPreviousStatement(statement);
          while (previousStatement != null) {
            if (previousStatement instanceof StatementObject) {
              StatementObject previousStatementObject=(StatementObject)previousStatement;
              if (!previousStatementObject.isLocalVariableAssignment(nonAcceptedVariableAssignments)) {
                if (!(previousStatementObject.getStatement() instanceof EmptyStatement)) {
                  newLocalVariableAssignments.add(index,previousStatement);
                  index=newLocalVariableAssignments.indexOf(previousStatement);
                }
                previousStatement=this.compositeStatement.getPreviousStatement(previousStatement);
              }
 else {
                break;
              }
            }
 else             if (previousStatement instanceof CompositeStatementObject) {
              CompositeStatementObject previousCompositeStatement=(CompositeStatementObject)previousStatement;
              if (previousCompositeStatement.getLocalVariableAssignments(nonAcceptedVariableAssignments).size() == 0) {
                newLocalVariableAssignments.add(index,previousStatement);
                index=newLocalVariableAssignments.indexOf(previousStatement);
                previousStatement=this.compositeStatement.getPreviousStatement(previousStatement);
              }
 else {
                break;
              }
            }
          }
        }
        ExtractionBlock block=new ExtractionBlock(variableDeclaration,getVariableDeclarationStatement(variableDeclaration),newLocalVariableAssignments,assignmentOperators);
        for (        LocalVariableInstructionObject variableInstruction : localVariableInstructionsFoundInAssignments) {
          LocalVariableDeclarationObject lvdo=variableInstruction.generateLocalVariableDeclaration();
          if (!lvdo.equals(variableDeclaration) && !hasAssignmentBeforeStatement(lvdo,newLocalVariableAssignments.get(0))) {
            VariableDeclarationStatement variableDeclarationStatement=getVariableDeclarationStatement(lvdo);
            if (variableDeclarationStatement != null)             block.addRequiredVariableDeclarationStatement(lvdo,variableDeclarationStatement);
          }
        }
        block.setParentStatementForCopy(parentStatement);
        extractionBlockList.add(block);
      }
    }
  }
  return extractionBlockList;
}