Program: 4454
Project: 4454
Buggy source:
private static byte[] derivePayload(UDPCrawlerPing request){
  byte format=(byte)(request.getFormat() & UDPCrawlerPing.FEATURE_MASK);
  List endpointsUP=new LinkedList();
  List endpointsLeaf=new LinkedList();
  Iterator iter=RouterService.getConnectionManager().getInitializedConnections().iterator();
  boolean newOnly=request.hasNewOnly();
  while (iter.hasNext()) {
    Connection c=(Connection)iter.next();
    if (newOnly && c.supportsVendorMessage(VendorMessage.F_LIME_VENDOR_ID,VendorMessage.F_ULTRAPEER_LIST) != -1)     endpointsUP.add(c);
 else     if (c.isGoodUltrapeer())     endpointsUP.add(c);
  }
  iter=RouterService.getConnectionManager().getInitializedClientConnections().iterator();
  while (iter.hasNext()) {
    Connection c=(Connection)iter.next();
    endpointsLeaf.add(c);
  }
  if (!request.hasLocaleInfo()) {
    if (request.getNumberUP() != request.ALL && request.getNumberUP() < endpointsUP.size()) {
      int index=(int)Math.floor(Math.random() * (endpointsUP.size() - request.getNumberUP()));
      endpointsUP=endpointsUP.subList(index,index + request.getNumberUP());
    }
    if (request.getNumberLeaves() != request.ALL && request.getNumberLeaves() < endpointsLeaf.size()) {
      int index=(int)Math.floor(Math.random() * (endpointsLeaf.size() - request.getNumberLeaves()));
      endpointsLeaf=endpointsLeaf.subList(index,index + request.getNumberLeaves());
    }
  }
 else {
    String myLocale=ApplicationSettings.LANGUAGE.getValue();
    List prefedcons=RouterService.getConnectionManager().getInitializedConnectionsMatchLocale(myLocale);
    endpointsUP.removeAll(prefedcons);
    prefedcons.addAll(endpointsUP);
    endpointsUP=prefedcons;
    prefedcons=RouterService.getConnectionManager().getInitializedClientConnectionsMatchLocale(myLocale);
    endpointsLeaf.removeAll(prefedcons);
    prefedcons.addAll(endpointsLeaf);
    endpointsLeaf=prefedcons;
    if (request.getNumberUP() != request.ALL && request.getNumberUP() < endpointsUP.size())     endpointsUP=endpointsUP.subList(0,request.getNumberUP());
    if (request.getNumberLeaves() != request.ALL && request.getNumberLeaves() < endpointsLeaf.size())     endpointsLeaf=endpointsLeaf.subList(0,request.getNumberLeaves());
  }
  int bytesPerResult=6;
  if (request.hasConnectionTime())   bytesPerResult+=2;
  if (request.hasLocaleInfo())   bytesPerResult+=2;
  byte[] result=new byte[(endpointsUP.size() + endpointsLeaf.size()) * bytesPerResult + 3];
  result[0]=(byte)endpointsUP.size();
  result[1]=(byte)endpointsLeaf.size();
  result[2]=format;
  endpointsUP.addAll(endpointsLeaf);
  long now=System.currentTimeMillis();
  int index=3;
  iter=endpointsUP.iterator();
  while (iter.hasNext()) {
    Connection c=(Connection)iter.next();
    System.arraycopy(packIPAddress(c.getInetAddress(),c.getPort()),0,result,index,6);
    index+=6;
    if (request.hasConnectionTime()) {
      long uptime=now - c.getConnectionTime();
      short packed=(short)(uptime / Constants.MINUTE);
      ByteOrder.short2leb(packed,result,index);
      index+=2;
    }
    if (request.hasLocaleInfo()) {
      System.arraycopy(c.getLocalePref().getBytes(),0,result,index,2);
      index+=2;
    }
  }
  return result;
}

Fixed version (ground truth):
private static byte[] derivePayload(UDPCrawlerPing request){
  byte format=(byte)(request.getFormat() & UDPCrawlerPing.FEATURE_MASK);
  List endpointsUP=new LinkedList();
  List endpointsLeaf=new LinkedList();
  Iterator iter=RouterService.getConnectionManager().getInitializedConnections().iterator();
  boolean newOnly=request.hasNewOnly();
  while (iter.hasNext()) {
    Connection c=(Connection)iter.next();
    if (newOnly) {
      if (c.remoteHostSupportsUDPCrawling() >= 1)       endpointsUP.add(c);
    }
 else     if (c.isGoodUltrapeer())     endpointsUP.add(c);
  }
  iter=RouterService.getConnectionManager().getInitializedClientConnections().iterator();
  while (iter.hasNext()) {
    Connection c=(Connection)iter.next();
    endpointsLeaf.add(c);
  }
  if (!request.hasLocaleInfo()) {
    if (request.getNumberUP() != request.ALL && request.getNumberUP() < endpointsUP.size()) {
      int index=(int)Math.floor(Math.random() * (endpointsUP.size() - request.getNumberUP()));
      endpointsUP=endpointsUP.subList(index,index + request.getNumberUP());
    }
    if (request.getNumberLeaves() != request.ALL && request.getNumberLeaves() < endpointsLeaf.size()) {
      int index=(int)Math.floor(Math.random() * (endpointsLeaf.size() - request.getNumberLeaves()));
      endpointsLeaf=endpointsLeaf.subList(index,index + request.getNumberLeaves());
    }
  }
 else {
    String myLocale=ApplicationSettings.LANGUAGE.getValue();
    List prefedcons=RouterService.getConnectionManager().getInitializedConnectionsMatchLocale(myLocale);
    endpointsUP.removeAll(prefedcons);
    prefedcons.addAll(endpointsUP);
    endpointsUP=prefedcons;
    prefedcons=RouterService.getConnectionManager().getInitializedClientConnectionsMatchLocale(myLocale);
    endpointsLeaf.removeAll(prefedcons);
    prefedcons.addAll(endpointsLeaf);
    endpointsLeaf=prefedcons;
    if (request.getNumberUP() != request.ALL && request.getNumberUP() < endpointsUP.size())     endpointsUP=endpointsUP.subList(0,request.getNumberUP());
    if (request.getNumberLeaves() != request.ALL && request.getNumberLeaves() < endpointsLeaf.size())     endpointsLeaf=endpointsLeaf.subList(0,request.getNumberLeaves());
  }
  int bytesPerResult=6;
  if (request.hasConnectionTime())   bytesPerResult+=2;
  if (request.hasLocaleInfo())   bytesPerResult+=2;
  byte[] result=new byte[(endpointsUP.size() + endpointsLeaf.size()) * bytesPerResult + 3];
  result[0]=(byte)endpointsUP.size();
  result[1]=(byte)endpointsLeaf.size();
  result[2]=format;
  endpointsUP.addAll(endpointsLeaf);
  long now=System.currentTimeMillis();
  int index=3;
  iter=endpointsUP.iterator();
  while (iter.hasNext()) {
    Connection c=(Connection)iter.next();
    System.arraycopy(packIPAddress(c.getInetAddress(),c.getPort()),0,result,index,6);
    index+=6;
    if (request.hasConnectionTime()) {
      long uptime=now - c.getConnectionTime();
      short packed=(short)(uptime / Constants.MINUTE);
      ByteOrder.short2leb(packed,result,index);
      index+=2;
    }
    if (request.hasLocaleInfo()) {
      System.arraycopy(c.getLocalePref().getBytes(),0,result,index,2);
      index+=2;
    }
  }
  return result;
}