Program: 89396
Project: 89396
Buggy source:
@Override public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone,ServiceOffering serviceOffering,VirtualMachineTemplate template,List<Long> networkIdList,List<Long> securityGroupIdList,Account owner,String hostName,String displayName,Long diskOfferingId,Long diskSize,String group,HypervisorType hypervisor,String userData,String sshKeyPair,Map<Long,String> requestedIps,String defaultIp) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
  Account caller=UserContext.current().getCaller();
  List<NetworkVO> networkList=new ArrayList<NetworkVO>();
  boolean isSecurityGroupEnabledNetworkUsed=false;
  boolean isVmWare=(template.getHypervisorType() == HypervisorType.VMware || (hypervisor != null && hypervisor == HypervisorType.VMware));
  _accountMgr.checkAccess(caller,owner);
  if (networkIdList == null || networkIdList.isEmpty()) {
    NetworkVO networkWithSecurityGroup=_networkMgr.getNetworkWithSecurityGroupEnabled(zone.getId());
    if (networkWithSecurityGroup == null) {
      throw new InvalidParameterValueException("String_Node_Str" + zone.getId());
    }
    networkList.add(networkWithSecurityGroup);
  }
 else   if (securityGroupIdList != null && !securityGroupIdList.isEmpty()) {
    if (isVmWare) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (networkIdList.size() > 1) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    NetworkVO network=_networkDao.findById(networkIdList.get(0).longValue());
    if (network == null) {
      throw new InvalidParameterValueException("String_Node_Str" + networkIdList.get(0).longValue());
    }
    if (!network.isSecurityGroupEnabled()) {
      throw new InvalidParameterValueException("String_Node_Str" + network.getId());
    }
    networkList.add(network);
    isSecurityGroupEnabledNetworkUsed=true;
  }
 else {
    for (    Long networkId : networkIdList) {
      NetworkVO network=_networkDao.findById(networkId);
      if (network == null) {
        throw new InvalidParameterValueException("String_Node_Str" + networkIdList.get(0).longValue());
      }
      if (network.isSecurityGroupEnabled() && networkIdList.size() > 1) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      if (network.getTrafficType() != TrafficType.Guest || network.getGuestType() != GuestIpType.Direct || (network.getIsShared() && !network.isSecurityGroupEnabled())) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      if (!network.getIsShared()) {
        List<NetworkVO> networkMap=_networkDao.listBy(owner.getId(),network.getId());
        if (networkMap == null || networkMap.isEmpty()) {
          throw new PermissionDeniedException("String_Node_Str" + network.getId() + "String_Node_Str");
        }
      }
      networkList.add(network);
    }
  }
  if (isSecurityGroupEnabledNetworkUsed && !isVmWare) {
    if (securityGroupIdList == null) {
      securityGroupIdList=new ArrayList<Long>();
    }
    SecurityGroup defaultGroup=_securityGroupMgr.getDefaultSecurityGroup(owner.getId());
    if (defaultGroup != null) {
      boolean defaultGroupPresent=false;
      for (      Long securityGroupId : securityGroupIdList) {
        if (securityGroupId.longValue() == defaultGroup.getId()) {
          defaultGroupPresent=true;
          break;
        }
      }
      if (!defaultGroupPresent) {
        securityGroupIdList.add(defaultGroup.getId());
      }
    }
 else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + owner + "String_Node_Str");
      }
      defaultGroup=_securityGroupMgr.createSecurityGroup(SecurityGroupManager.DEFAULT_GROUP_NAME,SecurityGroupManager.DEFAULT_GROUP_DESCRIPTION,owner.getDomainId(),owner.getId(),owner.getAccountName());
      securityGroupIdList.add(defaultGroup.getId());
    }
  }
  return createVirtualMachine(zone,serviceOffering,template,hostName,displayName,owner,diskOfferingId,diskSize,networkList,securityGroupIdList,group,userData,sshKeyPair,hypervisor,caller,requestedIps,defaultIp);
}

Fixed version (ground truth):
@Override public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone,ServiceOffering serviceOffering,VirtualMachineTemplate template,List<Long> networkIdList,List<Long> securityGroupIdList,Account owner,String hostName,String displayName,Long diskOfferingId,Long diskSize,String group,HypervisorType hypervisor,String userData,String sshKeyPair,Map<Long,String> requestedIps,String defaultIp,String keyboard) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
  Account caller=UserContext.current().getCaller();
  List<NetworkVO> networkList=new ArrayList<NetworkVO>();
  boolean isSecurityGroupEnabledNetworkUsed=false;
  boolean isVmWare=(template.getHypervisorType() == HypervisorType.VMware || (hypervisor != null && hypervisor == HypervisorType.VMware));
  _accountMgr.checkAccess(caller,owner);
  if (networkIdList == null || networkIdList.isEmpty()) {
    NetworkVO networkWithSecurityGroup=_networkMgr.getNetworkWithSecurityGroupEnabled(zone.getId());
    if (networkWithSecurityGroup == null) {
      throw new InvalidParameterValueException("String_Node_Str" + zone.getId());
    }
    networkList.add(networkWithSecurityGroup);
  }
 else   if (securityGroupIdList != null && !securityGroupIdList.isEmpty()) {
    if (isVmWare) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (networkIdList.size() > 1) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    NetworkVO network=_networkDao.findById(networkIdList.get(0).longValue());
    if (network == null) {
      throw new InvalidParameterValueException("String_Node_Str" + networkIdList.get(0).longValue());
    }
    if (!network.isSecurityGroupEnabled()) {
      throw new InvalidParameterValueException("String_Node_Str" + network.getId());
    }
    networkList.add(network);
    isSecurityGroupEnabledNetworkUsed=true;
  }
 else {
    for (    Long networkId : networkIdList) {
      NetworkVO network=_networkDao.findById(networkId);
      if (network == null) {
        throw new InvalidParameterValueException("String_Node_Str" + networkIdList.get(0).longValue());
      }
      if (network.isSecurityGroupEnabled() && networkIdList.size() > 1) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      if (network.getTrafficType() != TrafficType.Guest || network.getGuestType() != GuestIpType.Direct || (network.getIsShared() && !network.isSecurityGroupEnabled())) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      if (!network.getIsShared()) {
        List<NetworkVO> networkMap=_networkDao.listBy(owner.getId(),network.getId());
        if (networkMap == null || networkMap.isEmpty()) {
          throw new PermissionDeniedException("String_Node_Str" + network.getId() + "String_Node_Str");
        }
      }
      networkList.add(network);
    }
  }
  if (isSecurityGroupEnabledNetworkUsed && !isVmWare) {
    if (securityGroupIdList == null) {
      securityGroupIdList=new ArrayList<Long>();
    }
    SecurityGroup defaultGroup=_securityGroupMgr.getDefaultSecurityGroup(owner.getId());
    if (defaultGroup != null) {
      boolean defaultGroupPresent=false;
      for (      Long securityGroupId : securityGroupIdList) {
        if (securityGroupId.longValue() == defaultGroup.getId()) {
          defaultGroupPresent=true;
          break;
        }
      }
      if (!defaultGroupPresent) {
        securityGroupIdList.add(defaultGroup.getId());
      }
    }
 else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + owner + "String_Node_Str");
      }
      defaultGroup=_securityGroupMgr.createSecurityGroup(SecurityGroupManager.DEFAULT_GROUP_NAME,SecurityGroupManager.DEFAULT_GROUP_DESCRIPTION,owner.getDomainId(),owner.getId(),owner.getAccountName());
      securityGroupIdList.add(defaultGroup.getId());
    }
  }
  return createVirtualMachine(zone,serviceOffering,template,hostName,displayName,owner,diskOfferingId,diskSize,networkList,securityGroupIdList,group,userData,sshKeyPair,hypervisor,caller,requestedIps,defaultIp,keyboard);
}