Program: 105103
Project: 105103
Buggy source:
public void createVpcAssociatePublicIPCommands(final VirtualRouter router,final List<? extends PublicIpAddress> ips,final Commands cmds,final Map<String,String> vlanMacAddress){
  final String ipAssocCommand="String_Node_Str";
  if (router.getIsRedundantRouter()) {
    createRedundantAssociateIPCommands(router,ips,cmds,ipAssocCommand,0);
    return;
  }
  Pair<IpAddressTO,Long> sourceNatIpAdd=null;
  Boolean addSourceNat=null;
  final Map<String,ArrayList<PublicIpAddress>> vlanIpMap=new HashMap<String,ArrayList<PublicIpAddress>>();
  for (  final PublicIpAddress ipAddress : ips) {
    final String vlanTag=ipAddress.getVlanTag();
    ArrayList<PublicIpAddress> ipList=vlanIpMap.get(vlanTag);
    if (ipList == null) {
      ipList=new ArrayList<PublicIpAddress>();
    }
    if (ipAddress.isSourceNat() && ipAddress.getState() == IpAddress.State.Releasing) {
      ipAddress.setState(IpAddress.State.Allocated);
    }
    ipList.add(ipAddress);
    vlanIpMap.put(vlanTag,ipList);
  }
  for (  final Map.Entry<String,ArrayList<PublicIpAddress>> vlanAndIp : vlanIpMap.entrySet()) {
    final List<PublicIpAddress> ipAddrList=vlanAndIp.getValue();
    final Integer networkRate=_networkModel.getNetworkRate(ipAddrList.get(0).getNetworkId(),router.getId());
    final Network network=_networkModel.getNetwork(ipAddrList.get(0).getNetworkId());
    final IpAddressTO[] ipsToSend=new IpAddressTO[ipAddrList.size()];
    int i=0;
    for (    final PublicIpAddress ipAddr : ipAddrList) {
      final boolean add=ipAddr.getState() == IpAddress.State.Releasing ? false : true;
      final String macAddress=vlanMacAddress.get(BroadcastDomainType.getValue(BroadcastDomainType.fromString(ipAddr.getVlanTag())));
      final IpAddressTO ip=new IpAddressTO(ipAddr.getAccountId(),ipAddr.getAddress().addr(),add,false,ipAddr.isSourceNat(),BroadcastDomainType.fromString(ipAddr.getVlanTag()).toString(),ipAddr.getGateway(),ipAddr.getNetmask(),macAddress,networkRate,ipAddr.isOneToOneNat());
      ip.setTrafficType(network.getTrafficType());
      ip.setNetworkName(_networkModel.getNetworkTag(router.getHypervisorType(),network));
      ipsToSend[i++]=ip;
      if (ipAddr.isSourceNat()) {
        sourceNatIpAdd=new Pair<IpAddressTO,Long>(ip,ipAddr.getNetworkId());
        addSourceNat=add;
      }
    }
    final IpAssocVpcCommand cmd=new IpAssocVpcCommand(ipsToSend);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP,_routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP,_routerControlHelper.getRouterIpInNetwork(ipAddrList.get(0).getNetworkId(),router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME,router.getInstanceName());
    final DataCenterVO dcVo=_dcDao.findById(router.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE,dcVo.getNetworkType().toString());
    cmds.addCommand(ipAssocCommand,cmd);
  }
  if (sourceNatIpAdd != null) {
    final IpAddressTO sourceNatIp=sourceNatIpAdd.first();
    final SetSourceNatCommand cmd=new SetSourceNatCommand(sourceNatIp,addSourceNat);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP,_routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME,router.getInstanceName());
    final DataCenterVO dcVo=_dcDao.findById(router.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE,dcVo.getNetworkType().toString());
    cmds.addCommand("String_Node_Str",cmd);
  }
}

Fixed version (ground truth):
public void createVpcAssociatePublicIPCommands(final VirtualRouter router,final List<? extends PublicIpAddress> ips,final Commands cmds,final Map<String,String> vlanMacAddress){
  final String ipAssocCommand="String_Node_Str";
  if (router.getIsRedundantRouter()) {
    createRedundantAssociateIPCommands(router,ips,cmds,ipAssocCommand,0);
    return;
  }
  Pair<IpAddressTO,Long> sourceNatIpAdd=null;
  Boolean addSourceNat=null;
  final Map<String,ArrayList<PublicIpAddress>> vlanIpMap=new HashMap<String,ArrayList<PublicIpAddress>>();
  for (  final PublicIpAddress ipAddress : ips) {
    final String vlanTag=ipAddress.getVlanTag();
    ArrayList<PublicIpAddress> ipList=vlanIpMap.get(vlanTag);
    if (ipList == null) {
      ipList=new ArrayList<PublicIpAddress>();
    }
    if (ipAddress.isSourceNat() && ipAddress.getState() == IpAddress.State.Releasing) {
      ipAddress.setState(IpAddress.State.Allocated);
    }
    ipList.add(ipAddress);
    vlanIpMap.put(vlanTag,ipList);
  }
  for (  final Map.Entry<String,ArrayList<PublicIpAddress>> vlanAndIp : vlanIpMap.entrySet()) {
    final List<PublicIpAddress> ipAddrList=vlanAndIp.getValue();
    Collections.sort(ipAddrList,new Comparator<PublicIpAddress>(){
      @Override public int compare(      final PublicIpAddress o1,      final PublicIpAddress o2){
        final boolean s1=o1.isSourceNat();
        final boolean s2=o2.isSourceNat();
        return s1 ^ s2 ? s1 ^ true ? 1 : -1 : 0;
      }
    }
);
    final Integer networkRate=_networkModel.getNetworkRate(ipAddrList.get(0).getNetworkId(),router.getId());
    final Network network=_networkModel.getNetwork(ipAddrList.get(0).getNetworkId());
    final IpAddressTO[] ipsToSend=new IpAddressTO[ipAddrList.size()];
    int i=0;
    boolean firstIP=true;
    for (    final PublicIpAddress ipAddr : ipAddrList) {
      final boolean add=ipAddr.getState() == IpAddress.State.Releasing ? false : true;
      boolean sourceNat=ipAddr.isSourceNat();
      if (firstIP) {
        sourceNat=true;
      }
      final String macAddress=vlanMacAddress.get(BroadcastDomainType.getValue(BroadcastDomainType.fromString(ipAddr.getVlanTag())));
      final IpAddressTO ip=new IpAddressTO(ipAddr.getAccountId(),ipAddr.getAddress().addr(),add,firstIP,sourceNat,BroadcastDomainType.fromString(ipAddr.getVlanTag()).toString(),ipAddr.getGateway(),ipAddr.getNetmask(),macAddress,networkRate,ipAddr.isOneToOneNat());
      ip.setTrafficType(network.getTrafficType());
      ip.setNetworkName(_networkModel.getNetworkTag(router.getHypervisorType(),network));
      ipsToSend[i++]=ip;
      if (ipAddr.isSourceNat()) {
        sourceNatIpAdd=new Pair<IpAddressTO,Long>(ip,ipAddr.getNetworkId());
        addSourceNat=add;
      }
      if (!firstIP || add) {
        firstIP=false;
      }
    }
    final IpAssocVpcCommand cmd=new IpAssocVpcCommand(ipsToSend);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP,_routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP,_routerControlHelper.getRouterIpInNetwork(ipAddrList.get(0).getNetworkId(),router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME,router.getInstanceName());
    final DataCenterVO dcVo=_dcDao.findById(router.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE,dcVo.getNetworkType().toString());
    cmds.addCommand(ipAssocCommand,cmd);
  }
  if (sourceNatIpAdd != null) {
    final IpAddressTO sourceNatIp=sourceNatIpAdd.first();
    final SetSourceNatCommand cmd=new SetSourceNatCommand(sourceNatIp,addSourceNat);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP,_routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME,router.getInstanceName());
    final DataCenterVO dcVo=_dcDao.findById(router.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE,dcVo.getNetworkType().toString());
    cmds.addCommand("String_Node_Str",cmd);
  }
}