Program: 106952
Project: 106952
Buggy source:
private void createAssociateIPCommands(final DomainRouterVO router,final List<? extends PublicIpAddress> ips,Commands cmds,long vmId){
  Map<String,ArrayList<PublicIpAddress>> vlanIpMap=new HashMap<String,ArrayList<PublicIpAddress>>();
  for (  final PublicIpAddress ipAddress : ips) {
    String vlanTag=ipAddress.getVlanTag();
    ArrayList<PublicIpAddress> ipList=vlanIpMap.get(vlanTag);
    if (ipList == null) {
      ipList=new ArrayList<PublicIpAddress>();
    }
    ipList.add(ipAddress);
    vlanIpMap.put(vlanTag,ipList);
  }
  for (  Map.Entry<String,ArrayList<PublicIpAddress>> vlanAndIp : vlanIpMap.entrySet()) {
    List<PublicIpAddress> ipAddrList=vlanAndIp.getValue();
    Collections.sort(ipAddrList,new Comparator<PublicIpAddress>(){
      @Override public int compare(      PublicIpAddress o1,      PublicIpAddress o2){
        boolean s1=o1.isSourceNat();
        boolean s2=o2.isSourceNat();
        return (s1 ^ s2) ? ((s1 ^ true) ? 1 : -1) : 0;
      }
    }
);
    IpAddressTO[] ipsToSend=new IpAddressTO[ipAddrList.size()];
    int i=0;
    boolean firstIP=true;
    for (    final PublicIpAddress ipAddr : ipAddrList) {
      boolean add=(ipAddr.getState() == IpAddress.State.Releasing ? false : true);
      boolean sourceNat=ipAddr.isSourceNat();
      String vlanId=ipAddr.getVlanTag();
      String vlanGateway=ipAddr.getGateway();
      String vlanNetmask=ipAddr.getNetmask();
      String vifMacAddress=ipAddr.getMacAddress();
      String vmGuestAddress=null;
      Integer networkRate=_networkMgr.getNetworkRate(ipAddr.getNetworkId(),null);
      IpAddressTO ip=new IpAddressTO(ipAddr.getAddress().addr(),add,firstIP,sourceNat,vlanId,vlanGateway,vlanNetmask,vifMacAddress,vmGuestAddress,networkRate);
      ipsToSend[i++]=ip;
      firstIP=false;
    }
    IPAssocCommand cmd=new IPAssocCommand(ipsToSend);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP,router.getPrivateIpAddress());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP,router.getGuestIpAddress());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME,router.getInstanceName());
    DataCenterVO dcVo=_dcDao.findById(router.getDataCenterIdToDeployIn());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE,dcVo.getNetworkType().toString());
    cmds.addCommand("String_Node_Str",cmd);
  }
}

Fixed version (ground truth):
private void createAssociateIPCommands(final DomainRouterVO router,final List<? extends PublicIpAddress> ips,Commands cmds,long vmId){
  Map<String,ArrayList<PublicIpAddress>> vlanIpMap=new HashMap<String,ArrayList<PublicIpAddress>>();
  for (  final PublicIpAddress ipAddress : ips) {
    String vlanTag=ipAddress.getVlanTag();
    ArrayList<PublicIpAddress> ipList=vlanIpMap.get(vlanTag);
    if (ipList == null) {
      ipList=new ArrayList<PublicIpAddress>();
    }
    ipList.add(ipAddress);
    vlanIpMap.put(vlanTag,ipList);
  }
  for (  Map.Entry<String,ArrayList<PublicIpAddress>> vlanAndIp : vlanIpMap.entrySet()) {
    List<PublicIpAddress> ipAddrList=vlanAndIp.getValue();
    Collections.sort(ipAddrList,new Comparator<PublicIpAddress>(){
      @Override public int compare(      PublicIpAddress o1,      PublicIpAddress o2){
        boolean s1=o1.isSourceNat();
        boolean s2=o2.isSourceNat();
        return (s1 ^ s2) ? ((s1 ^ true) ? 1 : -1) : 0;
      }
    }
);
    IpAddressTO[] ipsToSend=new IpAddressTO[ipAddrList.size()];
    int i=0;
    boolean firstIP=true;
    for (    final PublicIpAddress ipAddr : ipAddrList) {
      boolean add=(ipAddr.getState() == IpAddress.State.Releasing ? false : true);
      boolean sourceNat=ipAddr.isSourceNat();
      String vlanId=ipAddr.getVlanTag();
      String vlanGateway=ipAddr.getGateway();
      String vlanNetmask=ipAddr.getNetmask();
      String vifMacAddress=ipAddr.getMacAddress();
      String vmGuestAddress=null;
      Integer networkRate=_networkMgr.getNetworkRate(ipAddr.getNetworkId(),router.getId());
      IpAddressTO ip=new IpAddressTO(ipAddr.getAddress().addr(),add,firstIP,sourceNat,vlanId,vlanGateway,vlanNetmask,vifMacAddress,vmGuestAddress,networkRate);
      ipsToSend[i++]=ip;
      firstIP=false;
    }
    IPAssocCommand cmd=new IPAssocCommand(ipsToSend);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP,router.getPrivateIpAddress());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP,router.getGuestIpAddress());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME,router.getInstanceName());
    DataCenterVO dcVo=_dcDao.findById(router.getDataCenterIdToDeployIn());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE,dcVo.getNetworkType().toString());
    cmds.addCommand("String_Node_Str",cmd);
  }
}