Program: 106306
Project: 106306
Buggy source:
@DB @Override @ActionEvent(eventType=EventTypes.EVENT_SECURITY_GROUP_DELETE,eventDescription="String_Node_Str") public boolean deleteAffinityGroup(Long affinityGroupId,String account,Long domainId,String affinityGroupName) throws ResourceInUseException {
  Account caller=UserContext.current().getCaller();
  Account owner=_accountMgr.finalizeOwner(caller,account,domainId,null);
  AffinityGroupVO group=null;
  if (affinityGroupId != null) {
    group=_affinityGroupDao.findById(affinityGroupId);
    if (group == null) {
      throw new InvalidParameterValueException("String_Node_Str" + affinityGroupId + "String_Node_Str");
    }
  }
 else   if (affinityGroupName != null) {
    group=_affinityGroupDao.findByAccountAndName(owner.getAccountId(),affinityGroupName);
    if (group == null) {
      throw new InvalidParameterValueException("String_Node_Str" + affinityGroupName + "String_Node_Str");
    }
  }
 else {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  _accountMgr.checkAccess(caller,null,true,group);
  final Transaction txn=Transaction.currentTxn();
  txn.start();
  group=_affinityGroupDao.lockRow(affinityGroupId,true);
  if (group == null) {
    throw new InvalidParameterValueException("String_Node_Str" + affinityGroupId);
  }
  List<AffinityGroupVMMapVO> affinityGroupVmMap=_affinityGroupVMMapDao.listByAffinityGroup(affinityGroupId);
  if (!affinityGroupVmMap.isEmpty()) {
    throw new ResourceInUseException("String_Node_Str");
  }
  _affinityGroupDao.expunge(affinityGroupId);
  txn.commit();
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + affinityGroupId);
  }
  return true;
}

Fixed version (ground truth):
@DB @Override @ActionEvent(eventType=EventTypes.EVENT_SECURITY_GROUP_DELETE,eventDescription="String_Node_Str") public boolean deleteAffinityGroup(Long affinityGroupId,String account,Long domainId,String affinityGroupName) throws ResourceInUseException {
  Account caller=UserContext.current().getCaller();
  Account owner=_accountMgr.finalizeOwner(caller,account,domainId,null);
  AffinityGroupVO group=null;
  if (affinityGroupId != null) {
    group=_affinityGroupDao.findById(affinityGroupId);
    if (group == null) {
      throw new InvalidParameterValueException("String_Node_Str" + affinityGroupId + "String_Node_Str");
    }
  }
 else   if (affinityGroupName != null) {
    group=_affinityGroupDao.findByAccountAndName(owner.getAccountId(),affinityGroupName);
    if (group == null) {
      throw new InvalidParameterValueException("String_Node_Str" + affinityGroupName + "String_Node_Str");
    }
  }
 else {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (affinityGroupId == null) {
    affinityGroupId=group.getId();
  }
  _accountMgr.checkAccess(caller,null,true,group);
  final Transaction txn=Transaction.currentTxn();
  txn.start();
  group=_affinityGroupDao.lockRow(affinityGroupId,true);
  if (group == null) {
    throw new InvalidParameterValueException("String_Node_Str" + affinityGroupId);
  }
  List<AffinityGroupVMMapVO> affinityGroupVmMap=_affinityGroupVMMapDao.listByAffinityGroup(affinityGroupId);
  if (!affinityGroupVmMap.isEmpty()) {
    throw new ResourceInUseException("String_Node_Str");
  }
  _affinityGroupDao.expunge(affinityGroupId);
  txn.commit();
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + affinityGroupId);
  }
  return true;
}