Program: 105565
Project: 105565
Buggy source:
@Override @DB public boolean associateIpAddressListToAccount(long userId,final long accountId,final long zoneId,final Long vlanId,final Network guestNetworkFinal) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, ResourceAllocationException {
  final Account owner=_accountMgr.getActiveAccountById(accountId);
  if (guestNetworkFinal != null && guestNetworkFinal.getTrafficType() != TrafficType.Guest) {
    throw new InvalidParameterValueException("String_Node_Str" + guestNetworkFinal + "String_Node_Str"+ TrafficType.Guest);
  }
  Ternary<Boolean,List<NetworkOfferingVO>,Network> pair=null;
  try {
    pair=Transaction.execute(new TransactionCallbackWithException<Ternary<Boolean,List<NetworkOfferingVO>,Network>,Exception>(){
      @Override public Ternary<Boolean,List<NetworkOfferingVO>,Network> doInTransaction(      TransactionStatus status) throws InsufficientCapacityException, ResourceAllocationException {
        boolean createNetwork=false;
        Network guestNetwork=guestNetworkFinal;
        if (guestNetwork == null) {
          List<? extends Network> networks=getIsolatedNetworksWithSourceNATOwnedByAccountInZone(zoneId,owner);
          if (networks.size() == 0) {
            createNetwork=true;
          }
 else           if (networks.size() == 1) {
            guestNetwork=networks.get(0);
          }
 else {
            throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
          }
        }
        List<NetworkOfferingVO> requiredOfferings=_networkOfferingDao.listByAvailability(Availability.Required,false);
        if (requiredOfferings.size() < 1) {
          throw new CloudRuntimeException("String_Node_Str" + Availability.Required + "String_Node_Str");
        }
        if (createNetwork) {
          if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled) {
            long physicalNetworkId=_networkModel.findPhysicalNetworkId(zoneId,requiredOfferings.get(0).getTags(),requiredOfferings.get(0).getTrafficType());
            PhysicalNetwork physicalNetwork=_physicalNetworkDao.findById(physicalNetworkId);
            if (physicalNetwork == null) {
              throw new InvalidParameterValueException("String_Node_Str" + physicalNetworkId + "String_Node_Str"+ requiredOfferings.get(0).getTags());
            }
            s_logger.debug("String_Node_Str" + owner + "String_Node_Str"+ requiredOfferings.get(0).getId()+ "String_Node_Str");
            guestNetwork=_networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(),owner.getAccountName() + "String_Node_Str",owner.getAccountName() + "String_Node_Str",null,null,null,null,owner,null,physicalNetwork,zoneId,ACLType.Account,null,null,null,null,true,null);
            if (guestNetwork == null) {
              s_logger.warn("String_Node_Str" + accountId + "String_Node_Str"+ zoneId);
              throw new CloudRuntimeException("String_Node_Str" + "String_Node_Str" + accountId + "String_Node_Str"+ zoneId);
            }
          }
 else {
            throw new CloudRuntimeException("String_Node_Str" + requiredOfferings.get(0).getId() + "String_Node_Str"+ NetworkOffering.State.Enabled);
          }
        }
        boolean allocateSourceNat=false;
        List<IPAddressVO> sourceNat=_ipAddressDao.listByAssociatedNetwork(guestNetwork.getId(),true);
        if (sourceNat.isEmpty()) {
          allocateSourceNat=true;
        }
        List<IPAddressVO> ips=_ipAddressDao.listByVlanId(vlanId);
        boolean isSourceNatAllocated=false;
        for (        IPAddressVO addr : ips) {
          if (addr.getState() != State.Allocated) {
            if (!isSourceNatAllocated && allocateSourceNat) {
              addr.setSourceNat(true);
              isSourceNatAllocated=true;
            }
 else {
              addr.setSourceNat(false);
            }
            addr.setAssociatedWithNetworkId(guestNetwork.getId());
            addr.setVpcId(guestNetwork.getVpcId());
            addr.setAllocatedTime(new Date());
            addr.setAllocatedInDomainId(owner.getDomainId());
            addr.setAllocatedToAccountId(owner.getId());
            addr.setSystem(false);
            addr.setState(IpAddress.State.Allocating);
            markPublicIpAsAllocated(addr);
          }
        }
        return new Ternary<Boolean,List<NetworkOfferingVO>,Network>(createNetwork,requiredOfferings,guestNetwork);
      }
    }
);
  }
 catch (  Exception e1) {
    ExceptionUtil.rethrowRuntime(e1);
    ExceptionUtil.rethrow(e1,InsufficientCapacityException.class);
    ExceptionUtil.rethrow(e1,ResourceAllocationException.class);
    throw new IllegalStateException(e1);
  }
  boolean createNetwork=pair.first();
  List<NetworkOfferingVO> requiredOfferings=pair.second();
  Network guestNetwork=pair.third();
  if (createNetwork && requiredOfferings.get(0).getIsPersistent()) {
    DataCenter zone=_dcDao.findById(zoneId);
    DeployDestination dest=new DeployDestination(zone,null,null,null);
    Account callerAccount=CallContext.current().getCallingAccount();
    UserVO callerUser=_userDao.findById(CallContext.current().getCallingUserId());
    Journal journal=new Journal.LogJournal("String_Node_Str" + guestNetwork,s_logger);
    ReservationContext context=new ReservationContextImpl(UUID.randomUUID().toString(),journal,callerUser,callerAccount);
    s_logger.debug("String_Node_Str" + guestNetwork + "String_Node_Str");
    try {
      Pair<? extends NetworkGuru,? extends Network> implementedNetwork=_networkMgr.implementNetwork(guestNetwork.getId(),dest,context);
      if (implementedNetwork == null || implementedNetwork.first() == null) {
        s_logger.warn("String_Node_Str" + guestNetwork);
      }
      guestNetwork=implementedNetwork.second();
    }
 catch (    Exception ex) {
      s_logger.warn("String_Node_Str" + guestNetwork + "String_Node_Str"+ "String_Node_Str",ex);
      CloudRuntimeException e=new CloudRuntimeException("String_Node_Str" + "String_Node_Str");
      e.addProxyObject(guestNetwork.getUuid(),"String_Node_Str");
      throw e;
    }
  }
  return true;
}

Fixed version (ground truth):
@Override @DB public boolean associateIpAddressListToAccount(long userId,final long accountId,final long zoneId,final Long vlanId,final Network guestNetworkFinal) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, ResourceAllocationException {
  final Account owner=_accountMgr.getActiveAccountById(accountId);
  if (guestNetworkFinal != null && guestNetworkFinal.getTrafficType() != TrafficType.Guest) {
    throw new InvalidParameterValueException("String_Node_Str" + guestNetworkFinal + "String_Node_Str"+ TrafficType.Guest);
  }
  Ternary<Boolean,List<NetworkOfferingVO>,Network> pair=null;
  try {
    pair=Transaction.execute(new TransactionCallbackWithException<Ternary<Boolean,List<NetworkOfferingVO>,Network>,Exception>(){
      @Override public Ternary<Boolean,List<NetworkOfferingVO>,Network> doInTransaction(      TransactionStatus status) throws InsufficientCapacityException, ResourceAllocationException {
        boolean createNetwork=false;
        Network guestNetwork=guestNetworkFinal;
        if (guestNetwork == null) {
          List<? extends Network> networks=getIsolatedNetworksWithSourceNATOwnedByAccountInZone(zoneId,owner);
          if (networks.size() == 0) {
            createNetwork=true;
          }
 else           if (networks.size() == 1) {
            guestNetwork=networks.get(0);
          }
 else {
            throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
          }
        }
        List<NetworkOfferingVO> requiredOfferings=_networkOfferingDao.listByAvailability(Availability.Required,false);
        if (requiredOfferings.size() < 1) {
          throw new CloudRuntimeException("String_Node_Str" + Availability.Required + "String_Node_Str");
        }
        if (createNetwork) {
          if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled) {
            long physicalNetworkId=_networkModel.findPhysicalNetworkId(zoneId,requiredOfferings.get(0).getTags(),requiredOfferings.get(0).getTrafficType());
            PhysicalNetwork physicalNetwork=_physicalNetworkDao.findById(physicalNetworkId);
            if (physicalNetwork == null) {
              throw new InvalidParameterValueException("String_Node_Str" + physicalNetworkId + "String_Node_Str"+ requiredOfferings.get(0).getTags());
            }
            s_logger.debug("String_Node_Str" + owner + "String_Node_Str"+ requiredOfferings.get(0).getId()+ "String_Node_Str");
            guestNetwork=_networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(),owner.getAccountName() + "String_Node_Str",owner.getAccountName() + "String_Node_Str",null,null,null,null,owner,null,physicalNetwork,zoneId,ACLType.Account,null,null,null,null,true,null);
            if (guestNetwork == null) {
              s_logger.warn("String_Node_Str" + accountId + "String_Node_Str"+ zoneId);
              throw new CloudRuntimeException("String_Node_Str" + "String_Node_Str" + accountId + "String_Node_Str"+ zoneId);
            }
          }
 else {
            throw new CloudRuntimeException("String_Node_Str" + requiredOfferings.get(0).getId() + "String_Node_Str"+ NetworkOffering.State.Enabled);
          }
        }
        boolean allocateSourceNat=false;
        List<IPAddressVO> sourceNat=_ipAddressDao.listByAssociatedNetwork(guestNetwork.getId(),true);
        if (sourceNat.isEmpty()) {
          allocateSourceNat=true;
        }
        List<IPAddressVO> ips=_ipAddressDao.listByVlanId(vlanId);
        boolean isSourceNatAllocated=false;
        for (        IPAddressVO addr : ips) {
          if (addr.getState() != State.Allocated) {
            if (!isSourceNatAllocated && allocateSourceNat) {
              addr.setSourceNat(true);
              isSourceNatAllocated=true;
            }
 else {
              addr.setSourceNat(false);
            }
            addr.setAssociatedWithNetworkId(guestNetwork.getId());
            addr.setVpcId(guestNetwork.getVpcId());
            addr.setAllocatedTime(new Date());
            addr.setAllocatedInDomainId(owner.getDomainId());
            addr.setAllocatedToAccountId(owner.getId());
            addr.setSystem(false);
            addr.setState(IpAddress.State.Allocating);
            markPublicIpAsAllocated(addr);
          }
        }
        return new Ternary<Boolean,List<NetworkOfferingVO>,Network>(createNetwork,requiredOfferings,guestNetwork);
      }
    }
);
  }
 catch (  Exception e1) {
    ExceptionUtil.rethrowRuntime(e1);
    ExceptionUtil.rethrow(e1,InsufficientCapacityException.class);
    ExceptionUtil.rethrow(e1,ResourceAllocationException.class);
    throw new IllegalStateException(e1);
  }
  boolean createNetwork=pair.first();
  List<NetworkOfferingVO> requiredOfferings=pair.second();
  Network guestNetwork=pair.third();
  if (createNetwork && requiredOfferings.get(0).getIsPersistent()) {
    DataCenter zone=_dcDao.findById(zoneId);
    DeployDestination dest=new DeployDestination(zone,null,null,null);
    Account callerAccount=CallContext.current().getCallingAccount();
    UserVO callerUser=_userDao.findById(CallContext.current().getCallingUserId());
    Journal journal=new Journal.LogJournal("String_Node_Str" + guestNetwork,s_logger);
    ReservationContext context=new ReservationContextImpl(UUID.randomUUID().toString(),journal,callerUser,callerAccount);
    s_logger.debug("String_Node_Str" + guestNetwork + "String_Node_Str");
    try {
      Pair<? extends NetworkGuru,? extends Network> implementedNetwork=_networkMgr.implementNetwork(guestNetwork.getId(),dest,context);
      if (implementedNetwork == null || implementedNetwork.first() == null) {
        s_logger.warn("String_Node_Str" + guestNetwork);
      }
      if (implementedNetwork != null) {
        guestNetwork=implementedNetwork.second();
      }
    }
 catch (    Exception ex) {
      s_logger.warn("String_Node_Str" + guestNetwork + "String_Node_Str"+ "String_Node_Str",ex);
      CloudRuntimeException e=new CloudRuntimeException("String_Node_Str" + "String_Node_Str");
      e.addProxyObject(guestNetwork.getUuid(),"String_Node_Str");
      throw e;
    }
  }
  return true;
}