Program: 4419
Project: 4419
Buggy source:
/** 
 * Tests to make sure that pongs are received properly via pong caching when the locale is specified in the ping
 */
public void testPongsReceivedFromPingWithLocale() throws Exception {
  PingPongSettings.PINGS_ACTIVE.setValue(false);
  byte[] ip={(byte)1,(byte)2,(byte)3,(byte)3};
  for (int i=0; i < PongCacher.NUM_HOPS + 4; i++) {
    PingReply curPong=PingReply.create(new GUID().bytes(),(byte)3,13232,ip,0,0,true,-1,false);
    PrivilegedAccessor.setValue((Object)curPong,"String_Node_Str","String_Node_Str");
    for (int j=0; j < i; j++) {
      if (j < PongCacher.NUM_HOPS) {
        curPong.hop();
      }
    }
    PongCacher.instance().addPong(curPong);
  }
  byte[] ip2={(byte)1,(byte)3,(byte)3,(byte)3};
  for (int i=0; i < PongCacher.NUM_HOPS + 4; i++) {
    PingReply curPong=PingReply.create(new GUID().bytes(),(byte)3,13232,ip2,0,0,true,-1,false);
    PrivilegedAccessor.setValue((Object)curPong,"String_Node_Str","String_Node_Str");
    for (int j=0; j < i; j++) {
      if (j < PongCacher.NUM_HOPS) {
        curPong.hop();
      }
    }
    PongCacher.instance().addPong(curPong);
  }
  byte[] ip3={(byte)3,(byte)3,(byte)3,(byte)3};
  for (int i=0; i < 2; i++) {
    PingReply curPong=PingReply.create(new GUID().bytes(),(byte)3,13232,ip3,0,0,true,-1,false);
    PrivilegedAccessor.setValue((Object)curPong,"String_Node_Str","String_Node_Str");
    for (int j=0; j < i; j++) {
      if (j < PongCacher.NUM_HOPS) {
        curPong.hop();
      }
    }
    PongCacher.instance().addPong(curPong);
  }
  List pongs=PongCacher.instance().getBestPongs("String_Node_Str");
  assertEquals(PongCacher.NUM_HOPS,pongs.size());
  pongs=PongCacher.instance().getBestPongs("String_Node_Str");
  assertEquals(PongCacher.NUM_HOPS,pongs.size());
  pongs=PongCacher.instance().getBestPongs("String_Node_Str");
  assertEquals(PongCacher.NUM_HOPS,pongs.size());
  ApplicationSettings.LANGUAGE.setValue("String_Node_Str");
  Message m=new PingRequest((byte)7);
  assertEquals("String_Node_Str","String_Node_Str",((PingRequest)m).getLocale());
  ApplicationSettings.LANGUAGE.setValue("String_Node_Str");
  Message m2=new PingRequest((byte)7);
  assertEquals("String_Node_Str","String_Node_Str",((PingRequest)m2).getLocale());
  ApplicationSettings.LANGUAGE.setValue("String_Node_Str");
  ULTRAPEER_3.send(m);
  ULTRAPEER_3.flush();
  Thread.sleep(100);
  ApplicationSettings.LANGUAGE.setValue("String_Node_Str");
  ULTRAPEER_4.send(m2);
  ULTRAPEER_4.flush();
  Message received;
  for (int i=0; i < PongCacher.NUM_HOPS; i++) {
    received=getFirstMessageOfType(ULTRAPEER_3,PingReply.class,10000);
    assertNotNull("String_Node_Str" + i,received);
    PingReply pr=(PingReply)received;
    assertEquals("String_Node_Str","String_Node_Str",pr.getClientLocale());
  }
  List returnedPongs=new ArrayList();
  for (int i=0; i < PongCacher.NUM_HOPS; i++) {
    received=getFirstMessageOfType(ULTRAPEER_4,PingReply.class,10000);
    assertNotNull("String_Node_Str" + i,received);
    PingReply pr=(PingReply)received;
    returnedPongs.add(pr);
  }
  int numSVPongs=0;
  Iterator iter=returnedPongs.iterator();
  while (iter.hasNext()) {
    PingReply pr=(PingReply)iter.next();
    if (pr.getClientLocale().equals("String_Node_Str"))     numSVPongs++;
 else     assertEquals("String_Node_Str","String_Node_Str",pr.getClientLocale());
  }
  assertEquals("String_Node_Str",2,numSVPongs);
  PingPongSettings.PINGS_ACTIVE.setValue(true);
}

Fixed version (ground truth):
/** 
 * Tests to make sure that pongs are received properly via pong caching when the locale is specified in the ping
 */
public void testPongsReceivedFromPingWithLocale() throws Exception {
  PingPongSettings.PINGS_ACTIVE.setValue(false);
  byte[] ip={(byte)1,(byte)2,(byte)3,(byte)3};
  for (int i=0; i < PongCacher.NUM_HOPS + 4; i++) {
    PingReply curPong=PingReply.create(new GUID().bytes(),(byte)3,13232,ip,0,0,true,-1,false,"String_Node_Str",1);
    for (int j=0; j < i; j++) {
      if (j < PongCacher.NUM_HOPS) {
        curPong.hop();
      }
    }
    PongCacher.instance().addPong(curPong);
  }
  byte[] ip2={(byte)1,(byte)3,(byte)3,(byte)3};
  for (int i=0; i < PongCacher.NUM_HOPS + 4; i++) {
    PingReply curPong=PingReply.create(new GUID().bytes(),(byte)3,13232,ip2,0,0,true,-1,false,"String_Node_Str",1);
    for (int j=0; j < i; j++) {
      if (j < PongCacher.NUM_HOPS) {
        curPong.hop();
      }
    }
    PongCacher.instance().addPong(curPong);
  }
  List pongs=PongCacher.instance().getBestPongs("String_Node_Str");
  assertEquals(PongCacher.NUM_HOPS,pongs.size());
  pongs=PongCacher.instance().getBestPongs("String_Node_Str");
  assertEquals(PongCacher.NUM_HOPS,pongs.size());
  ApplicationSettings.LANGUAGE.setValue("String_Node_Str");
  Message m=new PingRequest((byte)7);
  assertEquals("String_Node_Str","String_Node_Str",((PingRequest)m).getLocale());
  ULTRAPEER_3.send(m);
  ULTRAPEER_3.flush();
  Thread.sleep(100);
  ApplicationSettings.LANGUAGE.setValue("String_Node_Str");
  Message received;
  for (int i=0; i < PongCacher.NUM_HOPS; i++) {
    received=getFirstMessageOfType(ULTRAPEER_3,PingReply.class,5000);
    assertNotNull("String_Node_Str" + i,received);
    PingReply pr=(PingReply)received;
    assertEquals("String_Node_Str","String_Node_Str",pr.getClientLocale());
  }
  byte[] ip3={(byte)3,(byte)3,(byte)3,(byte)3};
  for (int i=0; i < 2; i++) {
    PingReply curPong=PingReply.create(new GUID().bytes(),(byte)3,13232,ip3,0,0,true,-1,false,"String_Node_Str",1);
    for (int j=0; j < i; j++) {
      if (j < PongCacher.NUM_HOPS) {
        curPong.hop();
      }
    }
    PongCacher.instance().addPong(curPong);
  }
  pongs=PongCacher.instance().getBestPongs("String_Node_Str");
  assertEquals(PongCacher.NUM_HOPS,pongs.size());
  ApplicationSettings.LANGUAGE.setValue("String_Node_Str");
  Message m2=new PingRequest((byte)7);
  assertEquals("String_Node_Str","String_Node_Str",((PingRequest)m2).getLocale());
  ULTRAPEER_4.send(m2);
  ULTRAPEER_4.flush();
  List returnedPongs=new ArrayList();
  for (int i=0; i < PongCacher.NUM_HOPS; i++) {
    received=getFirstMessageOfType(ULTRAPEER_4,PingReply.class,5000);
    assertNotNull("String_Node_Str" + i,received);
    PingReply pr=(PingReply)received;
    returnedPongs.add(pr);
  }
  int numSVPongs=0;
  Iterator iter=returnedPongs.iterator();
  while (iter.hasNext()) {
    PingReply pr=(PingReply)iter.next();
    if (pr.getClientLocale().equals("String_Node_Str"))     numSVPongs++;
 else     assertEquals("String_Node_Str","String_Node_Str",pr.getClientLocale());
  }
  assertEquals("String_Node_Str",2,numSVPongs);
  PingPongSettings.PINGS_ACTIVE.setValue(true);
}