Program: 12022
Project: 12022
Buggy source:
protected Statement processPredicateNode(PDGControlPredicateNode predicateNode,AST ast,ASTRewrite sourceRewriter,List<PDGNode> sliceNodes){
  Statement oldPredicateStatement=predicateNode.getASTStatement();
  sliceNodes.remove(predicateNode);
  Statement newPredicateStatement=null;
  if (oldPredicateStatement instanceof IfStatement) {
    IfStatement oldIfStatement=(IfStatement)oldPredicateStatement;
    IfStatement newIfStatement=ast.newIfStatement();
    newPredicateStatement=newIfStatement;
    sourceRewriter.set(newIfStatement,IfStatement.EXPRESSION_PROPERTY,oldIfStatement.getExpression(),null);
    Iterator<GraphEdge> outgoingDependenceIterator=predicateNode.getOutgoingDependenceIterator();
    List<PDGNode> trueControlDependentChildren=new ArrayList<PDGNode>();
    List<PDGNode> falseControlDependentChildren=new ArrayList<PDGNode>();
    while (outgoingDependenceIterator.hasNext()) {
      PDGDependence dependence=(PDGDependence)outgoingDependenceIterator.next();
      if (dependence instanceof PDGControlDependence) {
        PDGControlDependence controlDependence=(PDGControlDependence)dependence;
        PDGNode dstPDGNode=(PDGNode)controlDependence.getDst();
        if (sliceNodes.contains(dstPDGNode)) {
          if (controlDependence.isTrueControlDependence()) {
            trueControlDependentChildren.add(dstPDGNode);
          }
 else           if (controlDependence.isFalseControlDependence()) {
            falseControlDependentChildren.add(dstPDGNode);
          }
        }
      }
    }
    if (oldIfStatement.getThenStatement() instanceof Block || trueControlDependentChildren.size() > 1) {
      Block thenBlock=ast.newBlock();
      ListRewrite thenBodyRewrite=sourceRewriter.getListRewrite(thenBlock,Block.STATEMENTS_PROPERTY);
      for (      PDGNode dstPDGNode : trueControlDependentChildren) {
        ListRewrite listRewrite=thenBodyRewrite;
        listRewrite=createTryStatementIfNeeded(sourceRewriter,ast,listRewrite,dstPDGNode);
        if (dstPDGNode instanceof PDGControlPredicateNode) {
          PDGControlPredicateNode dstPredicateNode=(PDGControlPredicateNode)dstPDGNode;
          listRewrite.insertLast(processPredicateNode(dstPredicateNode,ast,sourceRewriter,sliceNodes),null);
        }
 else {
          processStatementNode(listRewrite,dstPDGNode,ast,sourceRewriter);
          sliceNodes.remove(dstPDGNode);
        }
      }
      sourceRewriter.set(newIfStatement,IfStatement.THEN_STATEMENT_PROPERTY,thenBlock,null);
    }
 else     if (trueControlDependentChildren.size() == 1) {
      PDGNode dstPDGNode=trueControlDependentChildren.get(0);
      if (dstPDGNode instanceof PDGControlPredicateNode) {
        PDGControlPredicateNode dstPredicateNode=(PDGControlPredicateNode)dstPDGNode;
        sourceRewriter.set(newIfStatement,IfStatement.THEN_STATEMENT_PROPERTY,processPredicateNode(dstPredicateNode,ast,sourceRewriter,sliceNodes),null);
      }
 else {
        sourceRewriter.set(newIfStatement,IfStatement.THEN_STATEMENT_PROPERTY,dstPDGNode.getASTStatement(),null);
        sliceNodes.remove(dstPDGNode);
      }
    }
    if (oldIfStatement.getElseStatement() instanceof Block || falseControlDependentChildren.size() > 1) {
      Block elseBlock=ast.newBlock();
      ListRewrite elseBodyRewrite=sourceRewriter.getListRewrite(elseBlock,Block.STATEMENTS_PROPERTY);
      for (      PDGNode dstPDGNode : falseControlDependentChildren) {
        ListRewrite listRewrite=elseBodyRewrite;
        listRewrite=createTryStatementIfNeeded(sourceRewriter,ast,listRewrite,dstPDGNode);
        if (dstPDGNode instanceof PDGControlPredicateNode) {
          PDGControlPredicateNode dstPredicateNode=(PDGControlPredicateNode)dstPDGNode;
          listRewrite.insertLast(processPredicateNode(dstPredicateNode,ast,sourceRewriter,sliceNodes),null);
        }
 else {
          processStatementNode(listRewrite,dstPDGNode,ast,sourceRewriter);
          sliceNodes.remove(dstPDGNode);
        }
      }
      sourceRewriter.set(newIfStatement,IfStatement.ELSE_STATEMENT_PROPERTY,elseBlock,null);
    }
 else     if (falseControlDependentChildren.size() == 1) {
      PDGNode dstPDGNode=falseControlDependentChildren.get(0);
      if (dstPDGNode instanceof PDGControlPredicateNode) {
        PDGControlPredicateNode dstPredicateNode=(PDGControlPredicateNode)dstPDGNode;
        sourceRewriter.set(newIfStatement,IfStatement.ELSE_STATEMENT_PROPERTY,processPredicateNode(dstPredicateNode,ast,sourceRewriter,sliceNodes),null);
      }
 else {
        sourceRewriter.set(newIfStatement,IfStatement.ELSE_STATEMENT_PROPERTY,dstPDGNode.getASTStatement(),null);
        sliceNodes.remove(dstPDGNode);
      }
    }
  }
 else   if (oldPredicateStatement instanceof SwitchStatement) {
    SwitchStatement oldSwitchStatement=(SwitchStatement)oldPredicateStatement;
    SwitchStatement newSwitchStatement=ast.newSwitchStatement();
    newPredicateStatement=newSwitchStatement;
    sourceRewriter.set(newSwitchStatement,SwitchStatement.EXPRESSION_PROPERTY,oldSwitchStatement.getExpression(),null);
    ListRewrite switchStatementsRewrite=sourceRewriter.getListRewrite(newSwitchStatement,SwitchStatement.STATEMENTS_PROPERTY);
    Iterator<GraphEdge> outgoingDependenceIterator=predicateNode.getOutgoingDependenceIterator();
    while (outgoingDependenceIterator.hasNext()) {
      ListRewrite bodyRewrite=switchStatementsRewrite;
      PDGDependence dependence=(PDGDependence)outgoingDependenceIterator.next();
      if (dependence instanceof PDGControlDependence) {
        PDGControlDependence controlDependence=(PDGControlDependence)dependence;
        PDGNode dstPDGNode=(PDGNode)controlDependence.getDst();
        if (sliceNodes.contains(dstPDGNode)) {
          bodyRewrite=createTryStatementIfNeeded(sourceRewriter,ast,bodyRewrite,dstPDGNode);
          if (dstPDGNode instanceof PDGControlPredicateNode) {
            PDGControlPredicateNode dstPredicateNode=(PDGControlPredicateNode)dstPDGNode;
            bodyRewrite.insertLast(processPredicateNode(dstPredicateNode,ast,sourceRewriter,sliceNodes),null);
          }
 else {
            processStatementNode(bodyRewrite,dstPDGNode,ast,sourceRewriter);
            sliceNodes.remove(dstPDGNode);
          }
        }
      }
    }
  }
 else {
    Block loopBlock=ast.newBlock();
    ListRewrite loopBodyRewrite=sourceRewriter.getListRewrite(loopBlock,Block.STATEMENTS_PROPERTY);
    Iterator<GraphEdge> outgoingDependenceIterator=predicateNode.getOutgoingDependenceIterator();
    while (outgoingDependenceIterator.hasNext()) {
      ListRewrite bodyRewrite=loopBodyRewrite;
      PDGDependence dependence=(PDGDependence)outgoingDependenceIterator.next();
      if (dependence instanceof PDGControlDependence) {
        PDGControlDependence controlDependence=(PDGControlDependence)dependence;
        PDGNode dstPDGNode=(PDGNode)controlDependence.getDst();
        if (sliceNodes.contains(dstPDGNode)) {
          bodyRewrite=createTryStatementIfNeeded(sourceRewriter,ast,bodyRewrite,dstPDGNode);
          if (dstPDGNode instanceof PDGControlPredicateNode) {
            PDGControlPredicateNode dstPredicateNode=(PDGControlPredicateNode)dstPDGNode;
            bodyRewrite.insertLast(processPredicateNode(dstPredicateNode,ast,sourceRewriter,sliceNodes),null);
          }
 else {
            processStatementNode(bodyRewrite,dstPDGNode,ast,sourceRewriter);
            sliceNodes.remove(dstPDGNode);
          }
        }
      }
    }
    if (oldPredicateStatement instanceof WhileStatement) {
      WhileStatement oldWhileStatement=(WhileStatement)oldPredicateStatement;
      WhileStatement newWhileStatement=ast.newWhileStatement();
      newPredicateStatement=newWhileStatement;
      sourceRewriter.set(newWhileStatement,WhileStatement.EXPRESSION_PROPERTY,oldWhileStatement.getExpression(),null);
      sourceRewriter.set(newWhileStatement,WhileStatement.BODY_PROPERTY,loopBlock,null);
    }
 else     if (oldPredicateStatement instanceof ForStatement) {
      ForStatement oldForStatement=(ForStatement)oldPredicateStatement;
      ForStatement newForStatement=ast.newForStatement();
      newPredicateStatement=newForStatement;
      sourceRewriter.set(newForStatement,ForStatement.EXPRESSION_PROPERTY,oldForStatement.getExpression(),null);
      ListRewrite initializerRewrite=sourceRewriter.getListRewrite(newForStatement,ForStatement.INITIALIZERS_PROPERTY);
      List<Expression> initializers=oldForStatement.initializers();
      for (      Expression expression : initializers)       initializerRewrite.insertLast(expression,null);
      ListRewrite updaterRewrite=sourceRewriter.getListRewrite(newForStatement,ForStatement.UPDATERS_PROPERTY);
      List<Expression> updaters=oldForStatement.updaters();
      for (      Expression expression : updaters)       updaterRewrite.insertLast(expression,null);
      sourceRewriter.set(newForStatement,ForStatement.BODY_PROPERTY,loopBlock,null);
    }
 else     if (oldPredicateStatement instanceof EnhancedForStatement) {
      EnhancedForStatement oldEnhancedForStatement=(EnhancedForStatement)oldPredicateStatement;
      EnhancedForStatement newEnhancedForStatement=ast.newEnhancedForStatement();
      newPredicateStatement=newEnhancedForStatement;
      sourceRewriter.set(newEnhancedForStatement,EnhancedForStatement.PARAMETER_PROPERTY,oldEnhancedForStatement.getParameter(),null);
      sourceRewriter.set(newEnhancedForStatement,EnhancedForStatement.EXPRESSION_PROPERTY,oldEnhancedForStatement.getExpression(),null);
      sourceRewriter.set(newEnhancedForStatement,EnhancedForStatement.BODY_PROPERTY,loopBlock,null);
    }
 else     if (oldPredicateStatement instanceof DoStatement) {
      DoStatement oldDoStatement=(DoStatement)oldPredicateStatement;
      DoStatement newDoStatement=ast.newDoStatement();
      newPredicateStatement=newDoStatement;
      sourceRewriter.set(newDoStatement,DoStatement.EXPRESSION_PROPERTY,oldDoStatement.getExpression(),null);
      sourceRewriter.set(newDoStatement,DoStatement.BODY_PROPERTY,loopBlock,null);
    }
  }
  return newPredicateStatement;
}

Fixed version (ground truth):
protected Statement processPredicateNode(PDGControlPredicateNode predicateNode,AST ast,ASTRewrite sourceRewriter,List<PDGNode> sliceNodes){
  Statement oldPredicateStatement=predicateNode.getASTStatement();
  sliceNodes.remove(predicateNode);
  Statement newPredicateStatement=null;
  if (oldPredicateStatement instanceof IfStatement) {
    IfStatement oldIfStatement=(IfStatement)oldPredicateStatement;
    IfStatement newIfStatement=ast.newIfStatement();
    newPredicateStatement=newIfStatement;
    sourceRewriter.set(newIfStatement,IfStatement.EXPRESSION_PROPERTY,oldIfStatement.getExpression(),null);
    Iterator<GraphEdge> outgoingDependenceIterator=predicateNode.getOutgoingDependenceIterator();
    List<PDGNode> trueControlDependentChildren=new ArrayList<PDGNode>();
    List<PDGNode> falseControlDependentChildren=new ArrayList<PDGNode>();
    while (outgoingDependenceIterator.hasNext()) {
      PDGDependence dependence=(PDGDependence)outgoingDependenceIterator.next();
      if (dependence instanceof PDGControlDependence) {
        PDGControlDependence controlDependence=(PDGControlDependence)dependence;
        PDGNode dstPDGNode=(PDGNode)controlDependence.getDst();
        if (sliceNodes.contains(dstPDGNode)) {
          if (controlDependence.isTrueControlDependence()) {
            trueControlDependentChildren.add(dstPDGNode);
          }
 else           if (controlDependence.isFalseControlDependence()) {
            falseControlDependentChildren.add(dstPDGNode);
          }
        }
      }
    }
    if (oldIfStatement.getThenStatement() instanceof Block || trueControlDependentChildren.size() > 1) {
      Block thenBlock=ast.newBlock();
      ListRewrite thenBodyRewrite=sourceRewriter.getListRewrite(thenBlock,Block.STATEMENTS_PROPERTY);
      for (      PDGNode dstPDGNode : trueControlDependentChildren) {
        ListRewrite listRewrite=thenBodyRewrite;
        listRewrite=createTryStatementIfNeeded(sourceRewriter,ast,listRewrite,dstPDGNode);
        if (dstPDGNode instanceof PDGControlPredicateNode) {
          PDGControlPredicateNode dstPredicateNode=(PDGControlPredicateNode)dstPDGNode;
          listRewrite.insertLast(processPredicateNode(dstPredicateNode,ast,sourceRewriter,sliceNodes),null);
        }
 else {
          processStatementNode(listRewrite,dstPDGNode,ast,sourceRewriter);
          sliceNodes.remove(dstPDGNode);
        }
      }
      sourceRewriter.set(newIfStatement,IfStatement.THEN_STATEMENT_PROPERTY,thenBlock,null);
    }
 else     if (trueControlDependentChildren.size() == 1) {
      PDGNode dstPDGNode=trueControlDependentChildren.get(0);
      if (dstPDGNode instanceof PDGControlPredicateNode) {
        PDGControlPredicateNode dstPredicateNode=(PDGControlPredicateNode)dstPDGNode;
        sourceRewriter.set(newIfStatement,IfStatement.THEN_STATEMENT_PROPERTY,processPredicateNode(dstPredicateNode,ast,sourceRewriter,sliceNodes),null);
      }
 else {
        sourceRewriter.set(newIfStatement,IfStatement.THEN_STATEMENT_PROPERTY,dstPDGNode.getASTStatement(),null);
        sliceNodes.remove(dstPDGNode);
      }
    }
    if (oldIfStatement.getElseStatement() instanceof Block || falseControlDependentChildren.size() > 1) {
      Block elseBlock=ast.newBlock();
      ListRewrite elseBodyRewrite=sourceRewriter.getListRewrite(elseBlock,Block.STATEMENTS_PROPERTY);
      for (      PDGNode dstPDGNode : falseControlDependentChildren) {
        ListRewrite listRewrite=elseBodyRewrite;
        listRewrite=createTryStatementIfNeeded(sourceRewriter,ast,listRewrite,dstPDGNode);
        if (dstPDGNode instanceof PDGControlPredicateNode) {
          PDGControlPredicateNode dstPredicateNode=(PDGControlPredicateNode)dstPDGNode;
          listRewrite.insertLast(processPredicateNode(dstPredicateNode,ast,sourceRewriter,sliceNodes),null);
        }
 else {
          processStatementNode(listRewrite,dstPDGNode,ast,sourceRewriter);
          sliceNodes.remove(dstPDGNode);
        }
      }
      sourceRewriter.set(newIfStatement,IfStatement.ELSE_STATEMENT_PROPERTY,elseBlock,null);
    }
 else     if (falseControlDependentChildren.size() == 1) {
      PDGNode dstPDGNode=falseControlDependentChildren.get(0);
      if (dstPDGNode instanceof PDGControlPredicateNode) {
        PDGControlPredicateNode dstPredicateNode=(PDGControlPredicateNode)dstPDGNode;
        sourceRewriter.set(newIfStatement,IfStatement.ELSE_STATEMENT_PROPERTY,processPredicateNode(dstPredicateNode,ast,sourceRewriter,sliceNodes),null);
      }
 else {
        sourceRewriter.set(newIfStatement,IfStatement.ELSE_STATEMENT_PROPERTY,dstPDGNode.getASTStatement(),null);
        sliceNodes.remove(dstPDGNode);
      }
    }
  }
 else   if (oldPredicateStatement instanceof SwitchStatement) {
    SwitchStatement oldSwitchStatement=(SwitchStatement)oldPredicateStatement;
    SwitchStatement newSwitchStatement=ast.newSwitchStatement();
    newPredicateStatement=newSwitchStatement;
    sourceRewriter.set(newSwitchStatement,SwitchStatement.EXPRESSION_PROPERTY,oldSwitchStatement.getExpression(),null);
    ListRewrite switchStatementsRewrite=sourceRewriter.getListRewrite(newSwitchStatement,SwitchStatement.STATEMENTS_PROPERTY);
    Iterator<GraphEdge> outgoingDependenceIterator=predicateNode.getOutgoingDependenceIterator();
    while (outgoingDependenceIterator.hasNext()) {
      ListRewrite bodyRewrite=switchStatementsRewrite;
      PDGDependence dependence=(PDGDependence)outgoingDependenceIterator.next();
      if (dependence instanceof PDGControlDependence) {
        PDGControlDependence controlDependence=(PDGControlDependence)dependence;
        PDGNode dstPDGNode=(PDGNode)controlDependence.getDst();
        if (sliceNodes.contains(dstPDGNode)) {
          bodyRewrite=createTryStatementIfNeeded(sourceRewriter,ast,bodyRewrite,dstPDGNode);
          if (dstPDGNode instanceof PDGControlPredicateNode) {
            PDGControlPredicateNode dstPredicateNode=(PDGControlPredicateNode)dstPDGNode;
            bodyRewrite.insertLast(processPredicateNode(dstPredicateNode,ast,sourceRewriter,sliceNodes),null);
          }
 else {
            processStatementNode(bodyRewrite,dstPDGNode,ast,sourceRewriter);
            sliceNodes.remove(dstPDGNode);
          }
        }
      }
    }
  }
 else {
    Block loopBlock=ast.newBlock();
    ListRewrite loopBodyRewrite=sourceRewriter.getListRewrite(loopBlock,Block.STATEMENTS_PROPERTY);
    Iterator<GraphEdge> outgoingDependenceIterator=predicateNode.getOutgoingDependenceIterator();
    while (outgoingDependenceIterator.hasNext()) {
      ListRewrite bodyRewrite=loopBodyRewrite;
      PDGDependence dependence=(PDGDependence)outgoingDependenceIterator.next();
      if (dependence instanceof PDGControlDependence) {
        PDGControlDependence controlDependence=(PDGControlDependence)dependence;
        PDGNode dstPDGNode=(PDGNode)controlDependence.getDst();
        if (sliceNodes.contains(dstPDGNode)) {
          bodyRewrite=createTryStatementIfNeeded(sourceRewriter,ast,bodyRewrite,dstPDGNode);
          if (dstPDGNode instanceof PDGControlPredicateNode) {
            PDGControlPredicateNode dstPredicateNode=(PDGControlPredicateNode)dstPDGNode;
            bodyRewrite.insertLast(processPredicateNode(dstPredicateNode,ast,sourceRewriter,sliceNodes),null);
          }
 else {
            processStatementNode(bodyRewrite,dstPDGNode,ast,sourceRewriter);
            sliceNodes.remove(dstPDGNode);
          }
        }
      }
    }
    if (oldPredicateStatement instanceof WhileStatement) {
      WhileStatement oldWhileStatement=(WhileStatement)oldPredicateStatement;
      WhileStatement newWhileStatement=ast.newWhileStatement();
      newPredicateStatement=newWhileStatement;
      sourceRewriter.set(newWhileStatement,WhileStatement.EXPRESSION_PROPERTY,oldWhileStatement.getExpression(),null);
      sourceRewriter.set(newWhileStatement,WhileStatement.BODY_PROPERTY,loopBlock,null);
    }
 else     if (oldPredicateStatement instanceof ForStatement) {
      ForStatement oldForStatement=(ForStatement)oldPredicateStatement;
      ForStatement newForStatement=ast.newForStatement();
      newPredicateStatement=newForStatement;
      sourceRewriter.set(newForStatement,ForStatement.EXPRESSION_PROPERTY,oldForStatement.getExpression(),null);
      ListRewrite initializerRewrite=sourceRewriter.getListRewrite(newForStatement,ForStatement.INITIALIZERS_PROPERTY);
      List<Expression> initializers=oldForStatement.initializers();
      for (      Expression expression : initializers)       initializerRewrite.insertLast(expression,null);
      ListRewrite updaterRewrite=sourceRewriter.getListRewrite(newForStatement,ForStatement.UPDATERS_PROPERTY);
      List<Expression> updaters=oldForStatement.updaters();
      for (      Expression expression : updaters)       updaterRewrite.insertLast(expression,null);
      sourceRewriter.set(newForStatement,ForStatement.BODY_PROPERTY,loopBlock,null);
    }
 else     if (oldPredicateStatement instanceof EnhancedForStatement) {
      EnhancedForStatement oldEnhancedForStatement=(EnhancedForStatement)oldPredicateStatement;
      EnhancedForStatement newEnhancedForStatement=ast.newEnhancedForStatement();
      newPredicateStatement=newEnhancedForStatement;
      sourceRewriter.set(newEnhancedForStatement,EnhancedForStatement.PARAMETER_PROPERTY,oldEnhancedForStatement.getParameter(),null);
      sourceRewriter.set(newEnhancedForStatement,EnhancedForStatement.EXPRESSION_PROPERTY,oldEnhancedForStatement.getExpression(),null);
      sourceRewriter.set(newEnhancedForStatement,EnhancedForStatement.BODY_PROPERTY,loopBlock,null);
    }
 else     if (oldPredicateStatement instanceof DoStatement) {
      DoStatement oldDoStatement=(DoStatement)oldPredicateStatement;
      DoStatement newDoStatement=ast.newDoStatement();
      newPredicateStatement=newDoStatement;
      sourceRewriter.set(newDoStatement,DoStatement.EXPRESSION_PROPERTY,oldDoStatement.getExpression(),null);
      sourceRewriter.set(newDoStatement,DoStatement.BODY_PROPERTY,loopBlock,null);
    }
  }
  LabeledStatement labeled=belongsToLabeledStatement(predicateNode);
  if (labeled != null) {
    labeledStatementsToBeRemoved.add(labeled);
    LabeledStatement newLabeledStatement=ast.newLabeledStatement();
    sourceRewriter.set(newLabeledStatement,LabeledStatement.LABEL_PROPERTY,labeled.getLabel(),null);
    sourceRewriter.set(newLabeledStatement,LabeledStatement.BODY_PROPERTY,newPredicateStatement,null);
    newPredicateStatement=newLabeledStatement;
  }
  return newPredicateStatement;
}