Program: 106787
Project: 106787
Buggy source:
@DB public void work(){
  if (s_logger.isTraceEnabled()) {
    s_logger.trace("String_Node_Str");
  }
  final SecurityGroupWorkVO work=_workDao.take(_serverId);
  if (work == null) {
    if (s_logger.isTraceEnabled()) {
      s_logger.trace("String_Node_Str");
    }
    return;
  }
  Long userVmId=work.getInstanceId();
  if (work.getStep() == Step.Done) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + userVmId);
    }
    Set<Long> affectedVms=new HashSet<Long>();
    affectedVms.add(userVmId);
    scheduleRulesetUpdateToHosts(affectedVms,true,_timeBetweenCleanups * 1000l);
  }
  UserVm vm=null;
  Long seqnum=null;
  s_logger.debug("String_Node_Str" + work);
  final Transaction txn=Transaction.currentTxn();
  txn.start();
  try {
    vm=_userVMDao.acquireInLockTable(work.getInstanceId());
    if (vm == null) {
      s_logger.warn("String_Node_Str" + userVmId);
      return;
    }
    Long agentId=null;
    VmRulesetLogVO log=_rulesetLogDao.findByVmId(userVmId);
    if (log == null) {
      s_logger.warn("String_Node_Str" + userVmId);
      return;
    }
    seqnum=log.getLogsequence();
    if (vm != null && vm.getState() == State.Running) {
      Map<PortAndProto,Set<String>> rules=generateRulesForVM(userVmId);
      agentId=vm.getHostId();
      if (agentId != null) {
        _rulesetLogDao.findByVmId(work.getInstanceId());
        SecurityIngressRulesCmd cmd=generateRulesetCmd(vm.getInstanceName(),vm.getPrivateIpAddress(),vm.getPrivateMacAddress(),vm.getId(),generateRulesetSignature(rules),seqnum,rules);
        Commands cmds=new Commands(cmd);
        try {
          _agentMgr.send(agentId,cmds,_answerListener);
        }
 catch (        AgentUnavailableException e) {
          s_logger.debug("String_Node_Str" + userVmId + "String_Node_Str"+ agentId+ "String_Node_Str");
          _workDao.updateStep(work.getInstanceId(),seqnum,Step.Done);
        }
      }
    }
  }
  finally {
    if (vm != null) {
      _userVMDao.releaseFromLockTable(userVmId);
      _workDao.updateStep(work.getId(),Step.Done);
    }
    txn.commit();
  }
}

Fixed version (ground truth):
@DB public void work(){
  if (s_logger.isTraceEnabled()) {
    s_logger.trace("String_Node_Str");
  }
  final SecurityGroupWorkVO work=_workDao.take(_serverId);
  if (work == null) {
    if (s_logger.isTraceEnabled()) {
      s_logger.trace("String_Node_Str");
    }
    return;
  }
  Long userVmId=work.getInstanceId();
  if (work.getStep() == Step.Done) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + userVmId);
    }
    Set<Long> affectedVms=new HashSet<Long>();
    affectedVms.add(userVmId);
    scheduleRulesetUpdateToHosts(affectedVms,true,_timeBetweenCleanups * 1000l);
  }
  UserVm vm=null;
  Long seqnum=null;
  s_logger.debug("String_Node_Str" + work);
  final Transaction txn=Transaction.currentTxn();
  txn.start();
  boolean locked=false;
  try {
    vm=_userVMDao.acquireInLockTable(work.getInstanceId());
    if (vm == null) {
      vm=_userVMDao.findById(work.getInstanceId());
      if (vm == null) {
        s_logger.info("String_Node_Str" + work.getInstanceId() + "String_Node_Str");
        locked=true;
        return;
      }
      s_logger.warn("String_Node_Str" + userVmId);
      return;
    }
    locked=true;
    Long agentId=null;
    VmRulesetLogVO log=_rulesetLogDao.findByVmId(userVmId);
    if (log == null) {
      s_logger.warn("String_Node_Str" + userVmId);
      return;
    }
    seqnum=log.getLogsequence();
    if (vm != null && vm.getState() == State.Running) {
      Map<PortAndProto,Set<String>> rules=generateRulesForVM(userVmId);
      agentId=vm.getHostId();
      if (agentId != null) {
        _rulesetLogDao.findByVmId(work.getInstanceId());
        SecurityIngressRulesCmd cmd=generateRulesetCmd(vm.getInstanceName(),vm.getPrivateIpAddress(),vm.getPrivateMacAddress(),vm.getId(),generateRulesetSignature(rules),seqnum,rules);
        Commands cmds=new Commands(cmd);
        try {
          _agentMgr.send(agentId,cmds,_answerListener);
        }
 catch (        AgentUnavailableException e) {
          s_logger.debug("String_Node_Str" + userVmId + "String_Node_Str"+ agentId+ "String_Node_Str");
          _workDao.updateStep(work.getInstanceId(),seqnum,Step.Done);
        }
      }
    }
  }
  finally {
    if (locked) {
      _userVMDao.releaseFromLockTable(userVmId);
      _workDao.updateStep(work.getId(),Step.Done);
    }
    txn.commit();
  }
}