Program: 89745
Project: 89745
Buggy source:
@Override public UserVm createAdvancedVirtualMachine(DataCenter zone,ServiceOffering serviceOffering,VirtualMachineTemplate template,List<Long> networkIdList,Account owner,String hostName,String displayName,Long diskOfferingId,Long diskSize,String group,HypervisorType hypervisor,String userData,String sshKeyPair) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
  Account caller=UserContext.current().getCaller();
  List<NetworkVO> networkList=new ArrayList<NetworkVO>();
  _accountMgr.checkAccess(caller,owner);
  if (networkIdList == null || networkIdList.isEmpty()) {
    List<NetworkVO> networks=_networkDao.listByOwner(owner.getId());
    NetworkVO guestVirtualNetwork=null;
    for (    NetworkVO network : networks) {
      if (!network.isShared() && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == GuestIpType.Virtual) {
        guestVirtualNetwork=network;
        break;
      }
    }
    if (guestVirtualNetwork == null) {
      throw new InvalidParameterValueException("String_Node_Str" + owner.getId() + "String_Node_Str");
    }
    networkList.add(guestVirtualNetwork);
  }
 else {
    boolean requiredNetworkOfferingIsPresent=false;
    List<NetworkOfferingVO> requiredOfferings=_networkOfferingDao.listByAvailability(Availability.Required,false);
    Long requiredOfferingId=null;
    if (!requiredOfferings.isEmpty()) {
      requiredOfferingId=requiredOfferings.get(0).getId();
    }
    for (    Long networkId : networkIdList) {
      NetworkVO network=_networkDao.findById(networkId);
      if (network == null) {
        throw new InvalidParameterValueException("String_Node_Str" + networkIdList.get(0).longValue());
      }
      if (!network.isShared()) {
        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");
        }
      }
      if (requiredOfferingId != null && network.getNetworkOfferingId() == requiredOfferingId.longValue()) {
        requiredNetworkOfferingIsPresent=true;
      }
      networkList.add(network);
    }
    if (requiredOfferingId != null && !requiredNetworkOfferingIsPresent) {
      throw new InvalidParameterValueException("String_Node_Str" + requiredOfferingId + "String_Node_Str");
    }
  }
  return createVirtualMachine(zone,serviceOffering,template,hostName,displayName,caller,diskOfferingId,diskSize,networkList,null,group,userData,sshKeyPair,hypervisor,caller);
}

Fixed version (ground truth):
@Override public UserVm createAdvancedVirtualMachine(DataCenter zone,ServiceOffering serviceOffering,VirtualMachineTemplate template,List<Long> networkIdList,Account owner,String hostName,String displayName,Long diskOfferingId,Long diskSize,String group,HypervisorType hypervisor,String userData,String sshKeyPair) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
  Account caller=UserContext.current().getCaller();
  List<NetworkVO> networkList=new ArrayList<NetworkVO>();
  _accountMgr.checkAccess(caller,owner);
  if (networkIdList == null || networkIdList.isEmpty()) {
    List<NetworkVO> networks=_networkDao.listByOwner(owner.getId());
    NetworkVO guestVirtualNetwork=null;
    for (    NetworkVO network : networks) {
      if (!network.isShared() && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == GuestIpType.Virtual) {
        guestVirtualNetwork=network;
        break;
      }
    }
    if (guestVirtualNetwork == null) {
      throw new InvalidParameterValueException("String_Node_Str" + owner.getId() + "String_Node_Str");
    }
    networkList.add(guestVirtualNetwork);
  }
 else {
    boolean requiredNetworkOfferingIsPresent=false;
    List<NetworkOfferingVO> requiredOfferings=_networkOfferingDao.listByAvailability(Availability.Required,false);
    Long requiredOfferingId=null;
    if (!requiredOfferings.isEmpty()) {
      requiredOfferingId=requiredOfferings.get(0).getId();
    }
    for (    Long networkId : networkIdList) {
      NetworkVO network=_networkDao.findById(networkId);
      if (network == null) {
        throw new InvalidParameterValueException("String_Node_Str" + networkIdList.get(0).longValue());
      }
      if (!network.isShared()) {
        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");
        }
      }
      if (requiredOfferingId != null && network.getNetworkOfferingId() == requiredOfferingId.longValue()) {
        requiredNetworkOfferingIsPresent=true;
      }
      networkList.add(network);
    }
    if (requiredOfferingId != null && !requiredNetworkOfferingIsPresent) {
      throw new InvalidParameterValueException("String_Node_Str" + requiredOfferingId + "String_Node_Str");
    }
  }
  return createVirtualMachine(zone,serviceOffering,template,hostName,displayName,owner,diskOfferingId,diskSize,networkList,null,group,userData,sshKeyPair,hypervisor,caller);
}