nus-yam/ex-repair huggingface dataset:
Program: 55589
Project: 55589
Buggy source:
@Override public void run(){
  while (!closed) {
    currWriteSlot=(currWriteSlot + 1) % BUFFER_LENGTH;
    int currDist=(BUFFER_LENGTH + currWriteSlot - currReadSlot) % BUFFER_LENGTH;
    int targetDistance=Math.min(MAX_DELAY,Math.max(MIN_DELAY,(int)(currDist + Math.random() * MAX_DELAY_STEP * 2 - MAX_DELAY_STEP)));
    if (targetDistance >= currDist) {
      currReadSlot=(BUFFER_LENGTH + currReadSlot - (targetDistance - currDist)) % BUFFER_LENGTH;
    }
 else {
      for (int i=targetDistance; i < currDist; i++) {
        writeNextSlot();
      }
    }
    try {
      Thread.sleep(1);
    }
 catch (    InterruptedException e) {
    }
  }
}

Fixed version (ground truth):
@Override public void run(){
  while (!closed) {
    currWriteSlot=(currWriteSlot + 1) % BUFFER_LENGTH;
    int currDist=(BUFFER_LENGTH + currWriteSlot - currReadSlot) % BUFFER_LENGTH;
    int targetDistance=Math.min(MAX_DELAY,Math.max(MIN_DELAY,(int)(currDist + Math.random() * MAX_DELAY_STEP * 2 - MAX_DELAY_STEP)));
    if (targetDistance >= currDist) {
      currReadSlot=(BUFFER_LENGTH + currReadSlot - (targetDistance - currDist)) % BUFFER_LENGTH;
    }
 else {
      for (int i=targetDistance; i < currDist; i++) {
        writeNextSlot();
      }
    }
    try {
      Thread.sleep(1L);
    }
 catch (    InterruptedException e) {
    }
  }
}
Program: 55590
Project: 55590
Buggy source:
/** 
 * NOTE: THIS METHOD IS BLOCKING for the given time
 * @param seconds block at maximum the given number of seconds to find the address
 * @return
 */
public static String retrieveLanServerAddress(int seconds){
  LanServerAddressBroadcastListener serverAddressReceiver=new LanServerAddressBroadcastListener();
  try {
    serverAddressReceiver.start();
    for (int i=0; i < 2 * seconds && !serverAddressReceiver.hasFoundServer(); i++) {
      try {
        Thread.sleep(500);
      }
 catch (      InterruptedException e) {
        e.printStackTrace();
      }
    }
    if (serverAddressReceiver.hasFoundServer()) {
      System.out.println("String_Node_Str");
      return serverAddressReceiver.getServerAddress().getHostAddress();
    }
 else {
      return null;
    }
  }
  finally {
    serverAddressReceiver.shutdown();
  }
}

Fixed version (ground truth):
/** 
 * NOTE: THIS METHOD IS BLOCKING for the given time
 * @param seconds block at maximum the given number of seconds to find the address
 * @return
 */
public static String retrieveLanServerAddress(int seconds){
  LanServerAddressBroadcastListener serverAddressReceiver=new LanServerAddressBroadcastListener();
  try {
    serverAddressReceiver.start();
    for (int i=0; i < 2 * seconds && !serverAddressReceiver.hasFoundServer(); i++) {
      try {
        Thread.sleep(500L);
      }
 catch (      InterruptedException e) {
        e.printStackTrace();
      }
    }
    if (serverAddressReceiver.hasFoundServer()) {
      System.out.println("String_Node_Str");
      return serverAddressReceiver.getServerAddress().getHostAddress();
    }
 else {
      return null;
    }
  }
  finally {
    serverAddressReceiver.shutdown();
  }
}
Program: 55591
Project: 55591
Buggy source:
@Override public void run(){
  try {
    socket=new DatagramSocket();
    while (!canceled) {
      try {
        Thread.sleep(500);
        byte[] data=NetworkConstants.Server.BROADCAST_MESSAGE.getBytes();
        broadcast(NetworkConstants.Server.BROADCAST_PORT,socket,data);
      }
 catch (      IOException e) {
        e.printStackTrace();
      }
catch (      InterruptedException e) {
      }
    }
  }
 catch (  SocketException e) {
    e.printStackTrace();
  }
 finally {
    if (socket != null)     socket.close();
  }
}

Fixed version (ground truth):
@Override public void run(){
  try {
    socket=new DatagramSocket();
    while (!canceled) {
      try {
        Thread.sleep(500L);
        byte[] data=NetworkConstants.Server.BROADCAST_MESSAGE.getBytes();
        broadcast(NetworkConstants.Server.BROADCAST_PORT,socket,data);
      }
 catch (      IOException e) {
        e.printStackTrace();
      }
catch (      InterruptedException e) {
      }
    }
  }
 catch (  SocketException e) {
    e.printStackTrace();
  }
 finally {
    if (socket != null)     socket.close();
  }
}
Program: 55592
Project: 55592
Buggy source:
@Test public void testCloseFromServerSide() throws IllegalStateException, InterruptedException {
  logIn(client1,"String_Node_Str","String_Node_Str");
  logIn(client2,"String_Node_Str","String_Node_Str");
  assertEquals(2,db.getNumberOfPlayers());
  server1Channel.close();
  Thread.sleep(10);
  assertEquals(1,db.getNumberOfPlayers());
  assertEquals(EPlayerState.DISCONNECTED,client1.getState());
}

Fixed version (ground truth):
@Test public void testCloseFromServerSide() throws IllegalStateException, InterruptedException {
  logIn(client1,"String_Node_Str","String_Node_Str");
  logIn(client2,"String_Node_Str","String_Node_Str");
  assertEquals(2,db.getNumberOfPlayers());
  server1Channel.close();
  Thread.sleep(10L);
  assertEquals(1,db.getNumberOfPlayers());
  assertEquals(EPlayerState.DISCONNECTED,client1.getState());
}
Program: 55593
Project: 55593
Buggy source:
@Test public void testOpenAndStartNewMatch() throws IllegalStateException, InterruptedException {
  openMatch("String_Node_Str","String_Node_Str",client1);
  client1.startMatch();
  Thread.sleep(50);
  assertEquals(EPlayerState.IN_RUNNING_MATCH,client1.getState());
}

Fixed version (ground truth):
@Test public void testOpenAndStartNewMatch() throws IllegalStateException, InterruptedException {
  openMatch("String_Node_Str","String_Node_Str",client1);
  client1.startMatch();
  Thread.sleep(50L);
  assertEquals(EPlayerState.IN_RUNNING_MATCH,client1.getState());
}
Program: 55594
Project: 55594
Buggy source:
@Test public void testConnection() throws InterruptedException {
  TestPacketListener listener=new TestPacketListener(NetworkConstants.ENetworkKey.TEST_PACKET);
  client1Channel.registerListener(listener);
  TestPacket testPacket=new TestPacket("String_Node_Str",2324);
  server1Channel.sendPacket(NetworkConstants.ENetworkKey.TEST_PACKET,testPacket);
  Thread.sleep(10);
  assertEquals(1,listener.packets.size());
  assertEquals(testPacket,listener.packets.get(0));
}

Fixed version (ground truth):
@Test public void testConnection() throws InterruptedException {
  TestPacketListener listener=new TestPacketListener(NetworkConstants.ENetworkKey.TEST_PACKET);
  client1Channel.registerListener(listener);
  TestPacket testPacket=new TestPacket("String_Node_Str",2324);
  server1Channel.sendPacket(NetworkConstants.ENetworkKey.TEST_PACKET,testPacket);
  Thread.sleep(10L);
  assertEquals(1,listener.packets.size());
  assertEquals(testPacket,listener.packets.get(0));
}
Program: 55596
Project: 55596
Buggy source:
@Test public void testStartMatchWithUnreadyPlayers() throws IllegalStateException, InterruptedException {
  logIn(client2,"String_Node_Str","String_Node_Str");
  openMatch("String_Node_Str","String_Node_Str",client1);
  client2.joinMatch(client1.getMatchInfo().getId(),null,null,null);
  BufferingPacketReceiver<RejectPacket> rejectReceiver2=new BufferingPacketReceiver<>();
  client2.registerRejectReceiver(rejectReceiver2);
  Thread.sleep(50);
  assertEquals(0,rejectReceiver2.popBufferedPackets().size());
  client2.startMatch();
  Thread.sleep(50);
  assertSingleRejectPacket(rejectReceiver2,ENetworkKey.REQUEST_START_MATCH,ENetworkMessage.NOT_ALL_PLAYERS_READY);
  client2.setReadyState(true);
  Thread.sleep(20);
  client1.setReadyState(false);
  Thread.sleep(20);
  client2.startMatch();
  Thread.sleep(50);
  assertSingleRejectPacket(rejectReceiver2,ENetworkKey.REQUEST_START_MATCH,ENetworkMessage.NOT_ALL_PLAYERS_READY);
  client1.setReadyState(true);
  Thread.sleep(20);
  client2.startMatch();
  Thread.sleep(50);
  assertEquals(EPlayerState.IN_RUNNING_MATCH,client1.getState());
  assertEquals(EPlayerState.IN_RUNNING_MATCH,client2.getState());
}

Fixed version (ground truth):
@Test public void testStartMatchWithUnreadyPlayers() throws IllegalStateException, InterruptedException {
  logIn(client2,"String_Node_Str","String_Node_Str");
  openMatch("String_Node_Str","String_Node_Str",client1);
  client2.joinMatch(client1.getMatchInfo().getId(),null,null,null);
  BufferingPacketReceiver<RejectPacket> rejectReceiver2=new BufferingPacketReceiver<>();
  client2.registerRejectReceiver(rejectReceiver2);
  Thread.sleep(50L);
  assertEquals(0,rejectReceiver2.popBufferedPackets().size());
  client2.startMatch();
  Thread.sleep(50L);
  assertSingleRejectPacket(rejectReceiver2,ENetworkKey.REQUEST_START_MATCH,ENetworkMessage.NOT_ALL_PLAYERS_READY);
  client2.setReadyState(true);
  Thread.sleep(20L);
  client1.setReadyState(false);
  Thread.sleep(20L);
  client2.startMatch();
  Thread.sleep(50L);
  assertSingleRejectPacket(rejectReceiver2,ENetworkKey.REQUEST_START_MATCH,ENetworkMessage.NOT_ALL_PLAYERS_READY);
  client1.setReadyState(true);
  Thread.sleep(20L);
  client2.startMatch();
  Thread.sleep(50L);
  assertEquals(EPlayerState.IN_RUNNING_MATCH,client1.getState());
  assertEquals(EPlayerState.IN_RUNNING_MATCH,client2.getState());
}
Program: 55597
Project: 55597
Buggy source:
private void logIn(NetworkClient client,String playerId,String playerName) throws IllegalStateException, InterruptedException {
  int currentNumberOfPlayers=db.getNumberOfPlayers();
  client.logIn(playerId,playerName,null);
  Thread.sleep(40);
  assertEquals(EPlayerState.LOGGED_IN,client.getState());
  assertEquals(currentNumberOfPlayers + 1,db.getNumberOfPlayers());
  Player p=db.getPlayer(playerId);
  assertEquals(playerId,p.getId());
  assertEquals(playerName,p.getPlayerInfo().getName());
}

Fixed version (ground truth):
private void logIn(NetworkClient client,String playerId,String playerName) throws IllegalStateException, InterruptedException {
  int currentNumberOfPlayers=db.getNumberOfPlayers();
  client.logIn(playerId,playerName,null);
  Thread.sleep(40L);
  assertEquals(EPlayerState.LOGGED_IN,client.getState());
  assertEquals(currentNumberOfPlayers + 1,db.getNumberOfPlayers());
  Player p=db.getPlayer(playerId);
  assertEquals(playerId,p.getId());
  assertEquals(playerName,p.getPlayerInfo().getName());
}
Program: 55598
Project: 55598
Buggy source:
@Test public void testChatMessaging() throws IllegalStateException, InterruptedException {
  testLogIn();
  BufferingPacketReceiver<ChatMessagePacket> chatReceiver=new BufferingPacketReceiver<>();
  client1.openNewMatch("String_Node_Str",4,new MapInfoPacket("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",9),923409340394293842L,null,null,chatReceiver);
  Thread.sleep(80);
  assertEquals(EPlayerState.IN_MATCH,client1.getState());
  testSendAndReceiveChatMessage(chatReceiver);
  client1.setReadyState(true);
  Thread.sleep(50);
  testSendAndReceiveChatMessage(chatReceiver);
  client1.startMatch();
  Thread.sleep(50);
  assertEquals(EPlayerState.IN_RUNNING_MATCH,client1.getState());
  testSendAndReceiveChatMessage(chatReceiver);
}

Fixed version (ground truth):
@Test public void testChatMessaging() throws IllegalStateException, InterruptedException {
  testLogIn();
  BufferingPacketReceiver<ChatMessagePacket> chatReceiver=new BufferingPacketReceiver<>();
  client1.openNewMatch("String_Node_Str",4,new MapInfoPacket("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",9),923409340394293842L,null,null,chatReceiver);
  Thread.sleep(80L);
  assertEquals(EPlayerState.IN_MATCH,client1.getState());
  testSendAndReceiveChatMessage(chatReceiver);
  client1.setReadyState(true);
  Thread.sleep(50L);
  testSendAndReceiveChatMessage(chatReceiver);
  client1.startMatch();
  Thread.sleep(50L);
  assertEquals(EPlayerState.IN_RUNNING_MATCH,client1.getState());
  testSendAndReceiveChatMessage(chatReceiver);
}
Program: 55599
Project: 55599
Buggy source:
private void testSendAndReceiveChatMessage(BufferingPacketReceiver<ChatMessagePacket> chatReceiver) throws IllegalStateException, InterruptedException {
  final String testMessage="String_Node_Str";
  client1.sendChatMessage(testMessage);
  assertEquals(0,chatReceiver.popBufferedPackets().size());
  Thread.sleep(50);
  List<ChatMessagePacket> chatMessages=chatReceiver.popBufferedPackets();
  assertEquals(1,chatMessages.size());
  assertEquals(TEST_PLAYER_ID,chatMessages.get(0).getAuthorId());
  assertEquals(testMessage,chatMessages.get(0).getMessage());
}

Fixed version (ground truth):
private void testSendAndReceiveChatMessage(BufferingPacketReceiver<ChatMessagePacket> chatReceiver) throws IllegalStateException, InterruptedException {
  final String testMessage="String_Node_Str";
  client1.sendChatMessage(testMessage);
  assertEquals(0,chatReceiver.popBufferedPackets().size());
  Thread.sleep(50L);
  List<ChatMessagePacket> chatMessages=chatReceiver.popBufferedPackets();
  assertEquals(1,chatMessages.size());
  assertEquals(TEST_PLAYER_ID,chatMessages.get(0).getAuthorId());
  assertEquals(testMessage,chatMessages.get(0).getMessage());
}
Program: 55600
Project: 55600
Buggy source:
@Test public void testTimeSynchronization() throws IllegalStateException, InterruptedException {
  testOpenStartAndJoinNewMatch();
  clock1.setTime(200);
  clock2.setTime(210);
  Thread.sleep(NetworkConstants.Client.TIME_SYNC_SEND_INTERVALL + 20);
  assertEquals(0,clock1.popAdjustmentEvents().size());
  assertEquals(0,clock2.popAdjustmentEvents().size());
  clock1.setTime(2056);
  Thread.sleep(3 * NetworkConstants.Client.TIME_SYNC_SEND_INTERVALL + 20);
  int diff=Math.abs(clock1.getTime() - clock2.getTime());
  assertTrue("String_Node_Str" + diff,diff < NetworkConstants.Client.TIME_SYNC_TOLERATED_DIFFERENCE);
  assertTrue(clock1.popAdjustmentEvents().size() > 0);
  assertEquals(0,clock2.popAdjustmentEvents().size());
  clock2.setTime(423423);
  Thread.sleep(6 * NetworkConstants.Client.TIME_SYNC_SEND_INTERVALL + 20);
  diff=Math.abs(clock2.getTime() - clock1.getTime());
  assertTrue("String_Node_Str" + diff,diff < NetworkConstants.Client.TIME_SYNC_TOLERATED_DIFFERENCE);
  assertTrue(clock2.popAdjustmentEvents().size() > 0);
  assertEquals(0,clock1.popAdjustmentEvents().size());
}

Fixed version (ground truth):
@Test public void testTimeSynchronization() throws IllegalStateException, InterruptedException {
  testOpenStartAndJoinNewMatch();
  clock1.setTime(200);
  clock2.setTime(210);
  Thread.sleep(NetworkConstants.Client.TIME_SYNC_SEND_INTERVALL + 20L);
  assertEquals(0,clock1.popAdjustmentEvents().size());
  assertEquals(0,clock2.popAdjustmentEvents().size());
  clock1.setTime(2056);
  Thread.sleep(3L * NetworkConstants.Client.TIME_SYNC_SEND_INTERVALL + 20L);
  int diff=Math.abs(clock1.getTime() - clock2.getTime());
  assertTrue("String_Node_Str" + diff,diff < NetworkConstants.Client.TIME_SYNC_TOLERATED_DIFFERENCE);
  assertTrue(clock1.popAdjustmentEvents().size() > 0);
  assertEquals(0,clock2.popAdjustmentEvents().size());
  clock2.setTime(423423);
  Thread.sleep(6L * NetworkConstants.Client.TIME_SYNC_SEND_INTERVALL + 20L);
  diff=Math.abs(clock2.getTime() - clock1.getTime());
  assertTrue("String_Node_Str" + diff,diff < NetworkConstants.Client.TIME_SYNC_TOLERATED_DIFFERENCE);
  assertTrue(clock2.popAdjustmentEvents().size() > 0);
  assertEquals(0,clock1.popAdjustmentEvents().size());
}
Program: 55601
Project: 55601
Buggy source:
@Test public void testLogInAndClose() throws IllegalStateException, InterruptedException {
  testLogIn();
  client1.close();
  Thread.sleep(10);
  assertEquals(0,db.getNumberOfPlayers());
  assertEquals(EPlayerState.DISCONNECTED,client1.getState());
}

Fixed version (ground truth):
@Test public void testLogInAndClose() throws IllegalStateException, InterruptedException {
  testLogIn();
  client1.close();
  Thread.sleep(10L);
  assertEquals(0,db.getNumberOfPlayers());
  assertEquals(EPlayerState.DISCONNECTED,client1.getState());
}
Program: 55602
Project: 55602
Buggy source:
@Test public void testOpenStartAndJoinNewMatch() throws IllegalStateException, InterruptedException {
  logIn(client2,"String_Node_Str","String_Node_Str");
  openMatch("String_Node_Str","String_Node_Str",client1);
  MatchInfoPacket dbMatchInfo=new MatchInfoPacket(db.getJoinableMatches().get(0));
  assertEquals(dbMatchInfo,client1.getMatchInfo());
  assertEquals(1,client1.getMatchInfo().getPlayers().length);
  client2.joinMatch(dbMatchInfo.getId(),null,null,null);
  Thread.sleep(50);
  assertEquals(EPlayerState.IN_MATCH,client2.getState());
  dbMatchInfo=new MatchInfoPacket(db.getJoinableMatches().get(0));
  assertEquals(dbMatchInfo,client1.getMatchInfo());
  assertEquals(2,client1.getMatchInfo().getPlayers().length);
  client2.setReadyState(true);
  Thread.sleep(50);
  assertEquals(EPlayerState.IN_MATCH,client2.getState());
  dbMatchInfo=new MatchInfoPacket(db.getJoinableMatches().get(0));
  assertEquals(dbMatchInfo,client1.getMatchInfo());
  assertEquals(2,client1.getMatchInfo().getPlayers().length);
  assertTrue(client1.getMatchInfo().getPlayers()[1].isReady());
  client1.startMatch();
  Thread.sleep(50);
  assertEquals(EPlayerState.IN_RUNNING_MATCH,client1.getState());
  assertEquals(EPlayerState.IN_RUNNING_MATCH,client2.getState());
}

Fixed version (ground truth):
@Test public void testOpenStartAndJoinNewMatch() throws IllegalStateException, InterruptedException {
  logIn(client2,"String_Node_Str","String_Node_Str");
  openMatch("String_Node_Str","String_Node_Str",client1);
  MatchInfoPacket dbMatchInfo=new MatchInfoPacket(db.getJoinableMatches().get(0));
  assertEquals(dbMatchInfo,client1.getMatchInfo());
  assertEquals(1,client1.getMatchInfo().getPlayers().length);
  client2.joinMatch(dbMatchInfo.getId(),null,null,null);
  Thread.sleep(50L);
  assertEquals(EPlayerState.IN_MATCH,client2.getState());
  dbMatchInfo=new MatchInfoPacket(db.getJoinableMatches().get(0));
  assertEquals(dbMatchInfo,client1.getMatchInfo());
  assertEquals(2,client1.getMatchInfo().getPlayers().length);
  client2.setReadyState(true);
  Thread.sleep(50L);
  assertEquals(EPlayerState.IN_MATCH,client2.getState());
  dbMatchInfo=new MatchInfoPacket(db.getJoinableMatches().get(0));
  assertEquals(dbMatchInfo,client1.getMatchInfo());
  assertEquals(2,client1.getMatchInfo().getPlayers().length);
  assertTrue(client1.getMatchInfo().getPlayers()[1].isReady());
  client1.startMatch();
  Thread.sleep(50);
  assertEquals(EPlayerState.IN_RUNNING_MATCH,client1.getState());
  assertEquals(EPlayerState.IN_RUNNING_MATCH,client2.getState());
}
Program: 55604
Project: 55604
Buggy source:
@Test public void testSendAndReceive() throws InterruptedException {
  SyncTasksPacketSchedulerMock taskReceiver=new SyncTasksPacketSchedulerMock();
  TaskPacketListener listener=new TaskPacketListener(taskReceiver);
  c1.registerListener(listener);
  TaskPacket testPacket1=new TestTaskPacket("String_Node_Str",23424,(byte)-2);
  TaskPacket testPacket2=new TestTaskPacket("String_Node_Str",-2342342,(byte)-67);
  int lockstep=23;
  SyncTasksPacket syncTasksPacket=new SyncTasksPacket(lockstep,Arrays.asList(testPacket1,testPacket2));
  c2.sendPacket(NetworkConstants.ENetworkKey.SYNCHRONOUS_TASK,syncTasksPacket);
  Thread.sleep(30);
  List<SyncTasksPacket> packets=taskReceiver.popBufferedPackets();
  assertEquals(1,packets.size());
  assertEquals(lockstep,packets.get(0).getLockstepNumber());
  List<TaskPacket> tasks=packets.get(0).getTasks();
  assertEquals(2,tasks.size());
  assertEquals(testPacket1,tasks.get(0));
  assertEquals(testPacket2,tasks.get(1));
}

Fixed version (ground truth):
@Test public void testSendAndReceive() throws InterruptedException {
  SyncTasksPacketSchedulerMock taskReceiver=new SyncTasksPacketSchedulerMock();
  TaskPacketListener listener=new TaskPacketListener(taskReceiver);
  c1.registerListener(listener);
  TaskPacket testPacket1=new TestTaskPacket("String_Node_Str",23424,(byte)-2);
  TaskPacket testPacket2=new TestTaskPacket("String_Node_Str",-2342342,(byte)-67);
  int lockstep=23;
  SyncTasksPacket syncTasksPacket=new SyncTasksPacket(lockstep,Arrays.asList(testPacket1,testPacket2));
  c2.sendPacket(NetworkConstants.ENetworkKey.SYNCHRONOUS_TASK,syncTasksPacket);
  Thread.sleep(30L);
  List<SyncTasksPacket> packets=taskReceiver.popBufferedPackets();
  assertEquals(1,packets.size());
  assertEquals(lockstep,packets.get(0).getLockstepNumber());
  List<TaskPacket> tasks=packets.get(0).getTasks();
  assertEquals(2,tasks.size());
  assertEquals(testPacket1,tasks.get(0));
  assertEquals(testPacket2,tasks.get(1));
}
Program: 55605
Project: 55605
Buggy source:
@Test public void testSerializationAndDeserialization() throws InterruptedException {
  c2.registerListener(listener);
  c1.sendPacket(NetworkConstants.ENetworkKey.TEST_PACKET,packet);
  Thread.sleep(150);
  List<? extends Packet> bufferedPackets=listener.popBufferedPackets();
  assertEquals(1,bufferedPackets.size());
  assertEquals(packet,bufferedPackets.get(0));
  assertEquals(packet.hashCode(),bufferedPackets.get(0).hashCode());
}

Fixed version (ground truth):
@Test public void testSerializationAndDeserialization() throws InterruptedException {
  c2.registerListener(listener);
  c1.sendPacket(NetworkConstants.ENetworkKey.TEST_PACKET,packet);
  Thread.sleep(150L);
  List<? extends Packet> bufferedPackets=listener.popBufferedPackets();
  assertEquals(1,bufferedPackets.size());
  assertEquals(packet,bufferedPackets.get(0));
  assertEquals(packet.hashCode(),bufferedPackets.get(0).hashCode());
}
Program: 55606
Project: 55606
Buggy source:
@Override public void commandTroops(Set<Integer> soldiersWithOrders){
  SoldierPositions soldierPositions=calculateSituation(player.playerId);
  if (aiStatistics.getEnemiesInTownOf(player.playerId).size() > 0) {
    defend(soldierPositions,soldiersWithOrders);
  }
 else   if (existsAliveEnemy()) {
    IPlayer weakestEnemy=getWeakestEnemy();
    SoldierPositions enemySoldierPositions=calculateSituation(weakestEnemy.getPlayerId());
    boolean infantryWouldDie=wouldInfantryDie(enemySoldierPositions);
    if (attackIsPossible(soldierPositions,enemySoldierPositions,infantryWouldDie)) {
      attack(soldierPositions,infantryWouldDie,soldiersWithOrders);
    }
  }
}

Fixed version (ground truth):
@Override public void commandTroops(Set<Integer> soldiersWithOrders){
  ensureAllTowersFullyMounted();
  SoldierPositions soldierPositions=calculateSituation(player.playerId);
  if (aiStatistics.getEnemiesInTownOf(player.playerId).size() > 0) {
    defend(soldierPositions,soldiersWithOrders);
  }
 else   if (existsAliveEnemy()) {
    IPlayer weakestEnemy=getWeakestEnemy();
    SoldierPositions enemySoldierPositions=calculateSituation(weakestEnemy.getPlayerId());
    boolean infantryWouldDie=wouldInfantryDie(enemySoldierPositions);
    if (attackIsPossible(soldierPositions,enemySoldierPositions,infantryWouldDie)) {
      attack(soldierPositions,infantryWouldDie,soldiersWithOrders);
    }
  }
}
Program: 55607
Project: 55607
Buggy source:
public ConfigurableGeneral(AiStatistics aiStatistics,Player player,MovableGrid movableGrid,ITaskScheduler taskScheduler,float attackerCountFactor){
  this.aiStatistics=aiStatistics;
  this.player=player;
  this.taskScheduler=taskScheduler;
  this.movableGrid=movableGrid;
  this.attackerCountFactor=attackerCountFactor;
}

Fixed version (ground truth):
public ConfigurableGeneral(AiStatistics aiStatistics,Player player,MovableGrid movableGrid,ITaskScheduler taskScheduler,EPlayerType playerType){
  this.aiStatistics=aiStatistics;
  this.player=player;
  this.taskScheduler=taskScheduler;
  this.movableGrid=movableGrid;
  this.attackerCountFactor=ATTACKER_COUNT_FACTOR_BY_PLAYER_TYPE[playerType.ordinal()];
}
Program: 55608
Project: 55608
Buggy source:
@Override public ShortPoint2D findBestConstructionPosition(AiStatistics aiStatistics,AbstractConstructionMarkableMap constructionMap,byte playerId){
  List<ScoredConstructionPosition> scoredConstructionPositions=new ArrayList<>();
  for (  ShortPoint2D point : aiStatistics.getLandForPlayer(playerId)) {
    if (constructionMap.canConstructAt(point.x,point.y,buildingType,playerId)) {
      int resourceAmount=0;
      LandscapeGrid landscapeGrid=aiStatistics.getMainGrid().getLandscapeGrid();
      for (      RelativePoint relativePoint : buildingType.getBlockedTiles()) {
        int x=point.x + relativePoint.getDx();
        int y=point.y + relativePoint.getDy();
        if (landscapeGrid.getResourceTypeAt(x,y) == resourceType) {
          resourceAmount-=landscapeGrid.getResourceAmountAt(x,y);
        }
      }
      if (resourceAmount != 0) {
        scoredConstructionPositions.add(new ScoredConstructionPosition(point,resourceAmount));
      }
    }
  }
  return ScoredConstructionPosition.detectPositionWithLowestScore(scoredConstructionPositions);
}

Fixed version (ground truth):
@Override public ShortPoint2D findBestConstructionPosition(AiStatistics aiStatistics,AbstractConstructionMarkableMap constructionMap,byte playerId){
  List<ScoredConstructionPosition> scoredConstructionPositions=new ArrayList<>();
  for (  ShortPoint2D point : aiStatistics.getLandForPlayer(playerId)) {
    if (constructionMap.canConstructAt(point.x,point.y,buildingType,playerId)) {
      int resourceAmount=0;
      LandscapeGrid landscapeGrid=aiStatistics.getMainGrid().getLandscapeGrid();
      for (      RelativePoint relativePoint : buildingType.getBlockedTiles()) {
        int x=point.x + relativePoint.getDx();
        int y=point.y + relativePoint.getDy();
        if (landscapeGrid.getResourceTypeAt(x,y) == resourceType) {
          resourceAmount+=landscapeGrid.getResourceAmountAt(x,y);
        }
      }
      if (resourceAmount != 0) {
        int distanceToCenter=aiStatistics.getPositionOfPartition(playerId).getOnGridDistTo(point);
        int score=resourceAmount - (int)(distanceToCenter * DISTANCE_PENALTY_FACTOR);
        scoredConstructionPositions.add(new ScoredConstructionPosition(point,-score));
      }
    }
  }
  return ScoredConstructionPosition.detectPositionWithLowestScore(scoredConstructionPositions);
}
Program: 55609
Project: 55609
Buggy source:
private ArmyGeneral determineArmyGeneral(EPlayerType type,ECivilisation civilisation,AiStatistics aiStatistics,Player player,MovableGrid movableGrid,ITaskScheduler taskScheduler){
  return new ConfigurableGeneral(aiStatistics,player,movableGrid,taskScheduler,ATTACKER_COUNT_FACTOR[type.ordinal()]);
}

Fixed version (ground truth):
private ArmyGeneral determineArmyGeneral(EPlayerType playerType,ECivilisation civilisation,AiStatistics aiStatistics,Player player,MovableGrid movableGrid,ITaskScheduler taskScheduler){
  return new ConfigurableGeneral(aiStatistics,player,movableGrid,taskScheduler,playerType);
}
Program: 55610
Project: 55610
Buggy source:
private EconomyMinister determineMinister(EPlayerType type,ECivilisation civilisation,AiStatistics aiStatistics,Player player){
switch (type) {
case AI_VERY_EASY:
    return new BuildingListEconomyMinister(aiStatistics,player,1F / 8F,1F / 4F,true);
case AI_EASY:
  return new BuildingListEconomyMinister(aiStatistics,player,1F / 4F,1F / 2F,false);
case AI_HARD:
return new BuildingListEconomyMinister(aiStatistics,player,1F / 2F,3F / 4F,false);
default :
return new BuildingListEconomyMinister(aiStatistics,player,1F,1F,false);
}
}

Fixed version (ground truth):
private EconomyMinister determineMinister(EPlayerType type,ECivilisation civilisation,AiStatistics aiStatistics,Player player){
switch (type) {
case AI_VERY_EASY:
    return new BuildingListEconomyMinister(aiStatistics,player,1F / 10F,1F / 5F,true);
case AI_EASY:
  return new BuildingListEconomyMinister(aiStatistics,player,1F / 4F,1F / 2F,false);
case AI_HARD:
return new BuildingListEconomyMinister(aiStatistics,player,1F / 2F,3F / 4F,false);
default :
return new BuildingListEconomyMinister(aiStatistics,player,1F,1F,false);
}
}
Program: 55611
Project: 55611
Buggy source:
private void changeTowerSoldiers(ChangeTowerSoldiersGuiTask soldierTask){
  ShortPoint2D buildingPosition=soldierTask.getBuildingPos();
  OccupyingBuilding occupyingBuilding=(OccupyingBuilding)grid.getBuildingAt(buildingPosition.x,buildingPosition.y);
switch (soldierTask.getTaskType()) {
case FULL:
    occupyingBuilding.requestSoldiers();
  break;
case MORE:
occupyingBuilding.requestSoldier(soldierTask.getSoldierType());
break;
case ONE:
occupyingBuilding.releaseSoldiers();
break;
case LESS:
occupyingBuilding.releaseSoldier(soldierTask.getSoldierType());
break;
}
}

Fixed version (ground truth):
private void changeTowerSoldiers(ChangeTowerSoldiersGuiTask soldierTask){
  ShortPoint2D buildingPosition=soldierTask.getBuildingPos();
  OccupyingBuilding occupyingBuilding=(OccupyingBuilding)grid.getBuildingAt(buildingPosition.x,buildingPosition.y);
switch (soldierTask.getTaskType()) {
case FULL:
    occupyingBuilding.requestFullSoldiers();
  break;
case MORE:
occupyingBuilding.requestSoldier(soldierTask.getSoldierType());
break;
case ONE:
occupyingBuilding.releaseSoldiers();
break;
case LESS:
occupyingBuilding.releaseSoldier(soldierTask.getSoldierType());
break;
}
}
Program: 55612
Project: 55612
Buggy source:
private void initSoldierRequests(){
  final OccupierPlace[] occupierPlaces=super.getBuildingType().getOccupierPlaces();
  if (occupierPlaces.length > 0) {
    emptyPlaces.addAll(Arrays.asList(occupierPlaces));
    requestSoldiers();
  }
}

Fixed version (ground truth):
private void initSoldierRequests(){
  final OccupierPlace[] occupierPlaces=super.getBuildingType().getOccupierPlaces();
  if (occupierPlaces.length > 0) {
    emptyPlaces.addAll(Arrays.asList(occupierPlaces));
    requestSoldier(ESoldierClass.INFANTRY);
  }
}
Program: 55613
Project: 55613
Buggy source:
@Test public void easyShouldConquerVeryEasy() throws MapLoadException {
  holdBattleBetween(EPlayerType.AI_EASY,EPlayerType.AI_VERY_EASY,65 * MINUTES);
}

Fixed version (ground truth):
@Test public void easyShouldConquerVeryEasy() throws MapLoadException {
  holdBattleBetween(EPlayerType.AI_EASY,EPlayerType.AI_VERY_EASY,75 * MINUTES);
}
Program: 55614
Project: 55614
Buggy source:
public T getFront(){
  return head.next;
}

Fixed version (ground truth):
/** 
 * gets the first item in the list without removing it from the list.
 * @return
 */
public T getFront(){
  return head.next;
}
Program: 55615
Project: 55615
Buggy source:
public void remove(DoubleLinkedListItem<T> item){
  item.prev.next=item.next;
  item.next.prev=item.prev;
  size--;
}

Fixed version (ground truth):
public void remove(DoubleLinkedListItem<T> item){
  item.prev.next=item.next;
  item.next.prev=item.prev;
  size--;
  item.next=null;
  item.prev=null;
}
Program: 55616
Project: 55616
Buggy source:
@Test public void testRemoveByHandle(){
  DoubleLinkedIntListItem handles[]=new DoubleLinkedIntListItem[TEST_NUMBERS];
  for (int i=0; i < TEST_NUMBERS; i++) {
    handles[i]=new DoubleLinkedIntListItem(i);
    list.pushFront(handles[i]);
  }
  list.remove(handles[4]);
  list.remove(handles[7]);
  assertEquals(TEST_NUMBERS - 2,list.size());
  for (int i=TEST_NUMBERS - 1; i >= 0; i--) {
    if (i == 4 || i == 7) {
      continue;
    }
    assertEquals(i,list.popFront().value);
  }
  assertEquals(0,list.size());
}

Fixed version (ground truth):
@Test public void testRemoveByHandle(){
  DoubleLinkedIntListItem handles[]=new DoubleLinkedIntListItem[TEST_NUMBERS];
  for (int i=0; i < TEST_NUMBERS; i++) {
    handles[i]=new DoubleLinkedIntListItem(i);
    list.pushFront(handles[i]);
  }
  list.remove(handles[4]);
  list.remove(handles[7]);
  assertEquals("String_Node_Str",TEST_NUMBERS - 2,list.size());
  assertNull("String_Node_Str",handles[4].next);
  assertNull("String_Node_Str",handles[4].prev);
  assertNull("String_Node_Str",handles[7].next);
  assertNull("String_Node_Str",handles[7].prev);
  for (int i=TEST_NUMBERS - 1; i >= 0; i--) {
    if (i == 4 || i == 7) {
      continue;
    }
    assertEquals(i,list.popFront().value);
  }
  assertEquals("String_Node_Str",0,list.size());
}
Program: 55617
Project: 55617
Buggy source:
@Override public void commandTroops(Set<Integer> soldiersWithOrders){
  SoldierPositions soldierPositions=calculateSituation(player.playerId);
  if (aiStatistics.getEnemiesInTownOf(player.playerId).size() > 0) {
    defend(soldierPositions,soldiersWithOrders);
  }
 else   if (existsAliveEnemy()) {
    IPlayer weakestEnemy=getWeakestEnemy();
    SoldierPositions enemySoldierPositions=calculateSituation(weakestEnemy.getPlayerId());
    boolean infantryWouldDie=wouldInfantryDie(enemySoldierPositions);
    if (attackIsPossible(soldierPositions,enemySoldierPositions,infantryWouldDie)) {
      attack(soldierPositions,infantryWouldDie,soldiersWithOrders);
    }
  }
}

Fixed version (ground truth):
@Override public void commandTroops(Set<Integer> soldiersWithOrders){
  ensureAllTowersFullyMounted();
  SoldierPositions soldierPositions=calculateSituation(player.playerId);
  if (aiStatistics.getEnemiesInTownOf(player.playerId).size() > 0) {
    defend(soldierPositions,soldiersWithOrders);
  }
 else   if (existsAliveEnemy()) {
    IPlayer weakestEnemy=getWeakestEnemy();
    SoldierPositions enemySoldierPositions=calculateSituation(weakestEnemy.getPlayerId());
    boolean infantryWouldDie=wouldInfantryDie(enemySoldierPositions);
    if (attackIsPossible(soldierPositions,enemySoldierPositions,infantryWouldDie)) {
      attack(soldierPositions,infantryWouldDie,soldiersWithOrders);
    }
  }
}
Program: 55618
Project: 55618
Buggy source:
public ConfigurableGeneral(AiStatistics aiStatistics,Player player,MovableGrid movableGrid,ITaskScheduler taskScheduler,float attackerCountFactor){
  this.aiStatistics=aiStatistics;
  this.player=player;
  this.taskScheduler=taskScheduler;
  this.movableGrid=movableGrid;
  this.attackerCountFactor=attackerCountFactor;
}

Fixed version (ground truth):
public ConfigurableGeneral(AiStatistics aiStatistics,Player player,MovableGrid movableGrid,ITaskScheduler taskScheduler,EPlayerType playerType){
  this.aiStatistics=aiStatistics;
  this.player=player;
  this.taskScheduler=taskScheduler;
  this.movableGrid=movableGrid;
  this.attackerCountFactor=ATTACKER_COUNT_FACTOR_BY_PLAYER_TYPE[playerType.ordinal()];
}
Program: 55619
Project: 55619
Buggy source:
@Override public ShortPoint2D findBestConstructionPosition(AiStatistics aiStatistics,AbstractConstructionMarkableMap constructionMap,byte playerId){
  List<ScoredConstructionPosition> scoredConstructionPositions=new ArrayList<>();
  for (  ShortPoint2D point : aiStatistics.getLandForPlayer(playerId)) {
    if (constructionMap.canConstructAt(point.x,point.y,buildingType,playerId)) {
      int resourceAmount=0;
      LandscapeGrid landscapeGrid=aiStatistics.getMainGrid().getLandscapeGrid();
      for (      RelativePoint relativePoint : buildingType.getBlockedTiles()) {
        int x=point.x + relativePoint.getDx();
        int y=point.y + relativePoint.getDy();
        if (landscapeGrid.getResourceTypeAt(x,y) == resourceType) {
          resourceAmount-=landscapeGrid.getResourceAmountAt(x,y);
        }
      }
      if (resourceAmount != 0) {
        scoredConstructionPositions.add(new ScoredConstructionPosition(point,resourceAmount));
      }
    }
  }
  return ScoredConstructionPosition.detectPositionWithLowestScore(scoredConstructionPositions);
}

Fixed version (ground truth):
@Override public ShortPoint2D findBestConstructionPosition(AiStatistics aiStatistics,AbstractConstructionMarkableMap constructionMap,byte playerId){
  List<ScoredConstructionPosition> scoredConstructionPositions=new ArrayList<>();
  for (  ShortPoint2D point : aiStatistics.getLandForPlayer(playerId)) {
    if (constructionMap.canConstructAt(point.x,point.y,buildingType,playerId)) {
      int resourceAmount=0;
      LandscapeGrid landscapeGrid=aiStatistics.getMainGrid().getLandscapeGrid();
      for (      RelativePoint relativePoint : buildingType.getBlockedTiles()) {
        int x=point.x + relativePoint.getDx();
        int y=point.y + relativePoint.getDy();
        if (landscapeGrid.getResourceTypeAt(x,y) == resourceType) {
          resourceAmount+=landscapeGrid.getResourceAmountAt(x,y);
        }
      }
      if (resourceAmount != 0) {
        int distanceToCenter=aiStatistics.getPositionOfPartition(playerId).getOnGridDistTo(point);
        int score=resourceAmount - (int)(distanceToCenter * DISTANCE_PENALTY_FACTOR);
        scoredConstructionPositions.add(new ScoredConstructionPosition(point,-score));
      }
    }
  }
  return ScoredConstructionPosition.detectPositionWithLowestScore(scoredConstructionPositions);
}
Program: 55620
Project: 55620
Buggy source:
private ArmyGeneral determineArmyGeneral(EPlayerType type,ECivilisation civilisation,AiStatistics aiStatistics,Player player,MovableGrid movableGrid,ITaskScheduler taskScheduler){
  return new ConfigurableGeneral(aiStatistics,player,movableGrid,taskScheduler,ATTACKER_COUNT_FACTOR[type.ordinal()]);
}

Fixed version (ground truth):
private ArmyGeneral determineArmyGeneral(EPlayerType playerType,ECivilisation civilisation,AiStatistics aiStatistics,Player player,MovableGrid movableGrid,ITaskScheduler taskScheduler){
  return new ConfigurableGeneral(aiStatistics,player,movableGrid,taskScheduler,playerType);
}
Program: 55621
Project: 55621
Buggy source:
private EconomyMinister determineMinister(EPlayerType type,ECivilisation civilisation,AiStatistics aiStatistics,Player player){
switch (type) {
case AI_VERY_EASY:
    return new BuildingListEconomyMinister(aiStatistics,player,1F / 8F,1F / 4F,true);
case AI_EASY:
  return new BuildingListEconomyMinister(aiStatistics,player,1F / 4F,1F / 2F,false);
case AI_HARD:
return new BuildingListEconomyMinister(aiStatistics,player,1F / 2F,3F / 4F,false);
default :
return new BuildingListEconomyMinister(aiStatistics,player,1F,1F,false);
}
}

Fixed version (ground truth):
private EconomyMinister determineMinister(EPlayerType type,ECivilisation civilisation,AiStatistics aiStatistics,Player player){
switch (type) {
case AI_VERY_EASY:
    return new BuildingListEconomyMinister(aiStatistics,player,1F / 10F,1F / 5F,true);
case AI_EASY:
  return new BuildingListEconomyMinister(aiStatistics,player,1F / 4F,1F / 2F,false);
case AI_HARD:
return new BuildingListEconomyMinister(aiStatistics,player,1F / 2F,3F / 4F,false);
default :
return new BuildingListEconomyMinister(aiStatistics,player,1F,1F,false);
}
}
Program: 55622
Project: 55622
Buggy source:
public BooleanMovingAverage(int numberOfValues,boolean defaultValue){
  values=new boolean[numberOfValues];
  if (defaultValue) {
    for (int i=0; i < numberOfValues; i++) {
      values[i]=defaultValue;
    }
    count=numberOfValues;
  }
}

Fixed version (ground truth):
/** 
 * Creates a fix sized boolean array filled with the default value.
 * @param numberOfValues the length of the array
 * @param defaultValue the default value to fill all entries of the array
 */
public BooleanMovingAverage(int numberOfValues,boolean defaultValue){
  values=new boolean[numberOfValues];
  if (defaultValue) {
    Arrays.fill(values,defaultValue);
    countTrue=numberOfValues;
  }
}
Program: 55623
Project: 55623
Buggy source:
public float getAverage(){
  return ((float)count) / values.length;
}

Fixed version (ground truth):
public float getAverage(){
  return ((float)countTrue) / values.length;
}
Program: 55624
Project: 55624
Buggy source:
NewFoWThread(){
  super("String_Node_Str");
  super.setDaemon(true);
  this.buffer=new byte[width][height];
  drawer=new CircleDrawer();
}

Fixed version (ground truth):
NewFoWThread(){
  super("String_Node_Str");
  super.setDaemon(true);
}
Program: 55625
Project: 55625
Buggy source:
@Override public final void run(){
  mySleep(500);
  while (!canceled) {
    if (enabled) {
      rebuildSight();
    }
    mySleep(800);
  }
}

Fixed version (ground truth):
@Override public final void run(){
  mySleep(500L);
  while (!canceled) {
    if (enabled) {
      rebuildSight();
    }
    mySleep(800L);
  }
}
Program: 55626
Project: 55626
Buggy source:
private void mySleep(int ms){
  try {
    Thread.sleep(ms);
  }
 catch (  InterruptedException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
private void mySleep(long ms){
  try {
    Thread.sleep(ms);
  }
 catch (  InterruptedException e) {
    e.printStackTrace();
  }
}
Program: 55627
Project: 55627
Buggy source:
private void rebuildSight(){
  drawer.setBuffer(buffer);
  for (int x=0; x < width; x++) {
    for (int y=0; y < height; y++) {
      byte currSight=sight[x][y];
      if (currSight >= CommonConstants.FOG_OF_WAR_EXPLORED) {
        byte newSight=(byte)(currSight - DIM_DOWN_SPEED);
        if (newSight < CommonConstants.FOG_OF_WAR_EXPLORED) {
          buffer[x][y]=CommonConstants.FOG_OF_WAR_EXPLORED;
        }
 else {
          buffer[x][y]=newSight;
        }
      }
 else {
        buffer[x][y]=sight[x][y];
      }
    }
  }
  ConcurrentLinkedQueue<? extends IViewDistancable> buildings=grid.getBuildingViewDistancables();
  applyViewDistances(buildings);
  ConcurrentLinkedQueue<? extends IViewDistancable> movables=grid.getMovableViewDistancables();
  applyViewDistances(movables);
  byte[][] temp=sight;
  sight=buffer;
  buffer=temp;
}

Fixed version (ground truth):
private void rebuildSight(){
  drawer.setBuffer(buffer);
  for (short x=0; x < width; x++) {
    for (short y=0; y < height; y++) {
      byte currSight=sight[x][y];
      if (currSight >= CommonConstants.FOG_OF_WAR_EXPLORED) {
        byte newSight=(byte)(currSight - DIM_DOWN_SPEED);
        if (newSight < CommonConstants.FOG_OF_WAR_EXPLORED) {
          buffer[x][y]=CommonConstants.FOG_OF_WAR_EXPLORED;
        }
 else {
          buffer[x][y]=newSight;
        }
      }
 else {
        buffer[x][y]=sight[x][y];
      }
    }
  }
  ConcurrentLinkedQueue<? extends IViewDistancable> buildings=grid.getBuildingViewDistancables();
  applyViewDistances(buildings);
  ConcurrentLinkedQueue<? extends IViewDistancable> movables=grid.getMovableViewDistancables();
  applyViewDistances(movables);
  byte[][] temp=sight;
  sight=buffer;
  buffer=temp;
}
Program: 55628
Project: 55628
Buggy source:
private void changeTowerSoldiers(ChangeTowerSoldiersGuiTask soldierTask){
  ShortPoint2D buildingPosition=soldierTask.getBuildingPos();
  OccupyingBuilding occupyingBuilding=(OccupyingBuilding)grid.getBuildingAt(buildingPosition.x,buildingPosition.y);
switch (soldierTask.getTaskType()) {
case FULL:
    occupyingBuilding.requestSoldiers();
  break;
case MORE:
occupyingBuilding.requestSoldier(soldierTask.getSoldierType());
break;
case ONE:
occupyingBuilding.releaseSoldiers();
break;
case LESS:
occupyingBuilding.releaseSoldier(soldierTask.getSoldierType());
break;
}
}

Fixed version (ground truth):
private void changeTowerSoldiers(ChangeTowerSoldiersGuiTask soldierTask){
  ShortPoint2D buildingPosition=soldierTask.getBuildingPos();
  OccupyingBuilding occupyingBuilding=(OccupyingBuilding)grid.getBuildingAt(buildingPosition.x,buildingPosition.y);
switch (soldierTask.getTaskType()) {
case FULL:
    occupyingBuilding.requestFullSoldiers();
  break;
case MORE:
occupyingBuilding.requestSoldier(soldierTask.getSoldierType());
break;
case ONE:
occupyingBuilding.releaseSoldiers();
break;
case LESS:
occupyingBuilding.releaseSoldier(soldierTask.getSoldierType());
break;
}
}
Program: 55629
Project: 55629
Buggy source:
private void initSoldierRequests(){
  final OccupierPlace[] occupierPlaces=super.getBuildingType().getOccupierPlaces();
  if (occupierPlaces.length > 0) {
    emptyPlaces.addAll(Arrays.asList(occupierPlaces));
    requestSoldiers();
  }
}

Fixed version (ground truth):
private void initSoldierRequests(){
  final OccupierPlace[] occupierPlaces=super.getBuildingType().getOccupierPlaces();
  if (occupierPlaces.length > 0) {
    emptyPlaces.addAll(Arrays.asList(occupierPlaces));
    requestSoldier(ESoldierClass.INFANTRY);
  }
}
Program: 55630
Project: 55630
Buggy source:
public BooleanMovingAverage(int numberOfValues,boolean defaultValue){
  values=new boolean[numberOfValues];
  if (defaultValue) {
    for (int i=0; i < numberOfValues; i++) {
      values[i]=defaultValue;
    }
    count=numberOfValues;
  }
}

Fixed version (ground truth):
/** 
 * Creates a fix sized boolean array filled with the default value.
 * @param numberOfValues the length of the array
 * @param defaultValue the default value to fill all entries of the array
 */
public BooleanMovingAverage(int numberOfValues,boolean defaultValue){
  values=new boolean[numberOfValues];
  if (defaultValue) {
    Arrays.fill(values,defaultValue);
    countTrue=numberOfValues;
  }
}
Program: 55631
Project: 55631
Buggy source:
public float getAverage(){
  return ((float)count) / values.length;
}

Fixed version (ground truth):
public float getAverage(){
  return ((float)countTrue) / values.length;
}
Program: 55632
Project: 55632
Buggy source:
protected void productivityActionExecuted(boolean successfully){
  movingAverage.inserValue(successfully);
}

Fixed version (ground truth):
protected void productivityActionExecuted(boolean successfully){
  movingAverage.insertValue(successfully);
}
Program: 55633
Project: 55633
Buggy source:
void addStartTowerMaterialsAndSettlers(EMapStartResources startResources){
  if (hasBuildings) {
    return;
  }
  int playerCount=mapData.getPlayerCount();
  for (byte playerId=0; playerId < playerCount; playerId++) {
    ShortPoint2D startPoint=mapData.getStartPoint(playerId);
    mapData.setMapObject(startPoint.x,startPoint.y,new BuildingMapDataObject(EBuildingType.TOWER,playerId));
    List<MapDataObject> mapObjects=EMapStartResources.generateStackObjects(startResources);
    mapObjects.addAll(EMapStartResources.generateMovableObjects(startResources,playerId));
    List<RelativePoint> towerTiles=Arrays.asList(EBuildingType.TOWER.getProtectedTiles());
    RelativePoint relativeMapObjectPoint=new RelativePoint(-3,3);
    for (    MapDataObject currentMapObject : mapObjects) {
      do {
        relativeMapObjectPoint=nextPointOnSpiral(relativeMapObjectPoint);
        if (towerTiles.contains(relativeMapObjectPoint)) {
          continue;
        }
        int x=relativeMapObjectPoint.calculateX(startPoint.x);
        int y=relativeMapObjectPoint.calculateY(startPoint.y);
        if (mapData.getMapObject(x,y) == null) {
          mapData.setMapObject(x,y,currentMapObject);
          break;
        }
      }
 while (true);
    }
  }
}

Fixed version (ground truth):
public void addStartTowerMaterialsAndSettlers(EMapStartResources startResources,PlayerSetting[] playerSettings){
  if (hasBuildings) {
    return;
  }
  int playerCount=mapData.getPlayerCount();
  for (byte playerId=0; playerId < playerCount; playerId++) {
    if (playerSettings != null && !playerSettings[playerId].isAvailable())     continue;
    ShortPoint2D startPoint=mapData.getStartPoint(playerId);
    mapData.setMapObject(startPoint.x,startPoint.y,new BuildingMapDataObject(EBuildingType.TOWER,playerId));
    List<MapDataObject> mapObjects=EMapStartResources.generateStackObjects(startResources);
    mapObjects.addAll(EMapStartResources.generateMovableObjects(startResources,playerId));
    List<RelativePoint> towerTiles=Arrays.asList(EBuildingType.TOWER.getProtectedTiles());
    RelativePoint relativeMapObjectPoint=new RelativePoint(-3,3);
    for (    MapDataObject currentMapObject : mapObjects) {
      do {
        relativeMapObjectPoint=nextPointOnSpiral(relativeMapObjectPoint);
        if (towerTiles.contains(relativeMapObjectPoint)) {
          continue;
        }
        int x=relativeMapObjectPoint.calculateX(startPoint.x);
        int y=relativeMapObjectPoint.calculateY(startPoint.y);
        if (mapData.getMapObject(x,y) == null) {
          mapData.setMapObject(x,y,currentMapObject);
          break;
        }
      }
 while (true);
    }
  }
}
Program: 55634
Project: 55634
Buggy source:
@Override public IMapData getMapData() throws MapLoadException {
  loadMapContent(EMapStartResources.HIGH_GOODS);
  OriginalMapFileContent mapData=mapContent.mapData;
  mapData.calculateBlockedPartitions();
  return mapData;
}

Fixed version (ground truth):
@Override public IMapData getMapData() throws MapLoadException {
  loadMapContent(EMapStartResources.HIGH_GOODS,null);
  OriginalMapFileContent mapData=mapContent.mapData;
  mapData.calculateBlockedPartitions();
  return mapData;
}