Program: 35002
Project: 35002
Buggy source:
@Override public Result onRollback(RedPunishTransaction1 tx,Object secondaryData){
  RedPunishData punishData=tx.getTxData();
  List<Agent> agentList=PocConsensusContext.getChainManager().getMasterChain().getChain().getAgentList();
  Agent agent=null;
  for (  Agent agent_ : agentList) {
    if (agent_.getDelHeight() <= 0) {
      continue;
    }
    if (Arrays.equals(agent_.getAgentAddress(),punishData.getAddress())) {
      agent=agent_;
      break;
    }
  }
  if (null == agent) {
    return Result.getFailed(KernelErrorCode.DATA_ERROR,"String_Node_Str");
  }
  CreateAgentTransaction transaction=(CreateAgentTransaction)this.ledgerService.getTx(agent.getTxHash());
  if (null == transaction) {
    return Result.getFailed(KernelErrorCode.DATA_ERROR,"String_Node_Str");
  }
  try {
    Result rollbackResult=this.ledgerService.rollbackUnlockTxCoinData(transaction);
    if (rollbackResult.isFailed()) {
      return rollbackResult;
    }
    rollbackResult=this.accountLedgerService.rollbackUnlockTxCoinData(transaction);
    if (rollbackResult.isFailed()) {
      this.ledgerService.rollbackUnlockTxCoinData(transaction);
      return rollbackResult;
    }
  }
 catch (  NulsException e) {
    Log.error(e);
    return Result.getFailed(e.getErrorCode(),e.getMessage());
  }
  List<DepositPo> depositPoList=depositStorageService.getList();
  if (null == depositPoList) {
    return Result.getSuccess();
  }
  List<Transaction> rollbackedList=new ArrayList<>();
  rollbackedList.add(transaction);
  for (  DepositPo po : depositPoList) {
    if (po.getDelHeight() >= 0) {
      continue;
    }
    if (!po.getAgentHash().equals(agent.getTxHash())) {
      continue;
    }
    po.setDelHeight(-1L);
    Transaction depositTx=ledgerService.getTx(po.getTxHash());
    try {
      Result result=ledgerService.rollbackUnlockTxCoinData(depositTx);
      if (result.isFailed()) {
        this.unlockTxList(rollbackedList,tx.getBlockHeight());
        return result;
      }
      result=accountLedgerService.rollbackUnlockTxCoinData(depositTx);
      if (result.isFailed()) {
        this.unlockTxList(rollbackedList,tx.getBlockHeight());
        return result;
      }
      boolean b=depositStorageService.save(po);
      if (!b) {
        this.unlockTxList(rollbackedList,tx.getBlockHeight());
        return ValidateResult.getFailedResult(this.getClass().getName(),"String_Node_Str");
      }
      rollbackedList.add(depositTx);
    }
 catch (    NulsException e) {
      this.unlockTxList(rollbackedList,tx.getBlockHeight());
      return Result.getFailed(e.getMessage());
    }
  }
  AgentPo agentPo=PoConvertUtil.agentToPo(agent);
  agentPo.setDelHeight(-1L);
  boolean success=agentStorageService.save(agentPo);
  if (!success) {
    this.unlockTxList(rollbackedList,tx.getBlockHeight());
    return Result.getFailed(KernelErrorCode.DATA_ERROR,"String_Node_Str");
  }
  success=storageService.delete(getPoKey(punishData.getAddress(),PunishType.RED.getCode(),tx.getBlockHeight()));
  if (!success) {
    this.unlockTxList(rollbackedList,tx.getBlockHeight());
    agentPo.setDelHeight(tx.getBlockHeight());
    agentStorageService.save(agentPo);
    throw new NulsRuntimeException(KernelErrorCode.FAILED,"String_Node_Str");
  }
  return Result.getSuccess();
}

Fixed version (ground truth):
@Override public Result onRollback(RedPunishTransaction tx,Object secondaryData){
  RedPunishData punishData=tx.getTxData();
  List<Agent> agentList=PocConsensusContext.getChainManager().getMasterChain().getChain().getAgentList();
  Agent agent=null;
  for (  Agent agent_ : agentList) {
    if (agent_.getDelHeight() <= 0) {
      continue;
    }
    if (Arrays.equals(agent_.getAgentAddress(),punishData.getAddress())) {
      agent=agent_;
      break;
    }
  }
  if (null == agent) {
    return Result.getFailed(KernelErrorCode.DATA_ERROR,"String_Node_Str");
  }
  CreateAgentTransaction transaction=(CreateAgentTransaction)this.ledgerService.getTx(agent.getTxHash());
  if (null == transaction) {
    return Result.getFailed(KernelErrorCode.DATA_ERROR,"String_Node_Str");
  }
  try {
    Result rollbackResult=this.ledgerService.rollbackUnlockTxCoinData(transaction);
    if (rollbackResult.isFailed()) {
      return rollbackResult;
    }
    rollbackResult=this.accountLedgerService.rollbackUnlockTxCoinData(transaction);
    if (rollbackResult.isFailed()) {
      this.ledgerService.rollbackUnlockTxCoinData(transaction);
      return rollbackResult;
    }
  }
 catch (  NulsException e) {
    Log.error(e);
    return Result.getFailed(e.getErrorCode(),e.getMessage());
  }
  List<DepositPo> depositPoList=depositStorageService.getList();
  if (null == depositPoList) {
    return Result.getSuccess();
  }
  List<Transaction> rollbackedList=new ArrayList<>();
  rollbackedList.add(transaction);
  for (  DepositPo po : depositPoList) {
    if (po.getDelHeight() >= 0) {
      continue;
    }
    if (!po.getAgentHash().equals(agent.getTxHash())) {
      continue;
    }
    po.setDelHeight(-1L);
    Transaction depositTx=ledgerService.getTx(po.getTxHash());
    try {
      Result result=ledgerService.rollbackUnlockTxCoinData(depositTx);
      if (result.isFailed()) {
        this.unlockTxList(rollbackedList,tx.getBlockHeight());
        return result;
      }
      result=accountLedgerService.rollbackUnlockTxCoinData(depositTx);
      if (result.isFailed()) {
        this.unlockTxList(rollbackedList,tx.getBlockHeight());
        return result;
      }
      boolean b=depositStorageService.save(po);
      if (!b) {
        this.unlockTxList(rollbackedList,tx.getBlockHeight());
        return ValidateResult.getFailedResult(this.getClass().getName(),"String_Node_Str");
      }
      rollbackedList.add(depositTx);
    }
 catch (    NulsException e) {
      this.unlockTxList(rollbackedList,tx.getBlockHeight());
      return Result.getFailed(e.getMessage());
    }
  }
  AgentPo agentPo=PoConvertUtil.agentToPo(agent);
  agentPo.setDelHeight(-1L);
  boolean success=agentStorageService.save(agentPo);
  if (!success) {
    this.unlockTxList(rollbackedList,tx.getBlockHeight());
    return Result.getFailed(KernelErrorCode.DATA_ERROR,"String_Node_Str");
  }
  success=storageService.delete(getPoKey(punishData.getAddress(),PunishType.RED.getCode(),tx.getBlockHeight()));
  if (!success) {
    this.unlockTxList(rollbackedList,tx.getBlockHeight());
    agentPo.setDelHeight(tx.getBlockHeight());
    agentStorageService.save(agentPo);
    throw new NulsRuntimeException(KernelErrorCode.FAILED,"String_Node_Str");
  }
  return Result.getSuccess();
}