Program: 35076
Project: 35076
Buggy source:
private boolean changeChain(ChainContainer newMasterChain,ChainContainer originalForkChain) throws NulsException, IOException {
  if (newMasterChain == null || originalForkChain == null) {
    return false;
  }
  ChainContainer oldChain=chainManager.getMasterChain().getAfterTheForkChain(originalForkChain);
  List<Block> rollbackBlockList=oldChain.getChain().getBlockList();
  ChainLog.debug("String_Node_Str",rollbackBlockList.size(),chainManager.getMasterChain().getChain().getId(),chainManager.getBestBlock().getHeader().getHeight(),chainManager.getBestBlock().getHeader().getHash(),blockService.getBestBlock().getData().getHeader().getHeight(),blockService.getBestBlock().getData().getHeader().getHash());
  Collections.reverse(rollbackBlockList);
  boolean rollbackResult=rollbackBlocks(rollbackBlockList);
  if (!rollbackResult) {
    return false;
  }
  List<Block> addBlockList=originalForkChain.getChain().getBlockList();
  boolean changeSuccess=true;
  List<Block> successList=new ArrayList<>();
  for (  Block newBlock : addBlockList) {
    newBlock.verifyWithException();
    List<Transaction> verifiedList=new ArrayList<>();
    for (    Transaction tx : newBlock.getTxs()) {
      if (tx.getType() == ConsensusConstant.TX_TYPE_YELLOW_PUNISH || tx.getType() == ConsensusConstant.TX_TYPE_RED_PUNISH) {
        continue;
      }
      ValidateResult result=ledgerService.verifyCoinData(tx.getCoinData(),verifiedList);
      if (result.isSuccess()) {
        result=tx.verify();
        if (result.isFailed()) {
          Log.info("String_Node_Str" + result.getMessage());
          changeSuccess=false;
          break;
        }
 else {
          verifiedList.add(tx);
        }
      }
 else {
        Log.info("String_Node_Str" + result.getMessage());
        changeSuccess=false;
        break;
      }
    }
    if (!changeSuccess) {
      break;
    }
    ValidateResult validateResult1=tansactionService.conflictDetect(newBlock.getTxs());
    if (validateResult1.isFailed()) {
      Log.info("String_Node_Str" + validateResult1.getMessage());
      changeSuccess=false;
      break;
    }
    try {
      Result result=blockService.saveBlock(newBlock);
      boolean success=result.isSuccess();
      if (success) {
        successList.add(newBlock);
      }
 else {
        ChainLog.debug("String_Node_Str" + result.getMessage() + "String_Node_Str"+ newBlock.getHeader().getHeight()+ "String_Node_Str"+ newBlock.getHeader().getHash());
        changeSuccess=false;
        break;
      }
    }
 catch (    Exception e) {
      Log.info("String_Node_Str",e);
      changeSuccess=false;
      break;
    }
  }
  ChainLog.debug("String_Node_Str",changeSuccess,successList.size(),blockService.getBestBlock().getData().getHeader().getHeight(),blockService.getBestBlock().getData().getHeader().getHash());
  if (changeSuccess) {
    chainManager.setMasterChain(newMasterChain);
    newMasterChain.initRound();
    NulsContext.getInstance().setBestBlock(newMasterChain.getBestBlock());
    if (oldChain.getChain().getBlockList().size() > 0) {
      chainManager.getChains().add(oldChain);
    }
  }
 else {
    Collections.reverse(successList);
    for (    Block rollBlock : successList) {
      blockService.rollbackBlock(rollBlock);
    }
    Collections.reverse(rollbackBlockList);
    for (    Block addBlock : rollbackBlockList) {
      blockService.saveBlock(addBlock);
    }
  }
  return changeSuccess;
}

Fixed version (ground truth):
private boolean changeChain(ChainContainer newMasterChain,ChainContainer originalForkChain) throws NulsException, IOException {
  if (newMasterChain == null || originalForkChain == null) {
    return false;
  }
  ChainContainer oldChain=chainManager.getMasterChain().getAfterTheForkChain(originalForkChain);
  List<Block> rollbackBlockList=oldChain.getChain().getBlockList();
  ChainLog.debug("String_Node_Str",rollbackBlockList.size(),chainManager.getMasterChain().getChain().getId(),chainManager.getBestBlock().getHeader().getHeight(),chainManager.getBestBlock().getHeader().getHash(),blockService.getBestBlock().getData().getHeader().getHeight(),blockService.getBestBlock().getData().getHeader().getHash());
  Collections.reverse(rollbackBlockList);
  boolean rollbackResult=rollbackBlocks(rollbackBlockList);
  if (!rollbackResult) {
    return false;
  }
  List<Block> addBlockList=originalForkChain.getChain().getBlockList();
  boolean changeSuccess=true;
  List<Block> successList=new ArrayList<>();
  for (  Block newBlock : addBlockList) {
    newBlock.verifyWithException();
    List<Transaction> verifiedList=new ArrayList<>();
    for (    Transaction tx : newBlock.getTxs()) {
      if (tx.getType() == ConsensusConstant.TX_TYPE_YELLOW_PUNISH || tx.getType() == ConsensusConstant.TX_TYPE_RED_PUNISH) {
        continue;
      }
      ValidateResult result=ledgerService.verifyCoinData(tx,verifiedList);
      if (result.isSuccess()) {
        result=tx.verify();
        if (result.isFailed()) {
          Log.info("String_Node_Str" + result.getMessage());
          changeSuccess=false;
          break;
        }
 else {
          verifiedList.add(tx);
        }
      }
 else {
        Log.info("String_Node_Str" + result.getMessage());
        changeSuccess=false;
        break;
      }
    }
    if (!changeSuccess) {
      break;
    }
    ValidateResult validateResult1=tansactionService.conflictDetect(newBlock.getTxs());
    if (validateResult1.isFailed()) {
      Log.info("String_Node_Str" + validateResult1.getMessage());
      changeSuccess=false;
      break;
    }
    try {
      Result result=blockService.saveBlock(newBlock);
      boolean success=result.isSuccess();
      if (success) {
        successList.add(newBlock);
      }
 else {
        ChainLog.debug("String_Node_Str" + result.getMessage() + "String_Node_Str"+ newBlock.getHeader().getHeight()+ "String_Node_Str"+ newBlock.getHeader().getHash());
        changeSuccess=false;
        break;
      }
    }
 catch (    Exception e) {
      Log.info("String_Node_Str",e);
      changeSuccess=false;
      break;
    }
  }
  ChainLog.debug("String_Node_Str",changeSuccess,successList.size(),blockService.getBestBlock().getData().getHeader().getHeight(),blockService.getBestBlock().getData().getHeader().getHash());
  if (changeSuccess) {
    chainManager.setMasterChain(newMasterChain);
    newMasterChain.initRound();
    NulsContext.getInstance().setBestBlock(newMasterChain.getBestBlock());
    if (oldChain.getChain().getBlockList().size() > 0) {
      chainManager.getChains().add(oldChain);
    }
  }
 else {
    Collections.reverse(successList);
    for (    Block rollBlock : successList) {
      blockService.rollbackBlock(rollBlock);
    }
    Collections.reverse(rollbackBlockList);
    for (    Block addBlock : rollbackBlockList) {
      blockService.saveBlock(addBlock);
    }
  }
  return changeSuccess;
}