nus-yam/ex-repair huggingface dataset:
Program: 4666
Project: 4666
Buggy source:
/** 
 * Obtains the time to wait for probe results to return.
 * @return the time to wait for this probe to complete, inmilliseconds
 */
long getTimeToWait(){
  if (!TTL_2_PROBES.isEmpty())   return (long)((double)QueryHandler.TIME_TO_WAIT_PER_HOP * 1.8);
  if (!TTL_1_PROBES.isEmpty())   return (long)((double)QueryHandler.TIME_TO_WAIT_PER_HOP * 2.0 * (double)TTL_1_PROBES.size());
  return 0L;
}

Fixed version (ground truth):
/** 
 * Obtains the time to wait for probe results to return.
 * @return the time to wait for this probe to complete, inmilliseconds
 */
long getTimeToWait(){
  if (!TTL_2_PROBES.isEmpty())   return (long)((double)QUERY_HANDLER.getTimeToWaitPerHop() * 1.8);
  if (!TTL_1_PROBES.isEmpty())   return (long)((double)QUERY_HANDLER.getTimeToWaitPerHop() * 2.0 * (double)TTL_1_PROBES.size());
  return 0L;
}
Program: 4667
Project: 4667
Buggy source:
/** 
 * Compares this to another interval by the 'low' element of the interval. If the low elements are the same, then the high element is compared.
 */
public int compareTo(Object o){
  Interval other=(Interval)o;
  if (this.low == other.low)   return this.low - other.low;
 else   return this.high - other.high;
}

Fixed version (ground truth):
/** 
 * Compares this to another interval by the 'low' element of the interval. If the low elements are the same, then the high element is compared.
 */
public int compareTo(Object o){
  Interval other=(Interval)o;
  if (this.low != other.low)   return this.low - other.low;
 else   return this.high - other.high;
}
Program: 4668
Project: 4668
Buggy source:
public void close(){
  if (fos == null)   return;
  try {
    fos.close();
  }
 catch (  IOException ioe) {
  }
}

Fixed version (ground truth):
public void close(){
  managedDownloader=null;
  if (fos == null)   return;
  try {
    fos.close();
  }
 catch (  IOException ioe) {
  }
}
Program: 4669
Project: 4669
Buggy source:
/** 
 * Accessor for the SHA1 URN for this <tt>RemoteFileDesc</tt>.
 * @return the SHA1 <tt>URN</tt> for this <tt>RemoteFileDesc</tt>, or <tt>null</tt> if there is none
 */
public final URN getSHA1Urn(){
  Iterator iter=_urns.iterator();
  while (iter.hasNext()) {
    URN urn=(URN)iter.next();
    if (urn.isSHA1()) {
      return urn;
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Accessor for the SHA1 URN for this <tt>RemoteFileDesc</tt>.
 * @return the SHA1 <tt>URN</tt> for this <tt>RemoteFileDesc</tt>, or <tt>null</tt> if there is none
 */
public final URN getSHA1Urn(){
  Iterator iter=_urns.iterator();
  while (iter.hasNext()) {
    URN urn=(URN)iter.next();
    if (urn == null)     continue;
    if (urn.isSHA1()) {
      return urn;
    }
  }
  return null;
}
Program: 4670
Project: 4670
Buggy source:
/** 
 * Test read & write of map
 */
public void testPersistence() throws Exception {
  assertTrue("String_Node_Str",!cacheExists());
  UrnCache cache=UrnCache.instance();
  FileDesc[] descs=createFileDescs();
  assertNotNull("String_Node_Str",descs);
  assertGreaterThan("String_Node_Str",0,descs.length);
  assertTrue("String_Node_Str",!cacheExists());
  cache.persistCache();
  assertTrue("String_Node_Str",cacheExists());
  for (int i=0; i < descs.length; i++) {
    Set set=cache.getUrns(descs[i].getFile());
    assertTrue("String_Node_Str",!set.equals(CommonUtils.EMPTY_SET));
    assertTrue("String_Node_Str",!set.isEmpty());
    assertEquals("String_Node_Str",descs[i].getUrns(),set);
  }
}

Fixed version (ground truth):
/** 
 * Test read & write of map
 */
public void testPersistence() throws Exception {
  assertTrue("String_Node_Str",!cacheExists());
  UrnCache cache=UrnCache.instance();
  FileDesc[] descs=createFileDescs();
  assertNotNull("String_Node_Str",descs);
  assertGreaterThan("String_Node_Str",0,descs.length);
  assertTrue("String_Node_Str",!cacheExists());
  cache.persistCache();
  assertTrue("String_Node_Str",cacheExists());
  for (int i=0; i < descs.length; i++) {
    Set set=cache.getUrns(descs[i].getFile());
    assertTrue("String_Node_Str",!set.equals(EMPTY_SET));
    assertTrue("String_Node_Str",!set.isEmpty());
    assertEquals("String_Node_Str",descs[i].getUrns(),set);
  }
}
Program: 4671
Project: 4671
Buggy source:
/** 
 * Implements the <tt>HTTPHeaderValue</tt> interface. This adds randomness to the order in which alternate locations are reported and only reports 10 locations.
 * @return an HTTP-compliant string of alternate locations, delimitedby commas, or the empty string if there are no alternate locations to report
 */
public String httpStringValue(){
  List list=new LinkedList(LOCATIONS);
  list=list.subList(0,list.size() >= 10 ? 10 : list.size());
  Iterator iter=list.iterator();
  final String commaSpace="String_Node_Str";
  StringBuffer writeBuffer=new StringBuffer();
  while (iter.hasNext()) {
    writeBuffer.append(((HTTPHeaderValue)iter.next()).httpStringValue());
    if (iter.hasNext()) {
      writeBuffer.append(commaSpace);
    }
  }
  return writeBuffer.toString();
}

Fixed version (ground truth):
/** 
 * Implements the <tt>HTTPHeaderValue</tt> interface. This adds randomness to the order in which alternate locations are reported and only reports 10 locations.
 * @return an HTTP-compliant string of alternate locations, delimitedby commas, or the empty string if there are no alternate locations to report
 */
public String httpStringValue(){
  List list=null;
synchronized (LOCATIONS) {
    list=new LinkedList(LOCATIONS);
  }
  list=list.subList(0,list.size() >= 10 ? 10 : list.size());
  Iterator iter=list.iterator();
  final String commaSpace="String_Node_Str";
  StringBuffer writeBuffer=new StringBuffer();
  while (iter.hasNext()) {
    writeBuffer.append(((HTTPHeaderValue)iter.next()).httpStringValue());
    if (iter.hasNext()) {
      writeBuffer.append(commaSpace);
    }
  }
  return writeBuffer.toString();
}
Program: 4672
Project: 4672
Buggy source:
/** 
 * Creates a HandshakeResponse with the desired status code, status message,  and headers to respond with.
 * @param code the response code to use.
 * @param message the response message to use.
 * @param headers the headers to use in the response.
 */
HandshakeResponse(int code,String message,Properties headers){
  STATUS_CODE=code;
  STATUS_MESSAGE=message;
  HEADERS=Collections.unmodifiableMap(headers);
  DEGREE=extractIntHeaderValue(HEADERS,HeaderNames.X_DEGREE,6);
  HIGH_DEGREE=getNumIntraUltrapeerConnections() >= 15;
  ULTRAPEER_QRP=isVersionOrHigher(HEADERS,HeaderNames.X_ULTRAPEER_QUERY_ROUTING,0.1F);
  MAX_TTL=extractByteHeaderValue(HEADERS,HeaderNames.X_MAX_TTL,(byte)5);
  DYNAMIC_QUERY=isVersionOrHigher(HEADERS,HeaderNames.X_DYNAMIC_QUERY,0.1F);
  GOOD=isHighDegreeConnection() && isUltrapeerQueryRoutingConnection() && (getMaxTTL() < 5)&& isDynamicQueryConnection();
  ULTRAPEER=isTrueValue(HEADERS,HeaderNames.X_ULTRAPEER);
  LEAF=isFalseValue(HEADERS,HeaderNames.X_ULTRAPEER);
}

Fixed version (ground truth):
/** 
 * Creates a HandshakeResponse with the desired status code, status message,  and headers to respond with.
 * @param code the response code to use.
 * @param message the response message to use.
 * @param headers the headers to use in the response.
 */
HandshakeResponse(int code,String message,Properties headers){
  STATUS_CODE=code;
  STATUS_MESSAGE=message;
  HEADERS=headers;
  DEGREE=extractIntHeaderValue(HEADERS,HeaderNames.X_DEGREE,6);
  HIGH_DEGREE=getNumIntraUltrapeerConnections() >= 15;
  ULTRAPEER_QRP=isVersionOrHigher(HEADERS,HeaderNames.X_ULTRAPEER_QUERY_ROUTING,0.1F);
  MAX_TTL=extractByteHeaderValue(HEADERS,HeaderNames.X_MAX_TTL,(byte)5);
  DYNAMIC_QUERY=isVersionOrHigher(HEADERS,HeaderNames.X_DYNAMIC_QUERY,0.1F);
  GOOD=isHighDegreeConnection() && isUltrapeerQueryRoutingConnection() && (getMaxTTL() < 5)&& isDynamicQueryConnection();
  ULTRAPEER=isTrueValue(HEADERS,HeaderNames.X_ULTRAPEER);
  LEAF=isFalseValue(HEADERS,HeaderNames.X_ULTRAPEER);
}
Program: 4673
Project: 4673
Buggy source:
public void testProbeIsTTL1Only() throws Exception {
  for (int i=2; i < 5; i++) {
    drainAll();
    QueryRequest request=QueryRequest.createQuery("String_Node_Str");
    request.setTTL((byte)i);
    ULTRAPEER_2.send(request);
    ULTRAPEER_2.flush();
    QueryRequest reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
    assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
    assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
    reqRecvd=(QueryRequest)ULTRAPEER_1.receive(TIMEOUT);
    assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
    assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
    assertEquals(reqRecvd.getHops(),(byte)1);
    Thread.sleep(2 * 1000);
    request.setTTL((byte)(i + 1));
    ULTRAPEER_2.send(request);
    ULTRAPEER_2.flush();
    try {
      LEAF.receive(TIMEOUT);
      assertTrue(false);
    }
 catch (    InterruptedIOException expected) {
    }
    try {
      ULTRAPEER_1.receive(TIMEOUT);
      assertTrue(false);
    }
 catch (    InterruptedIOException expected) {
    }
  }
}

Fixed version (ground truth):
public void testProbeIsTTL1Only() throws Exception {
  for (int i=2; i < 5; i++) {
    drainAll();
    QueryRequest request=QueryRequest.createQuery("String_Node_Str");
    request.setTTL((byte)i);
    ULTRAPEER_2.send(request);
    ULTRAPEER_2.flush();
    QueryRequest reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
    assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
    assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
    reqRecvd=getFirstQueryRequest(ULTRAPEER_1);
    assertTrue(reqRecvd != null);
    assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
    assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
    assertEquals(reqRecvd.getHops(),(byte)1);
    Thread.sleep(2 * 1000);
    request.setTTL((byte)(i + 1));
    ULTRAPEER_2.send(request);
    ULTRAPEER_2.flush();
    try {
      LEAF.receive(TIMEOUT);
      assertTrue(false);
    }
 catch (    InterruptedIOException expected) {
    }
    assertTrue(noUnexpectedMessages(ULTRAPEER_1));
  }
}
Program: 4674
Project: 4674
Buggy source:
public void testDuplicateProbes() throws Exception {
  drainAll();
  QueryRequest request=QueryRequest.createQuery("String_Node_Str");
  request.setTTL((byte)1);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  QueryRequest reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  try {
    ULTRAPEER_1.receive(TIMEOUT);
    assertTrue(false);
  }
 catch (  InterruptedIOException expected) {
  }
  Thread.sleep(2 * 1000);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  try {
    reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
  }
 catch (  InterruptedIOException expected) {
  }
  try {
    ULTRAPEER_1.receive(TIMEOUT);
    assertTrue(false);
  }
 catch (  InterruptedIOException expected) {
  }
}

Fixed version (ground truth):
public void testDuplicateProbes() throws Exception {
  drainAll();
  QueryRequest request=QueryRequest.createQuery("String_Node_Str");
  request.setTTL((byte)1);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  QueryRequest reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  assertTrue(noUnexpectedMessages(ULTRAPEER_1));
  Thread.sleep(2 * 1000);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  try {
    reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
  }
 catch (  InterruptedIOException expected) {
  }
  assertTrue(noUnexpectedMessages(ULTRAPEER_1));
}
Program: 4675
Project: 4675
Buggy source:
public void testBasicProbeMechanicsFromUltrapeer() throws Exception {
  drainAll();
  QueryRequest request=QueryRequest.createQuery("String_Node_Str");
  request.setTTL((byte)1);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  QueryRequest reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  try {
    ULTRAPEER_1.receive(TIMEOUT);
    assertTrue(false);
  }
 catch (  InterruptedIOException expected) {
  }
  Response response1=new Response(0L,0L,"String_Node_Str");
  byte[] guid1=GUID.makeGuid();
  QueryReply reply1=new QueryReply(request.getGUID(),(byte)2,6346,new byte[4],56,new Response[]{response1},guid1,false);
  drain(ULTRAPEER_2);
  LEAF.send(reply1);
  LEAF.flush();
  QueryReply qRep=(QueryReply)ULTRAPEER_2.receive(TIMEOUT);
  assertEquals(new GUID(guid1),new GUID(qRep.getClientGUID()));
  Thread.sleep(2 * 1000);
  request.setTTL((byte)2);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  try {
    LEAF.receive(TIMEOUT);
    assertTrue(false);
  }
 catch (  InterruptedIOException expected) {
  }
  reqRecvd=(QueryRequest)ULTRAPEER_1.receive(TIMEOUT);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  assertEquals(reqRecvd.getHops(),(byte)1);
}

Fixed version (ground truth):
public void testBasicProbeMechanicsFromUltrapeer() throws Exception {
  drainAll();
  QueryRequest request=QueryRequest.createQuery("String_Node_Str");
  request.setTTL((byte)1);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  QueryRequest reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  assertTrue(noUnexpectedMessages(ULTRAPEER_1));
  Response response1=new Response(0L,0L,"String_Node_Str");
  byte[] guid1=GUID.makeGuid();
  QueryReply reply1=new QueryReply(request.getGUID(),(byte)2,6346,new byte[4],56,new Response[]{response1},guid1,false);
  drain(ULTRAPEER_2);
  LEAF.send(reply1);
  LEAF.flush();
  QueryReply qRep=getFirstQueryReply(ULTRAPEER_2);
  assertTrue(qRep != null);
  assertEquals(new GUID(guid1),new GUID(qRep.getClientGUID()));
  Thread.sleep(2 * 1000);
  request.setTTL((byte)2);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  try {
    LEAF.receive(TIMEOUT);
    assertTrue(false);
  }
 catch (  InterruptedIOException expected) {
  }
  reqRecvd=getFirstQueryRequest(ULTRAPEER_1);
  assertTrue(reqRecvd != null);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  assertEquals(reqRecvd.getHops(),(byte)1);
}
Program: 4676
Project: 4676
Buggy source:
public void testProbeIsLimited() throws Exception {
  drainAll();
  QueryRequest request=QueryRequest.createQuery("String_Node_Str");
  request.setTTL((byte)1);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  QueryRequest reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  try {
    ULTRAPEER_1.receive(TIMEOUT);
    assertTrue(false);
  }
 catch (  InterruptedIOException expected) {
  }
  Thread.sleep(2 * 1000);
  request.setTTL((byte)3);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  try {
    LEAF.receive(TIMEOUT);
    assertTrue(false);
  }
 catch (  InterruptedIOException expected) {
  }
  reqRecvd=(QueryRequest)ULTRAPEER_1.receive(TIMEOUT);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  assertEquals(reqRecvd.getHops(),(byte)1);
  Thread.sleep(2 * 1000);
  request.setTTL((byte)4);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  try {
    reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
  }
 catch (  InterruptedIOException expected) {
  }
  try {
    ULTRAPEER_1.receive(TIMEOUT);
    assertTrue(false);
  }
 catch (  InterruptedIOException expected) {
  }
}

Fixed version (ground truth):
public void testProbeIsLimited() throws Exception {
  drainAll();
  QueryRequest request=QueryRequest.createQuery("String_Node_Str");
  request.setTTL((byte)1);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  QueryRequest reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  assertTrue(noUnexpectedMessages(ULTRAPEER_1));
  Thread.sleep(2 * 1000);
  request.setTTL((byte)3);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  try {
    LEAF.receive(TIMEOUT);
    assertTrue(false);
  }
 catch (  InterruptedIOException expected) {
  }
  reqRecvd=getFirstQueryRequest(ULTRAPEER_1);
  assertTrue(reqRecvd != null);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  assertEquals(reqRecvd.getHops(),(byte)1);
  Thread.sleep(2 * 1000);
  request.setTTL((byte)4);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  try {
    reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
  }
 catch (  InterruptedIOException expected) {
  }
  assertTrue(noUnexpectedMessages(ULTRAPEER_1));
}
Program: 4677
Project: 4677
Buggy source:
public void testBasicProbeMechanicsFromLeaf() throws Exception {
  drainAll();
  QueryRequest request=QueryRequest.createQuery("String_Node_Str");
  request.hop();
  request.setTTL((byte)1);
  assertTrue((request.getHops() == 1));
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  QueryRequest reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  try {
    ULTRAPEER_1.receive(TIMEOUT);
    assertTrue(false);
  }
 catch (  InterruptedIOException expected) {
  }
  Response response1=new Response(0L,0L,"String_Node_Str");
  byte[] guid1=GUID.makeGuid();
  QueryReply reply1=new QueryReply(request.getGUID(),(byte)2,6346,new byte[4],56,new Response[]{response1},guid1,false);
  drain(ULTRAPEER_2);
  LEAF.send(reply1);
  LEAF.flush();
  QueryReply qRep=(QueryReply)ULTRAPEER_2.receive(TIMEOUT);
  assertEquals(new GUID(guid1),new GUID(qRep.getClientGUID()));
  Thread.sleep(2 * 1000);
  request.setTTL((byte)2);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  try {
    LEAF.receive(TIMEOUT);
    assertTrue(false);
  }
 catch (  InterruptedIOException expected) {
  }
  reqRecvd=(QueryRequest)ULTRAPEER_1.receive(TIMEOUT);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  assertEquals(reqRecvd.getHops(),(byte)2);
}

Fixed version (ground truth):
public void testBasicProbeMechanicsFromLeaf() throws Exception {
  drainAll();
  QueryRequest request=QueryRequest.createQuery("String_Node_Str");
  request.hop();
  request.setTTL((byte)1);
  assertTrue((request.getHops() == 1));
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  QueryRequest reqRecvd=(QueryRequest)LEAF.receive(TIMEOUT);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  assertTrue(noUnexpectedMessages(ULTRAPEER_1));
  Response response1=new Response(0L,0L,"String_Node_Str");
  byte[] guid1=GUID.makeGuid();
  QueryReply reply1=new QueryReply(request.getGUID(),(byte)2,6346,new byte[4],56,new Response[]{response1},guid1,false);
  drain(ULTRAPEER_2);
  LEAF.send(reply1);
  LEAF.flush();
  QueryReply qRep=getFirstQueryReply(ULTRAPEER_2);
  assertTrue(qRep != null);
  assertEquals(new GUID(guid1),new GUID(qRep.getClientGUID()));
  Thread.sleep(2 * 1000);
  request.setTTL((byte)2);
  ULTRAPEER_2.send(request);
  ULTRAPEER_2.flush();
  try {
    LEAF.receive(TIMEOUT);
    assertTrue(false);
  }
 catch (  InterruptedIOException expected) {
  }
  reqRecvd=getFirstQueryRequest(ULTRAPEER_1);
  assertTrue(reqRecvd != null);
  assertTrue(reqRecvd.getQuery().equals("String_Node_Str"));
  assertTrue(Arrays.equals(request.getGUID(),reqRecvd.getGUID()));
  assertEquals(reqRecvd.getHops(),(byte)2);
}
Program: 4679
Project: 4679
Buggy source:
/** 
 * Overrides ManagedDownloader to display a reasonable file name even when no locations have been found.
 */
public synchronized String getFileName(){
  if (_filename != null)   return _filename;
 else {
    String fname=super.getFileName();
    if (fname == null || fname.equals(UNKNOWN_FILENAME))     fname=getFileNameHint();
    return fname;
  }
}

Fixed version (ground truth):
/** 
 * Overrides ManagedDownloader to display a reasonable file name even when no locations have been found.
 */
public synchronized String getFileName(){
  if (_filename != null)   return _filename;
 else {
    String fname=null;
    if (hasRFD())     fname=super.getFileName();
    if (fname == null || fname.equals(UNKNOWN_FILENAME))     fname=getFileNameHint();
    return fname;
  }
}
Program: 4680
Project: 4680
Buggy source:
/** 
 * The number of bytes read. The way we calculate the number of bytes  read is a little wierd if the range header begins from the middle of  the file (say from byte x). Then we consider that bytes 0-x have  already been read.  <p> This may lead to some wierd behaviour with chunking. For example if  a host requests the last 10% of a file, the GUI will display 90% downloaded. Later if the same host requests from 20% to 30% the  progress will reduce to 20% onwards.  Implements the Uploader interface.
 */
public int amountUploaded(){
  return _amountRead;
}

Fixed version (ground truth):
/** 
 * The amount of bytes that this upload has transferred. Implements the Uploader interface.
 */
public int amountUploaded(){
  return _amountRead;
}
Program: 4681
Project: 4681
Buggy source:
public void measureBandwidth(){
  bandwidthTracker.measureBandwidth(amountUploaded());
}

Fixed version (ground truth):
public void measureBandwidth(){
  bandwidthTracker.measureBandwidth(getTotalAmountUploaded());
}
Program: 4683
Project: 4683
Buggy source:
public void measureBandwidth(){
  bandwidthTracker.measureBandwidth(getAmountRead());
}

Fixed version (ground truth):
public void measureBandwidth(){
  bandwidthTracker.measureBandwidth(getTotalAmountRead());
}
Program: 4684
Project: 4684
Buggy source:
/** 
 * Top level method of the thread. Calls three methods  a. Establish a TCP Connection. b. Assign this thread a part of the file, and do HTTP handshaking c. get the file. Each of these steps can run into errors, which have to be dealt with differently.
 * @return true if this worker thread should notify, false otherwise.currently this method returns false iff NSEEx is  thrown. 
 */
private boolean connectAndDownload(RemoteFileDesc rfd){
  HTTPDownloader dloader=null;
  dloader=establishConnection(rfd);
  if (dloader == null)   return true;
  boolean http11=true;
  while (http11) {
    boolean wasQueued=false;
    int connected;
    http11=!(rfd.getUrns().isEmpty());
    while (true) {
      int[] a={-1};
      connected=assignAndRequest(dloader,a,http11);
      if (connected != 1)       break;
      if (!wasQueued) {
synchronized (this) {
          queuedCount++;
        }
        wasQueued=true;
      }
      try {
        if (a[0] > 0)         Thread.sleep(a[0]);
      }
 catch (      InterruptedException ix) {
        debug("String_Node_Str" + dloader);
synchronized (this) {
          queuedCount--;
        }
        dloader.stop();
        return true;
      }
    }
    if (wasQueued) {
synchronized (this) {
        queuedCount--;
      }
    }
    Assert.that(connected == 0 || connected == 2 || connected == 3,"String_Node_Str" + connected);
    if (connected == 0)     return true;
 else     if (connected == 3)     return false;
    doDownload(dloader,http11);
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Top level method of the thread. Calls three methods  a. Establish a TCP Connection. b. Assign this thread a part of the file, and do HTTP handshaking c. get the file. Each of these steps can run into errors, which have to be dealt with differently.
 * @return true if this worker thread should notify, false otherwise.currently this method returns false iff NSEEx is  thrown. 
 */
private boolean connectAndDownload(RemoteFileDesc rfd){
  HTTPDownloader dloader=null;
  dloader=establishConnection(rfd);
  if (dloader == null)   return true;
  boolean http11=true;
  while (http11) {
    boolean wasQueued=false;
    int connected;
    http11=!(rfd.getUrns().isEmpty());
    while (true) {
      int[] a={-1};
      connected=assignAndRequest(dloader,a,http11);
      if (connected != 1)       break;
      if (!wasQueued) {
synchronized (this) {
          queuedCount++;
        }
        wasQueued=true;
      }
      try {
        if (a[0] > 0)         Thread.sleep(a[0]);
      }
 catch (      InterruptedException ix) {
        debug("String_Node_Str" + dloader);
synchronized (this) {
          queuedCount--;
        }
        dloader.stop();
        return true;
      }
    }
    if (wasQueued) {
synchronized (this) {
        queuedCount--;
      }
    }
    Assert.that(connected == 0 || connected == 2 || connected == 3,"String_Node_Str" + connected);
    if (connected == 0) {
      dloader.stop();
      return true;
    }
 else     if (connected == 3) {
      dloader.stop();
      return false;
    }
    doDownload(dloader,http11);
  }
  return true;
}
Program: 4685
Project: 4685
Buggy source:
/** 
 * Replaces OS specific illegal characters from any filename with '_',  including ( / \n \r \t ) on all operating systems, ( ? * \  < > | " )  on Windows, ( ` ) on unix.
 * @param name the filename to check for illegal characters
 * @return String containing the cleaned filename
 */
public static String convertFileName(String name){
  for (int i=0; i < ILLEGAL_CHARS_ANY_OS.length; i++)   name=name.replace(ILLEGAL_CHARS_ANY_OS[i],'_');
  if (_isWindows) {
    for (int i=0; i < ILLEGAL_CHARS_WINDOWS.length; i++)     name=name.replace(ILLEGAL_CHARS_WINDOWS[i],'_');
  }
 else   if (_isLinux || _isSolaris) {
    for (int i=0; i < ILLEGAL_CHARS_UNIX.length; i++)     name=name.replace(ILLEGAL_CHARS_UNIX[i],'_');
  }
  return name;
}

Fixed version (ground truth):
/** 
 * Replaces OS specific illegal characters from any filename with '_',  including ( / \n \r \t ) on all operating systems, ( ? * \  < > | " )  on Windows, ( ` ) on unix.
 * @param name the filename to check for illegal characters
 * @return String containing the cleaned filename
 */
public static String convertFileName(String name){
  if (name.length() > 180) {
    name=name.substring(0,180);
  }
  for (int i=0; i < ILLEGAL_CHARS_ANY_OS.length; i++)   name=name.replace(ILLEGAL_CHARS_ANY_OS[i],'_');
  if (_isWindows) {
    for (int i=0; i < ILLEGAL_CHARS_WINDOWS.length; i++)     name=name.replace(ILLEGAL_CHARS_WINDOWS[i],'_');
  }
 else   if (_isLinux || _isSolaris) {
    for (int i=0; i < ILLEGAL_CHARS_UNIX.length; i++)     name=name.replace(ILLEGAL_CHARS_UNIX[i],'_');
  }
  return name;
}
Program: 4686
Project: 4686
Buggy source:
private void tMismatchedVerifyHash(boolean deleteCorrupt) throws Exception {
  shouldRun(MISMATCHED_VERIFY_HASH);
  debug("String_Node_Str" + "String_Node_Str" + "String_Node_Str" + deleteCorrupt + "String_Node_Str");
  final int RATE=100;
  uploader1.setRate(RATE);
  RemoteFileDesc rfd1=newRFDWithURN(PORT_1,100,"String_Node_Str");
  Downloader download=null;
  download=dm.download(new RemoteFileDesc[]{rfd1},false);
  if (deleteCorrupt)   waitForCorrupt(download);
 else   waitForComplete(download);
  debug("String_Node_Str" + "String_Node_Str");
}

Fixed version (ground truth):
private void tMismatchedVerifyHash(boolean deleteCorrupt) throws Exception {
  shouldRun(MISMATCHED_VERIFY_HASH);
  debug("String_Node_Str" + "String_Node_Str" + "String_Node_Str" + deleteCorrupt + "String_Node_Str");
  final int RATE=100;
  uploader1.setRate(RATE);
  RemoteFileDesc rfd1=newRFDWithURN(PORT_1,100,"String_Node_Str");
  Downloader download=null;
  download=dm.download(rfd1.getFileName(),new RemoteFileDesc[]{rfd1},false);
  if (deleteCorrupt)   waitForCorrupt(download);
 else   waitForComplete(download);
  debug("String_Node_Str" + "String_Node_Str");
}
Program: 4687
Project: 4687
Buggy source:
private void tOverlapCheckWhite(boolean deleteCorrupt) throws Exception {
  shouldRun(OVERLAP_CHECK_WHITE);
  debug("String_Node_Str" + "String_Node_Str" + deleteCorrupt + "String_Node_Str");
  final int RATE=500;
  uploader1.setCorruption(true);
  uploader1.stopAfter(TestFile.length() / 8);
  uploader2.setRate(RATE);
  RemoteFileDesc rfd1=newRFD(PORT_1,100);
  RemoteFileDesc rfd2=newRFD(PORT_2,100);
  Downloader download=null;
  download=dm.download(new RemoteFileDesc[]{rfd1,rfd2},false);
  if (deleteCorrupt)   waitForCorrupt(download);
 else   waitForComplete(download);
  debug("String_Node_Str" + "String_Node_Str");
}

Fixed version (ground truth):
private void tOverlapCheckWhite(boolean deleteCorrupt) throws Exception {
  shouldRun(OVERLAP_CHECK_WHITE);
  debug("String_Node_Str" + "String_Node_Str" + deleteCorrupt + "String_Node_Str");
  final int RATE=500;
  uploader1.setCorruption(true);
  uploader1.stopAfter(TestFile.length() / 8);
  uploader2.setRate(RATE);
  RemoteFileDesc rfd1=newRFD(PORT_1,100);
  RemoteFileDesc rfd2=newRFD(PORT_2,100);
  Downloader download=null;
  download=dm.download(rfd1.getFileName(),new RemoteFileDesc[]{rfd1,rfd2},false);
  if (deleteCorrupt)   waitForCorrupt(download);
 else   waitForComplete(download);
  debug("String_Node_Str" + "String_Node_Str");
}
Program: 4688
Project: 4688
Buggy source:
public void testAddDownload() throws Exception {
  shouldRun(ADD_DOWNLOAD);
  debug("String_Node_Str");
  final int RATE=500;
  final int FUDGE_FACTOR=RATE * 1024;
  uploader1.setRate(RATE);
  uploader2.setRate(RATE);
  RemoteFileDesc rfd1=newRFD(PORT_1,100);
  RemoteFileDesc rfd2=newRFD(PORT_2,100);
  Downloader download=null;
  download=dm.download(new RemoteFileDesc[]{rfd1},false);
  ((ManagedDownloader)download).addDownload(rfd2);
  waitForComplete(download);
  if (isComplete())   debug("String_Node_Str" + "String_Node_Str");
 else   fail("String_Node_Str");
  int u1=uploader1.amountUploaded();
  int u2=uploader2.amountUploaded();
  debug("String_Node_Str" + u1 + "String_Node_Str");
  debug("String_Node_Str" + u2 + "String_Node_Str");
  debug("String_Node_Str" + (u1 + u2) + "String_Node_Str");
  assertLessThan("String_Node_Str",(TestFile.length() / 2 + FUDGE_FACTOR),u1);
  assertLessThan("String_Node_Str",(TestFile.length() / 2 + FUDGE_FACTOR),u2);
}

Fixed version (ground truth):
public void testAddDownload() throws Exception {
  shouldRun(ADD_DOWNLOAD);
  debug("String_Node_Str");
  final int RATE=500;
  final int FUDGE_FACTOR=RATE * 1024;
  uploader1.setRate(RATE);
  uploader2.setRate(RATE);
  RemoteFileDesc rfd1=newRFD(PORT_1,100);
  RemoteFileDesc rfd2=newRFD(PORT_2,100);
  Downloader download=null;
  download=dm.download(rfd1.getFileName(),new RemoteFileDesc[]{rfd1},false);
  ((ManagedDownloader)download).addDownload(rfd2);
  waitForComplete(download);
  if (isComplete())   debug("String_Node_Str" + "String_Node_Str");
 else   fail("String_Node_Str");
  int u1=uploader1.amountUploaded();
  int u2=uploader2.amountUploaded();
  debug("String_Node_Str" + u1 + "String_Node_Str");
  debug("String_Node_Str" + u2 + "String_Node_Str");
  debug("String_Node_Str" + (u1 + u2) + "String_Node_Str");
  assertLessThan("String_Node_Str",(TestFile.length() / 2 + FUDGE_FACTOR),u1);
  assertLessThan("String_Node_Str",(TestFile.length() / 2 + FUDGE_FACTOR),u2);
}
Program: 4689
Project: 4689
Buggy source:
private void tOverlapCheckGrey(boolean deleteCorrupt) throws Exception {
  shouldRun(OVERLAP_CHECK_GREY);
  debug("String_Node_Str" + "String_Node_Str" + deleteCorrupt + "String_Node_Str");
  final int RATE=500;
  uploader1.setRate(RATE);
  uploader2.setRate(RATE / 100);
  uploader2.setCorruption(true);
  RemoteFileDesc rfd1=newRFD(PORT_1,100);
  RemoteFileDesc rfd2=newRFD(PORT_2,100);
  Downloader download=null;
  download=dm.download(new RemoteFileDesc[]{rfd1,rfd2},false);
  if (deleteCorrupt)   waitForCorrupt(download);
 else   waitForComplete(download);
  debug("String_Node_Str" + "String_Node_Str");
}

Fixed version (ground truth):
private void tOverlapCheckGrey(boolean deleteCorrupt) throws Exception {
  shouldRun(OVERLAP_CHECK_GREY);
  debug("String_Node_Str" + "String_Node_Str" + deleteCorrupt + "String_Node_Str");
  final int RATE=500;
  uploader1.setRate(RATE);
  uploader2.setRate(RATE / 100);
  uploader2.setCorruption(true);
  RemoteFileDesc rfd1=newRFD(PORT_1,100);
  RemoteFileDesc rfd2=newRFD(PORT_2,100);
  Downloader download=null;
  download=dm.download(rfd1.getFileName(),new RemoteFileDesc[]{rfd1,rfd2},false);
  if (deleteCorrupt)   waitForCorrupt(download);
 else   waitForComplete(download);
  debug("String_Node_Str" + "String_Node_Str");
}
Program: 4690
Project: 4690
Buggy source:
/** 
 * Performs a generic download of the file specified in <tt>rfds</tt>.
 */
private static void tGeneric(RemoteFileDesc[] rfds) throws Exception {
  Downloader download=null;
  download=dm.download(rfds,false);
  waitForComplete(download);
  if (isComplete())   debug("String_Node_Str" + "String_Node_Str");
 else   fail("String_Node_Str");
  IncompleteFileManager ifm=dm.getIncompleteFileManager();
  for (int i=0; i < rfds.length; i++) {
    File incomplete=ifm.getFile(rfds[i]);
    VerifyingFile vf=ifm.getEntry(incomplete);
    assertNull("String_Node_Str",vf);
  }
}

Fixed version (ground truth):
/** 
 * Performs a generic download of the file specified in <tt>rfds</tt>.
 */
private static void tGeneric(RemoteFileDesc[] rfds) throws Exception {
  Downloader download=null;
  download=dm.download(rfds[0].getFileName(),rfds,false);
  waitForComplete(download);
  if (isComplete())   debug("String_Node_Str" + "String_Node_Str");
 else   fail("String_Node_Str");
  IncompleteFileManager ifm=dm.getIncompleteFileManager();
  for (int i=0; i < rfds.length; i++) {
    File incomplete=ifm.getFile(rfds[i]);
    VerifyingFile vf=ifm.getEntry(incomplete);
    assertNull("String_Node_Str",vf);
  }
}
Program: 4692
Project: 4692
Buggy source:
public void testLegacy(){
  ManagedDownloader.unitTest();
}

Fixed version (ground truth):
public void testLegacy(){
}
Program: 4693
Project: 4693
Buggy source:
public TestManagedDownloader(RemoteFileDesc[] files){
  super(files);
}

Fixed version (ground truth):
public TestManagedDownloader(RemoteFileDesc[] files){
  super(files[0].getFileName(),files,new IncompleteFileManager());
}
Program: 4694
Project: 4694
Buggy source:
/** 
 * Tests that the progress is not 0% when resume button is hit while requerying.  This was caused by the call to cleanup() from tryAllDownloads3() and was reported by Sam Berlin. 
 */
public void testRequeryProgress() throws Exception {
  TestUploader uploader=null;
  ManagedDownloader downloader=null;
  try {
    uploader=new TestUploader("String_Node_Str",PORT);
    uploader.stopAfter(100);
    downloader=new ManagedDownloader(new RemoteFileDesc[]{newRFD("String_Node_Str")},new IncompleteFileManager());
    downloader.initialize(new DownloadManagerStub(),new FileManagerStub(),new ActivityCallbackStub());
    try {
      Thread.sleep(6000);
    }
 catch (    InterruptedException e) {
    }
    assertEquals("String_Node_Str",Downloader.WAITING_FOR_RESULTS,downloader.getState());
    assertEquals("String_Node_Str",100,downloader.getAmountRead());
    try {
      downloader.resume();
    }
 catch (    AlreadyDownloadingException e) {
      fail("String_Node_Str",e);
    }
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException e) {
    }
    assertEquals(Downloader.WAITING_FOR_RESULTS,downloader.getState());
    assertEquals(100,downloader.getAmountRead());
  }
  finally {
    if (uploader != null)     uploader.stopThread();
    if (downloader != null)     downloader.stop();
  }
}

Fixed version (ground truth):
/** 
 * Tests that the progress is not 0% when resume button is hit while requerying.  This was caused by the call to cleanup() from tryAllDownloads3() and was reported by Sam Berlin. 
 */
public void testRequeryProgress() throws Exception {
  TestUploader uploader=null;
  ManagedDownloader downloader=null;
  try {
    uploader=new TestUploader("String_Node_Str",PORT);
    uploader.stopAfter(100);
    downloader=new ManagedDownloader("String_Node_Str",new RemoteFileDesc[]{newRFD("String_Node_Str")},new IncompleteFileManager());
    downloader.initialize(new DownloadManagerStub(),new FileManagerStub(),new ActivityCallbackStub());
    try {
      Thread.sleep(6000);
    }
 catch (    InterruptedException e) {
    }
    assertEquals("String_Node_Str",Downloader.WAITING_FOR_RESULTS,downloader.getState());
    assertEquals("String_Node_Str",100,downloader.getAmountRead());
    try {
      downloader.resume();
    }
 catch (    AlreadyDownloadingException e) {
      fail("String_Node_Str",e);
    }
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException e) {
    }
    assertEquals(Downloader.WAITING_FOR_RESULTS,downloader.getState());
    assertEquals(100,downloader.getAmountRead());
  }
  finally {
    if (uploader != null)     uploader.stopThread();
    if (downloader != null)     downloader.stop();
  }
}
Program: 4695
Project: 4695
Buggy source:
public synchronized String getFileName(){
  return _fileName;
}

Fixed version (ground truth):
public synchronized String getFileName(){
  if (_fileName != null)   return _fileName;
  String ret=null;
  if (dloaders.size() > 0)   ret=((HTTPDownloader)dloaders.get(0)).getRemoteFileDesc().getFileName();
 else   if (files != null && files.size() > 0)   ret=((RemoteFileDesc)files.get(0)).getFileName();
 else   if (allFiles.length > 0)   ret=allFiles[0].getFileName();
 else   ret=UNKNOWN_FILENAME;
  return CommonUtils.convertFileName(ret);
}
Program: 4696
Project: 4696
Buggy source:
/** 
 * Removes and returns the RemoteFileDesc with the highest quality in filesLeft.  If two or more entries have the same quality, returns the entry with the highest speed.  
 * @param filesLeft the list of file/locations to choose from, which MUSThave length of at least one.  Each entry MUST be an instance of RemoteFileDesc.  The assumption is that all are "same", though this isn't strictly needed.
 * @return the best file/endpoint location 
 */
private static RemoteFileDesc removeBest(List filesLeft){
  Iterator iter=filesLeft.iterator();
  RemoteFileDesc ret=(RemoteFileDesc)iter.next();
  while (iter.hasNext()) {
    RemoteFileDesc rfd=(RemoteFileDesc)iter.next();
    if (rfd.getSHA1Urn() != null && ret.getSHA1Urn() == null)     ret=rfd;
 else     if ((rfd.getSHA1Urn() == null) == (ret.getSHA1Urn() == null)) {
      if (rfd.getQuality() > ret.getQuality())       ret=rfd;
 else       if (rfd.getQuality() == ret.getQuality()) {
        if (rfd.getSpeed() > ret.getSpeed())         ret=rfd;
      }
    }
  }
  filesLeft.remove(ret);
  return ret;
}

Fixed version (ground truth):
/** 
 * Removes and returns the RemoteFileDesc with the highest quality in filesLeft.  If two or more entries have the same quality, returns the entry with the highest speed.  
 * @param filesLeft the list of file/locations to choose from, which MUSThave length of at least one.  Each entry MUST be an instance of RemoteFileDesc.  The assumption is that all are "same", though this isn't strictly needed.
 * @return the best file/endpoint location 
 */
private synchronized RemoteFileDesc removeBest(List filesLeft){
  Iterator iter=filesLeft.iterator();
  RemoteFileDesc ret=(RemoteFileDesc)iter.next();
  while (iter.hasNext()) {
    RemoteFileDesc rfd=(RemoteFileDesc)iter.next();
    if (rfd.getSHA1Urn() != null && ret.getSHA1Urn() == null)     ret=rfd;
 else     if ((rfd.getSHA1Urn() == null) == (ret.getSHA1Urn() == null)) {
      if (rfd.getQuality() > ret.getQuality())       ret=rfd;
 else       if (rfd.getQuality() == ret.getQuality()) {
        if (rfd.getSpeed() > ret.getSpeed())         ret=rfd;
      }
    }
  }
  filesLeft.remove(ret);
  return ret;
}
Program: 4697
Project: 4697
Buggy source:
protected void handlePingReply(PingReply reply,ReplyHandler handler){
  super.handlePingReply(reply,handler);
  try {
    if (!Endpoint.isPrivateAddress(reply.getIPBytes()) && notMe(InetAddress.getByName(reply.getIP()),reply.getPort()) && reply.supportsUnicast()) {
synchronized (_guessPongs) {
        _guessPongs.add(reply);
        _guessPongs.notify();
      }
    }
  }
 catch (  UnknownHostException ignored) {
  }
}

Fixed version (ground truth):
protected void handlePingReply(PingReply reply,ReplyHandler handler){
  super.handlePingReply(reply,handler);
  try {
    if (!CommonUtils.isPrivateAddress(reply.getIPBytes()) && notMe(InetAddress.getByName(reply.getIP()),reply.getPort()) && reply.supportsUnicast()) {
synchronized (_guessPongs) {
        _guessPongs.add(reply);
        _guessPongs.notify();
      }
    }
  }
 catch (  UnknownHostException ignored) {
  }
}
Program: 4698
Project: 4698
Buggy source:
/** 
 * Creates a new MAGNET downloader.  Immediately tries to download from <tt>defaultURLs</tt>, if specified. If that fails, or if defaultURLs does not provide alternate locations, issues a requery with <tt>textQuery</tt> and </tt>urn</tt>, as provided.  (Note that at least one must be non-null.)  If <tt>filename</tt> is specified, it will be used as the name of the complete file; otherwise it will be taken from any search results or guessed from <tt>defaultURLs</tt>.
 * @param manager controls download queuing; passed to superclass
 * @param filemanager shares saved files; passed to superclass
 * @param ifm maintains blocks stored on disk; passed to superclass
 * @param callback notifies GUI of updates; passed to superclass
 * @param urn the hash of the file (exact topic), or null if unknown
 * @param textQuery requery keywords (keyword topic), or null if unknown
 * @param filename the final file name, or null if unknown
 * @param defaultURLs the initial locations to try (exact source), or null if unknown
 * @exception IllegalArgumentException both urn and textQuery are null 
 */
public MagnetDownloader(DownloadManager manager,FileManager filemanager,IncompleteFileManager ifm,ActivityCallback callback,URN urn,String textQuery,String filename,String[] defaultURLs) throws IllegalArgumentException {
  super(new RemoteFileDesc[0],ifm);
  this._textQuery=textQuery;
  this._urn=urn;
  this._filename=filename;
  this._defaultURLs=defaultURLs;
}

Fixed version (ground truth):
/** 
 * Creates a new MAGNET downloader.  Immediately tries to download from <tt>defaultURLs</tt>, if specified. If that fails, or if defaultURLs does not provide alternate locations, issues a requery with <tt>textQuery</tt> and </tt>urn</tt>, as provided.  (Note that at least one must be non-null.)  If <tt>filename</tt> is specified, it will be used as the name of the complete file; otherwise it will be taken from any search results or guessed from <tt>defaultURLs</tt>.
 * @param manager controls download queuing; passed to superclass
 * @param filemanager shares saved files; passed to superclass
 * @param ifm maintains blocks stored on disk; passed to superclass
 * @param callback notifies GUI of updates; passed to superclass
 * @param urn the hash of the file (exact topic), or null if unknown
 * @param textQuery requery keywords (keyword topic), or null if unknown
 * @param filename the final file name, or null if unknown
 * @param defaultURLs the initial locations to try (exact source), or null if unknown
 */
public MagnetDownloader(DownloadManager manager,FileManager filemanager,IncompleteFileManager ifm,ActivityCallback callback,URN urn,String textQuery,String filename,String[] defaultURLs){
  super("String_Node_Str",new RemoteFileDesc[0],ifm);
  this._textQuery=textQuery;
  this._urn=urn;
  this._filename=filename;
  this._defaultURLs=defaultURLs;
}
Program: 4699
Project: 4699
Buggy source:
public synchronized String getFileName(){
  String ret=null;
  if (dloaders.size() > 0)   ret=((HTTPDownloader)dloaders.get(0)).getRemoteFileDesc().getFileName();
 else   if (files != null && files.size() > 0)   ret=((RemoteFileDesc)files.get(0)).getFileName();
 else   if (allFiles.length > 0)   ret=allFiles[0].getFileName();
 else   ret=UNKNOWN_FILENAME;
  return CommonUtils.convertFileName(ret);
}

Fixed version (ground truth):
public synchronized String getFileName(){
  return _fileName;
}
Program: 4700
Project: 4700
Buggy source:
/** 
 * Stub constructor for testing only.  Does not actually start downloads. 
 */
protected ManagedDownloader(RemoteFileDesc[] allFiles){
  this.allFiles=allFiles;
}

Fixed version (ground truth):
/** 
 * Creates a new ManagedDownload to download the given files.  The download does not start until initialize(..) is called, nor is it safe to call any other methods until that point.
 * @param name the name of the file on disk -- this can change slightlyto eliminate any characters that are problematic on certain  platforms
 * @param files the list of files to get.  This stops after ANY of thefiles is downloaded.
 * @param incompleteFileManager the repository of incomplete files forresuming
 */
public ManagedDownloader(String name,RemoteFileDesc[] files,IncompleteFileManager ifc){
  if (name == null) {
    throw new NullPointerException("String_Node_Str");
  }
  if (name.length() == 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (files == null) {
    throw new NullPointerException("String_Node_Str");
  }
  if (files.length == 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (ifc == null) {
    throw new NullPointerException("String_Node_Str");
  }
  _fileName=CommonUtils.convertFileName(name);
  this.allFiles=files;
  this.incompleteFileManager=ifc;
}
Program: 4701
Project: 4701
Buggy source:
/** 
 * Creates a new RequeryDownloader - a RequeryDownloader has no files initially associated with it, but it may have them later (via calls to addDownload().  Non-blocking.     
 * @param incompleteFileManager the repository of incomplete files forresuming
 * @param add the keywords to requery with
 */
public RequeryDownloader(IncompleteFileManager incompleteFileManager,AutoDownloadDetails add){
  super(new RemoteFileDesc[0],incompleteFileManager);
  Assert.that(add != null,"String_Node_Str");
  _add=add;
}

Fixed version (ground truth):
/** 
 * Creates a new RequeryDownloader - a RequeryDownloader has no files initially associated with it, but it may have them later (via calls to addDownload().  Non-blocking.     
 * @param incompleteFileManager the repository of incomplete files forresuming
 * @param add the keywords to requery with
 */
public RequeryDownloader(IncompleteFileManager incompleteFileManager,AutoDownloadDetails add){
  super("String_Node_Str",new RemoteFileDesc[0],incompleteFileManager);
  Assert.that(add != null,"String_Node_Str");
  _add=add;
}
Program: 4702
Project: 4702
Buggy source:
/** 
 * Overrides ManagedDownloader to allow any RemoteFileDesc that matches this' keywords.  If a match has already been found and a download has been started, only allows those RemoteFileDesc's that actually match  the download.
 */
protected boolean allowAddition(RemoteFileDesc other){
  if (_hasFile)   return super.allowAddition(other);
 else {
synchronized (_add) {
      if (_add.addDownload(other)) {
        _add.commitDownload(other);
        _hasFile=true;
        return true;
      }
 else {
        return false;
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Overrides ManagedDownloader to allow any RemoteFileDesc that matches this' keywords.  If a match has already been found and a download has been started, only allows those RemoteFileDesc's that actually match  the download.
 */
protected boolean allowAddition(RemoteFileDesc other){
  if (_hasFile)   return super.allowAddition(other);
 else {
synchronized (_add) {
      if (_add.addDownload(other)) {
        _add.commitDownload(other);
        _hasFile=true;
        _fileName=CommonUtils.convertFileName(other.getFileName());
        return true;
      }
 else {
        return false;
      }
    }
  }
}