nus-yam/ex-repair huggingface dataset:
Program: 1099
Project: 1099
Buggy source:
public void updateNetworkEntity(EntityRef entity){
  NetworkComponent netComponent=entity.getComponent(NetworkComponent.class);
  if (netComponent.getNetworkId() == 0) {
    return;
  }
  EntityRef lastOwnerEntity=ownerLookup.get(entity);
  if (lastOwnerEntity == null) {
    lastOwnerEntity=EntityRef.NULL;
  }
  if (!Objects.equal(lastOwnerEntity,netComponent.owner)) {
    NetClient lastOwner=getNetOwner(lastOwnerEntity);
    NetClient newOwner=getNetOwner(netComponent.owner);
    if (!Objects.equal(lastOwner,newOwner)) {
      recursiveUpdateOwnership(entity,lastOwner,newOwner);
      if (newOwner != null) {
        int id=netComponent.getNetworkId();
        for (        Component component : entity.iterateComponents()) {
          if (entitySystemLibrary.getComponentLibrary().getMetadata(component.getClass()).isReplicated()) {
            newOwner.setComponentDirty(id,component.getClass());
          }
        }
      }
    }
    if (lastOwnerEntity.exists()) {
      ownedLookup.remove(lastOwnerEntity,entity);
    }
    if (netComponent.owner.exists()) {
      ownerLookup.put(entity,netComponent.owner);
      ownedLookup.put(netComponent.owner,entity);
    }
 else {
      ownerLookup.remove(entity);
    }
  }
}

Fixed version (ground truth):
public void updateNetworkEntity(EntityRef entity){
  NetworkComponent netComponent=entity.getComponent(NetworkComponent.class);
  if (netComponent.getNetworkId() == NULL_NET_ID) {
    return;
  }
  EntityRef lastOwnerEntity=ownerLookup.get(entity);
  if (lastOwnerEntity == null) {
    lastOwnerEntity=EntityRef.NULL;
  }
  if (!Objects.equal(lastOwnerEntity,netComponent.owner)) {
    NetClient lastOwner=getNetOwner(lastOwnerEntity);
    NetClient newOwner=getNetOwner(netComponent.owner);
    if (!Objects.equal(lastOwner,newOwner)) {
      recursiveUpdateOwnership(entity,lastOwner,newOwner);
      if (newOwner != null) {
        int id=netComponent.getNetworkId();
        for (        Component component : entity.iterateComponents()) {
          if (entitySystemLibrary.getComponentLibrary().getMetadata(component.getClass()).isReplicated()) {
            newOwner.setComponentDirty(id,component.getClass());
          }
        }
      }
    }
    if (lastOwnerEntity.exists()) {
      ownedLookup.remove(lastOwnerEntity,entity);
    }
    if (netComponent.owner.exists()) {
      ownerLookup.put(entity,netComponent.owner);
      ownedLookup.put(netComponent.owner,entity);
    }
 else {
      ownerLookup.remove(entity);
    }
  }
}
Program: 1100
Project: 1100
Buggy source:
public void unregisterNetworkEntity(EntityRef entity){
  NetworkComponent netComponent=entity.getComponent(NetworkComponent.class);
  if (netComponent != null) {
    logger.debug("String_Node_Str",entity,netComponent.getNetworkId());
    netIdToEntityId.remove(netComponent.getNetworkId());
    if (mode == NetworkMode.SERVER) {
      for (      NetClient client : netClientList) {
        client.setNetRemoved(netComponent.getNetworkId());
      }
    }
    netComponent.setNetworkId(0);
    entity.saveComponent(netComponent);
  }
  ownerLookup.remove(entity);
}

Fixed version (ground truth):
public void unregisterNetworkEntity(EntityRef entity){
  NetworkComponent netComponent=entity.getComponent(NetworkComponent.class);
  if (netComponent != null) {
    logger.debug("String_Node_Str",entity,netComponent.getNetworkId());
    netIdToEntityId.remove(netComponent.getNetworkId());
    if (mode == NetworkMode.SERVER) {
      for (      NetClient client : netClientList) {
        client.setNetRemoved(netComponent.getNetworkId());
      }
    }
    netComponent.setNetworkId(NULL_NET_ID);
    entity.saveComponent(netComponent);
  }
  ownerLookup.remove(entity);
}
Program: 1101
Project: 1101
Buggy source:
@Override public void shutdown(){
  if (mode != NetworkMode.NONE) {
    allChannels.close().awaitUninterruptibly();
    factory.releaseExternalResources();
  }
  processPendingDisconnects();
  for (  Client client : clientList) {
    processRemovedClient(client);
  }
  mode=NetworkMode.NONE;
  server=null;
  nextNetId=1;
  netIdToEntityId.clear();
  if (this.entityManager != null) {
    this.entityManager.unsubscribe(this);
  }
  entityManager=null;
  entitySystemLibrary=null;
  eventSerializer=null;
  entitySerializer=null;
  clientList.clear();
  netClientList.clear();
  logger.info("String_Node_Str");
}

Fixed version (ground truth):
@Override public void shutdown(){
  if (mode != NetworkMode.NONE) {
    allChannels.close().awaitUninterruptibly();
    factory.releaseExternalResources();
  }
  processPendingDisconnects();
  for (  Client client : clientList) {
    processRemovedClient(client);
  }
  mode=NetworkMode.NONE;
  server=null;
  nextNetId=1;
  netIdToEntityId.clear();
  if (this.entityManager != null) {
    for (    EntityRef entity : entityManager.listEntitiesWith(NetworkComponent.class)) {
      NetworkComponent netComp=entity.getComponent(NetworkComponent.class);
      netComp.setNetworkId(0);
      entity.saveComponent(netComp);
    }
    this.entityManager.unsubscribe(this);
  }
  entityManager=null;
  entitySystemLibrary=null;
  eventSerializer=null;
  entitySerializer=null;
  clientList.clear();
  netClientList.clear();
  logger.info("String_Node_Str");
}
Program: 1102
Project: 1102
Buggy source:
private void createEntityMessage(NetData.CreateEntityMessage message){
  EntityRef newEntity;
  if (message.hasBlockPos()) {
    newEntity=blockEntityRegistry.getOrCreateBlockEntityAt(NetMessageUtil.convert(message.getBlockPos()));
    entitySerializer.deserializeOnto(newEntity,message.getEntity());
  }
 else {
    newEntity=entitySerializer.deserialize(message.getEntity());
  }
  if (newEntity == null) {
    logger.error("String_Node_Str");
  }
 else   if (newEntity.getComponent(NetworkComponent.class) == null) {
    logger.error("String_Node_Str",newEntity);
  }
 else   if (newEntity.getComponent(NetworkComponent.class).getNetworkId() == 0) {
    logger.error("String_Node_Str",newEntity);
  }
  logger.info("String_Node_Str",newEntity,newEntity.getComponent(NetworkComponent.class).getNetworkId());
  networkSystem.registerNetworkEntity(newEntity);
}

Fixed version (ground truth):
private void createEntityMessage(NetData.CreateEntityMessage message){
  EntityRef newEntity=entitySerializer.deserialize(message.getEntity());
  if (newEntity == null) {
    logger.error("String_Node_Str");
  }
 else   if (newEntity.getComponent(NetworkComponent.class) == null) {
    logger.error("String_Node_Str",newEntity);
  }
 else   if (newEntity.getComponent(NetworkComponent.class).getNetworkId() == 0) {
    logger.error("String_Node_Str",newEntity);
  }
  logger.info("String_Node_Str",newEntity,newEntity.getComponent(NetworkComponent.class).getNetworkId());
  networkSystem.registerNetworkEntity(newEntity);
}
Program: 1103
Project: 1103
Buggy source:
@Override public boolean step(){
  ComponentSystemManager componentSystemManager=CoreRegistry.get(ComponentSystemManager.class);
  for (  UpdateSubscriberSystem updater : componentSystemManager.iterateUpdateSubscribers()) {
    updater.update(0.0f);
  }
  LocalPlayer localPlayer=CoreRegistry.get(LocalPlayer.class);
  ClientComponent client=localPlayer.getClientEntity().getComponent(ClientComponent.class);
  if (client != null && client.character.exists()) {
    worldRenderer.setPlayer(CoreRegistry.get(LocalPlayer.class));
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean step(){
  ComponentSystemManager componentSystemManager=CoreRegistry.get(ComponentSystemManager.class);
  for (  UpdateSubscriberSystem updater : componentSystemManager.iterateUpdateSubscribers()) {
    updater.update(0.0f);
  }
  LocalPlayer localPlayer=CoreRegistry.get(LocalPlayer.class);
  ClientComponent client=localPlayer.getClientEntity().getComponent(ClientComponent.class);
  if (client != null && client.character.exists()) {
    worldRenderer.setPlayer(CoreRegistry.get(LocalPlayer.class));
    return true;
  }
 else {
    worldRenderer.getChunkProvider().update();
  }
  return false;
}
Program: 1104
Project: 1104
Buggy source:
@ReceiveEvent(components=ClientComponent.class) public void onConnect(ConnectedEvent connected,EntityRef entity){
  worldRenderer.getChunkProvider().addRelevanceEntity(entity,4,networkSystem.getOwner(entity));
  if (connected.getEntityStore().hasCharacter()) {
    LocationComponent location=entity.getComponent(LocationComponent.class);
    location.setWorldPosition(connected.getEntityStore().getRelevanceLocation());
    entity.saveComponent(location);
    if (worldRenderer.getWorldProvider().isBlockActive(connected.getEntityStore().getRelevanceLocation())) {
      restoreCharacter(entity,connected.getEntityStore());
    }
 else {
      SpawningClientInfo spawningClientInfo=new SpawningClientInfo(entity,connected.getEntityStore().getRelevanceLocation(),connected.getEntityStore());
      clientsPreparingToSpawn.add(spawningClientInfo);
    }
  }
 else {
    Vector3i pos=Vector3i.zero();
    if (chunkProvider.getChunk(pos) != null) {
      spawnPlayer(entity,new Vector3i(Chunk.SIZE_X / 2,Chunk.SIZE_Y,Chunk.SIZE_Z / 2));
    }
 else {
      LocationComponent location=entity.getComponent(LocationComponent.class);
      location.setWorldPosition(new Vector3f(Chunk.SIZE_X / 2,Chunk.SIZE_Y / 2,Chunk.SIZE_Z / 2));
      entity.saveComponent(location);
      SpawningClientInfo spawningClientInfo=new SpawningClientInfo(entity,new Vector3f(Chunk.SIZE_X / 2,Chunk.SIZE_Y / 2,Chunk.SIZE_Z / 2));
      clientsPreparingToSpawn.add(spawningClientInfo);
    }
  }
}

Fixed version (ground truth):
@ReceiveEvent(components=ClientComponent.class) public void onConnect(ConnectedEvent connected,EntityRef entity){
  LocationComponent loc=entity.getComponent(LocationComponent.class);
  loc.setWorldPosition(connected.getEntityStore().getRelevanceLocation());
  entity.saveComponent(loc);
  worldRenderer.getChunkProvider().addRelevanceEntity(entity,4,networkSystem.getOwner(entity));
  if (connected.getEntityStore().hasCharacter()) {
    if (worldRenderer.getWorldProvider().isBlockActive(connected.getEntityStore().getRelevanceLocation())) {
      restoreCharacter(entity,connected.getEntityStore());
    }
 else {
      SpawningClientInfo spawningClientInfo=new SpawningClientInfo(entity,connected.getEntityStore().getRelevanceLocation(),connected.getEntityStore());
      clientsPreparingToSpawn.add(spawningClientInfo);
    }
  }
 else {
    Vector3i pos=Vector3i.zero();
    if (chunkProvider.getChunk(pos) != null) {
      spawnPlayer(entity,new Vector3i(Chunk.SIZE_X / 2,Chunk.SIZE_Y,Chunk.SIZE_Z / 2));
    }
 else {
      SpawningClientInfo spawningClientInfo=new SpawningClientInfo(entity,new Vector3f(Chunk.SIZE_X / 2,Chunk.SIZE_Y / 2,Chunk.SIZE_Z / 2));
      clientsPreparingToSpawn.add(spawningClientInfo);
    }
  }
}
Program: 1105
Project: 1105
Buggy source:
private void restoreCharacter(EntityRef entity,PlayerEntityStore playerEntityStore){
  Map<String,EntityRef> restoredEntities=playerEntityStore.restoreAll();
  EntityRef character=restoredEntities.get("String_Node_Str");
  if (character == null) {
    spawnPlayer(entity,new Vector3i(Chunk.SIZE_X / 2,Chunk.SIZE_Y,Chunk.SIZE_Z / 2));
  }
 else {
    Client clientListener=networkSystem.getOwner(entity);
    int distance=clientListener.getViewDistance();
    if (!clientListener.isLocal()) {
      distance+=ChunkConstants.REMOTE_GENERATION_DISTANCE;
    }
    worldRenderer.getChunkProvider().updateRelevanceEntity(entity,distance);
    NetworkComponent netComp=character.getComponent(NetworkComponent.class);
    if (netComp != null) {
      netComp.owner=entity;
      character.saveComponent(netComp);
    }
    ClientComponent client=entity.getComponent(ClientComponent.class);
    client.character=character;
    entity.saveComponent(client);
  }
}

Fixed version (ground truth):
private void restoreCharacter(EntityRef entity,PlayerEntityStore playerEntityStore){
  Map<String,EntityRef> restoredEntities=playerEntityStore.restoreAll();
  EntityRef character=restoredEntities.get("String_Node_Str");
  if (character == null) {
    spawnPlayer(entity,new Vector3i(Chunk.SIZE_X / 2,Chunk.SIZE_Y,Chunk.SIZE_Z / 2));
  }
 else {
    Client clientListener=networkSystem.getOwner(entity);
    int distance=clientListener.getViewDistance();
    if (!clientListener.isLocal()) {
      distance+=ChunkConstants.REMOTE_GENERATION_DISTANCE;
    }
    worldRenderer.getChunkProvider().updateRelevanceEntity(entity,distance);
    NetworkComponent netComp=character.getComponent(NetworkComponent.class);
    if (netComp != null) {
      netComp.owner=entity;
      character.saveComponent(netComp);
    }
    ClientComponent client=entity.getComponent(ClientComponent.class);
    client.character=character;
    entity.saveComponent(client);
    Location.attachChild(character,entity);
  }
}
Program: 1106
Project: 1106
Buggy source:
@Override public void dispose(){
  boolean saveWorld=CoreRegistry.get(NetworkSystem.class).getMode().isAuthority();
  networkSystem.shutdown();
  eventSystem.process();
  componentSystemManager.shutdown();
  guiManager.closeAllWindows();
  if (saveWorld) {
    try {
      CoreRegistry.get(WorldPersister.class).save(new File(PathManager.getInstance().getCurrentWorldPath(),TerasologyConstants.ENTITY_DATA_FILE),WorldPersister.SaveFormat.Binary);
    }
 catch (    IOException e) {
      logger.error("String_Node_Str",e);
    }
  }
  entityManager.clear();
  if (worldRenderer != null) {
    worldRenderer.dispose();
    worldRenderer=null;
  }
}

Fixed version (ground truth):
@Override public void dispose(){
  boolean saveWorld=CoreRegistry.get(NetworkSystem.class).getMode().isAuthority();
  networkSystem.shutdown();
  eventSystem.process();
  componentSystemManager.shutdown();
  guiManager.closeAllWindows();
  if (saveWorld) {
    try {
      CoreRegistry.get(WorldPersister.class).save(new File(PathManager.getInstance().getCurrentWorldPath(),TerasologyConstants.ENTITY_DATA_FILE),WorldPersister.SaveFormat.Binary);
    }
 catch (    IOException e) {
      logger.error("String_Node_Str",e);
    }
  }
  entityManager.clear();
  if (worldRenderer != null) {
    worldRenderer.dispose(saveWorld);
    worldRenderer=null;
  }
}
Program: 1107
Project: 1107
Buggy source:
@Override public void removedForStoring(EntityRef entity){
  if (entity.exists()) {
    int entityId=entity.getId();
    if (eventSystem != null) {
      eventSystem.send(entity,OnDeactivatedEvent.newInstance());
    }
    store.remove(entityId);
  }
}

Fixed version (ground truth):
@Override public void removedForStoring(EntityRef entity){
  if (entity.exists()) {
    int entityId=entity.getId();
    if (eventSystem != null) {
      eventSystem.send(entity,OnDeactivatedEvent.newInstance());
    }
    loadedIds.remove(entityId);
    store.remove(entityId);
  }
}
Program: 1108
Project: 1108
Buggy source:
@Override public EntityRef createEntityWithId(int id,Iterable<Component> components){
  if (!freedIds.contains(id)) {
    EntityRef entity=createEntityRef(id);
    for (    Component c : components) {
      store.put(id,c);
    }
    if (eventSystem != null) {
      eventSystem.send(entity,OnActivatedEvent.newInstance());
    }
    return entity;
  }
  return EntityRef.NULL;
}

Fixed version (ground truth):
@Override public EntityRef createEntityWithId(int id,Iterable<Component> components){
  if (!freedIds.contains(id)) {
    EntityRef entity=createEntityRef(id);
    for (    Component c : components) {
      store.put(id,c);
    }
    loadedIds.add(id);
    if (eventSystem != null) {
      eventSystem.send(entity,OnActivatedEvent.newInstance());
    }
    return entity;
  }
  return EntityRef.NULL;
}
Program: 1109
Project: 1109
Buggy source:
@Override public void clear(){
  store.clear();
  nextEntityId=1;
  freedIds.clear();
  entityCache.clear();
}

Fixed version (ground truth):
@Override public void clear(){
  store.clear();
  nextEntityId=1;
  loadedIds.clear();
  freedIds.clear();
  entityCache.clear();
}
Program: 1110
Project: 1110
Buggy source:
void destroy(int entityId){
  EntityRef ref=createEntityRef(entityId);
  if (eventSystem != null) {
    eventSystem.send(ref,OnDeactivatedEvent.newInstance());
    eventSystem.send(ref,OnRemovedEvent.newInstance());
  }
  for (  Component comp : store.iterateComponents(entityId)) {
    notifyComponentRemoved(ref,comp.getClass());
  }
  entityCache.remove(entityId);
  freedIds.add(entityId);
  if (ref instanceof PojoEntityRef) {
    ((PojoEntityRef)ref).invalidate();
  }
  store.remove(entityId);
}

Fixed version (ground truth):
void destroy(int entityId){
  if (!loadedIds.contains(entityId)) {
    return;
  }
  EntityRef ref=createEntityRef(entityId);
  if (eventSystem != null) {
    eventSystem.send(ref,OnDeactivatedEvent.newInstance());
    eventSystem.send(ref,OnRemovedEvent.newInstance());
  }
  for (  Component comp : store.iterateComponents(entityId)) {
    notifyComponentRemoved(ref,comp.getClass());
  }
  entityCache.remove(entityId);
  loadedIds.remove(entityId);
  freedIds.add(entityId);
  if (ref instanceof PojoEntityRef) {
    ((PojoEntityRef)ref).invalidate();
  }
  store.remove(entityId);
}
Program: 1111
Project: 1111
Buggy source:
public static void attachChild(EntityRef parent,EntityRef child){
  LocationComponent childLoc=child.getComponent(LocationComponent.class);
  LocationComponent parentLoc=parent.getComponent(LocationComponent.class);
  if (childLoc != null && parentLoc != null && !childLoc.getParent().equals(parent)) {
    Vector3f oldWorldPos=childLoc.getWorldPosition();
    LocationComponent oldParentLoc=childLoc.getParent().getComponent(LocationComponent.class);
    if (oldParentLoc != null) {
      oldParentLoc.children.remove(child);
      childLoc.getParent().saveComponent(oldParentLoc);
    }
    childLoc.parent=parent;
    childLoc.setWorldPosition(oldWorldPos);
    parentLoc.children.add(child);
    child.saveComponent(childLoc);
    parent.saveComponent(parentLoc);
  }
}

Fixed version (ground truth):
/** 
 * Attaches an entity to another entity. Both must have location components. The child maintains its previous position and rotation but follows the parent.
 * @param parent
 * @param child
 */
public static void attachChild(EntityRef parent,EntityRef child){
  LocationComponent childLoc=child.getComponent(LocationComponent.class);
  LocationComponent parentLoc=parent.getComponent(LocationComponent.class);
  if (childLoc != null && parentLoc != null && !childLoc.getParent().equals(parent)) {
    Vector3f oldWorldPos=childLoc.getWorldPosition();
    LocationComponent oldParentLoc=childLoc.getParent().getComponent(LocationComponent.class);
    if (oldParentLoc != null) {
      oldParentLoc.children.remove(child);
      childLoc.getParent().saveComponent(oldParentLoc);
    }
    childLoc.parent=parent;
    childLoc.setWorldPosition(oldWorldPos);
    parentLoc.children.add(child);
    child.saveComponent(childLoc);
    parent.saveComponent(parentLoc);
  }
}
Program: 1113
Project: 1113
Buggy source:
private void spawnPlayer(EntityRef clientEntity,Vector3i spawnPos){
  while (worldRenderer.getWorldProvider().getBlock(spawnPos) == BlockManager.getAir() && spawnPos.y > 0) {
    spawnPos.y--;
  }
  ClientComponent client=clientEntity.getComponent(ClientComponent.class);
  if (client != null) {
    PlayerFactory playerFactory=new PlayerFactory(entityManager,inventoryManager);
    EntityRef playerCharacter=playerFactory.newInstance(new Vector3f(spawnPos.x,spawnPos.y + 1.5f,spawnPos.z),clientEntity);
    Location.attachChild(playerCharacter,clientEntity);
    LocationComponent clientLoc=clientEntity.getComponent(LocationComponent.class);
    clientLoc.setLocalPosition(new Vector3f());
    clientLoc.setLocalRotation(new Quat4f(0,0,0,1));
    clientEntity.saveComponent(clientLoc);
    Client clientListener=networkSystem.getOwner(clientEntity);
    int distance=clientListener.getViewDistance();
    if (!clientListener.isLocal()) {
      distance+=ChunkConstants.REMOTE_GENERATION_DISTANCE;
    }
    worldRenderer.getChunkProvider().updateRelevanceEntity(playerCharacter,distance);
    client.character=playerCharacter;
    clientEntity.saveComponent(client);
  }
}

Fixed version (ground truth):
private void spawnPlayer(EntityRef clientEntity,Vector3i spawnPos){
  while (worldRenderer.getWorldProvider().getBlock(spawnPos) == BlockManager.getAir() && spawnPos.y > 0) {
    spawnPos.y--;
  }
  ClientComponent client=clientEntity.getComponent(ClientComponent.class);
  if (client != null) {
    PlayerFactory playerFactory=new PlayerFactory(entityManager,inventoryManager);
    EntityRef playerCharacter=playerFactory.newInstance(new Vector3f(spawnPos.x,spawnPos.y + 1.5f,spawnPos.z),clientEntity);
    Location.attachChild(playerCharacter,clientEntity,new Vector3f(),new Quat4f(0,0,0,1));
    Client clientListener=networkSystem.getOwner(clientEntity);
    int distance=clientListener.getViewDistance();
    if (!clientListener.isLocal()) {
      distance+=ChunkConstants.REMOTE_GENERATION_DISTANCE;
    }
    worldRenderer.getChunkProvider().updateRelevanceEntity(clientEntity,distance);
    client.character=playerCharacter;
    clientEntity.saveComponent(client);
  }
}
Program: 1114
Project: 1114
Buggy source:
private void restoreCharacter(EntityRef entity,PlayerEntityStore playerEntityStore){
  Map<String,EntityRef> restoredEntities=playerEntityStore.restoreAll();
  EntityRef character=restoredEntities.get("String_Node_Str");
  if (character == null) {
    spawnPlayer(entity,new Vector3i(Chunk.SIZE_X / 2,Chunk.SIZE_Y,Chunk.SIZE_Z / 2));
  }
 else {
    Client clientListener=networkSystem.getOwner(entity);
    int distance=clientListener.getViewDistance();
    if (!clientListener.isLocal()) {
      distance+=ChunkConstants.REMOTE_GENERATION_DISTANCE;
    }
    worldRenderer.getChunkProvider().updateRelevanceEntity(entity,distance);
    ClientComponent client=entity.getComponent(ClientComponent.class);
    client.character=character;
    entity.saveComponent(client);
    CharacterComponent characterComp=character.getComponent(CharacterComponent.class);
    characterComp.controller=entity;
    character.saveComponent(characterComp);
    Location.attachChild(character,entity);
  }
}

Fixed version (ground truth):
private void restoreCharacter(EntityRef entity,PlayerEntityStore playerEntityStore){
  Map<String,EntityRef> restoredEntities=playerEntityStore.restoreAll();
  EntityRef character=restoredEntities.get("String_Node_Str");
  if (character == null) {
    spawnPlayer(entity,new Vector3i(Chunk.SIZE_X / 2,Chunk.SIZE_Y,Chunk.SIZE_Z / 2));
  }
 else {
    Client clientListener=networkSystem.getOwner(entity);
    int distance=clientListener.getViewDistance();
    if (!clientListener.isLocal()) {
      distance+=ChunkConstants.REMOTE_GENERATION_DISTANCE;
    }
    worldRenderer.getChunkProvider().updateRelevanceEntity(entity,distance);
    ClientComponent client=entity.getComponent(ClientComponent.class);
    client.character=character;
    entity.saveComponent(client);
    CharacterComponent characterComp=character.getComponent(CharacterComponent.class);
    if (characterComp != null) {
      characterComp.controller=entity;
      character.saveComponent(characterComp);
      NetworkComponent netComp=character.getComponent(NetworkComponent.class);
      netComp.owner=entity;
      character.saveComponent(netComp);
      Location.attachChild(character,entity,new Vector3f(),new Quat4f(0,0,0,1));
    }
 else {
      character.destroy();
      spawnPlayer(entity,new Vector3i(Chunk.SIZE_X / 2,Chunk.SIZE_Y,Chunk.SIZE_Z / 2));
    }
  }
}
Program: 1115
Project: 1115
Buggy source:
private void receivedServerInfo(ServerInfoMessage message){
  if (awaitingServerInfo) {
    awaitingServerInfo=false;
    server.setServerInfo(message);
  }
}

Fixed version (ground truth):
private void receivedServerInfo(ServerInfoMessage message){
  if (awaitingServerInfo) {
    logger.info("String_Node_Str");
    awaitingServerInfo=false;
    server.setServerInfo(message);
  }
}
Program: 1116
Project: 1116
Buggy source:
private void processEvents(NetData.NetMessage message){
  boolean lagCompensated=false;
  PredictionSystem predictionSystem=CoreRegistry.get(PredictionSystem.class);
  for (  NetData.EventMessage eventMessage : message.getEventList()) {
    Event event=eventSerializer.deserialize(eventMessage.getEvent());
    EventMetadata<?> metadata=entitySystemLibrary.getEventLibrary().getMetadata(event.getClass());
    if (metadata.getNetworkEventType() != NetworkEventType.SERVER) {
      logger.warn("String_Node_Str",metadata,getName());
      continue;
    }
    if (!lagCompensated && metadata.isLagCompensated()) {
      if (predictionSystem != null) {
        predictionSystem.lagCompensate(getEntity(),lastReceivedTime);
      }
      lagCompensated=true;
    }
    EntityRef target=EntityRef.NULL;
    if (eventMessage.hasTargetId()) {
      target=networkSystem.getEntity(eventMessage.getTargetId());
    }
    if (target.exists()) {
      if (networkSystem.getOwner(target).equals(this)) {
        target.send(event);
      }
 else {
        logger.warn("String_Node_Str",event,target,this);
      }
    }
  }
  if (lagCompensated && predictionSystem != null) {
    predictionSystem.restoreToPresent();
  }
}

Fixed version (ground truth):
private void processEvents(NetData.NetMessage message){
  boolean lagCompensated=false;
  PredictionSystem predictionSystem=CoreRegistry.get(PredictionSystem.class);
  for (  NetData.EventMessage eventMessage : message.getEventList()) {
    Event event=eventSerializer.deserialize(eventMessage.getEvent());
    EventMetadata<?> metadata=entitySystemLibrary.getEventLibrary().getMetadata(event.getClass());
    if (metadata.getNetworkEventType() != NetworkEventType.SERVER) {
      logger.warn("String_Node_Str",metadata,getName());
      continue;
    }
    if (!lagCompensated && metadata.isLagCompensated()) {
      if (predictionSystem != null) {
        predictionSystem.lagCompensate(getEntity(),lastReceivedTime);
      }
      lagCompensated=true;
    }
    EntityRef target=EntityRef.NULL;
    if (eventMessage.hasTargetId()) {
      target=networkSystem.getEntity(eventMessage.getTargetId());
    }
    if (target.exists()) {
      if (Objects.equal(networkSystem.getOwner(target),this)) {
        target.send(event);
      }
 else {
        logger.warn("String_Node_Str",event,target,this);
      }
    }
  }
  if (lagCompensated && predictionSystem != null) {
    predictionSystem.restoreToPresent();
  }
}
Program: 1117
Project: 1117
Buggy source:
@ReceiveEvent(components={PotionComponent.class}) public void onActivate(ActivateEvent event,EntityRef entity){
  potion=entity.getComponent(PotionComponent.class);
  poisoned=entity.getComponent(PoisonedComponent.class);
  EntityManager entityManager=CoreRegister.get(EntityManager.class);
  HealthComponent health=event.getTarget().getComponent(HealthComponent.class);
  ItemComponent itemComp=entity.getComponent(ItemComponent.class);
  EntityRef item=entityManager.create("String_Node_Str");
switch (potion.type) {
case Red:
    event.getInstigator().send(new BoostHpEvent());
  event.getInstigator().send(new ReceiveItemEvent(item));
if (itemComp != null && !itemComp.container.exists()) {
  item.destroy();
}
break;
case Green:
event.getInstigator().send(new ReceiveItemEvent(item));
if (itemComp != null && !itemComp.container.exists()) {
item.destroy();
}
event.getInstigator().send(new PoisonedEvent());
break;
case Orange:
event.getInstigator().send(new CurePoisonEvent());
event.getInstigator().send(new ReceiveItemEvent(item));
if (itemComp != null && !itemComp.container.exists()) {
item.destroy();
}
break;
case Purple:
event.getInstigator().send(new ReceiveItemEvent(item));
if (itemComp != null && !itemComp.container.exists()) {
item.destroy();
}
event.getInstigator().send(new BoostSpeedEvent());
break;
default :
break;
}
AudioManager.play(new AssetUri(AssetType.SOUND,"String_Node_Str"),1.0f);
}

Fixed version (ground truth):
@ReceiveEvent(components={PotionComponent.class}) public void onActivate(ActivateEvent event,EntityRef entity){
  potion=entity.getComponent(PotionComponent.class);
  poisoned=entity.getComponent(PoisonedComponent.class);
  EntityManager entityManager=CoreRegister.get(EntityManager.class);
  HealthComponent health=event.getTarget().getComponent(HealthComponent.class);
  ItemComponent itemComp=entity.getComponent(ItemComponent.class);
  EntityRef item=entityManager.create("String_Node_Str");
switch (potion.type) {
case Red:
    event.getInstigator().send(new BoostHpEvent());
  event.getInstigator().send(new ReceiveItemEvent(item));
if (itemComp != null && !itemComp.container.exists()) {
  item.destroy();
}
break;
case Green:
event.getInstigator().send(new ReceiveItemEvent(item));
if (itemComp != null && !itemComp.container.exists()) {
item.destroy();
}
event.getInstigator().send(new PoisonedEvent());
break;
case Orange:
event.getInstigator().send(new CurePoisonEvent());
event.getInstigator().send(new ReceiveItemEvent(item));
if (itemComp != null && !itemComp.container.exists()) {
item.destroy();
}
break;
case Purple:
event.getInstigator().send(new ReceiveItemEvent(item));
if (itemComp != null && !itemComp.container.exists()) {
item.destroy();
}
event.getInstigator().send(new BoostSpeedEvent());
break;
default :
break;
}
audioManager.playSound(Assets.getSound("String_Node_Str"),1.0f);
}
Program: 1118
Project: 1118
Buggy source:
/** 
 * Stops all playback.
 */
@Override public void stopAllSounds(){
  for (  SoundPool pool : _pools.values()) {
    pool.stopAll();
  }
}

Fixed version (ground truth):
void stopAllSounds();
Program: 1119
Project: 1119
Buggy source:
public static SoundSource playMusic(String shortUri){
  AssetUri uri=new AssetUri(AssetType.MUSIC,shortUri);
  return playMusic(uri);
}

Fixed version (ground truth):
void playMusic(Sound sound);
Program: 1120
Project: 1120
Buggy source:
public void setFullscreen(Boolean state){
  if (Config.getInstance().isFullscreen() != state) {
    Config.getInstance().setFullscreen(state);
    setDisplayMode();
    CoreRegistry.get(GUIManager.class).update(true);
  }
}

Fixed version (ground truth):
public void setFullscreen(Boolean state){
  if (Config.getInstance().isFullscreen() != state) {
    Config.getInstance().setFullscreen(state);
    setDisplayMode();
    resizeViewport();
    CoreRegistry.get(GUIManager.class).update(true);
  }
}
Program: 1122
Project: 1122
Buggy source:
@Override public void generateChunk(final Chunk chunk){
  for (int x=0; x < Chunk.SIZE_X; x++) {
    for (int z=0; z < Chunk.SIZE_Z; z++) {
      final WorldBiomeProvider.Biome type=biomeProvider.getBiomeAt(chunk.getBlockWorldPosX(x),chunk.getBlockWorldPosZ(z));
      for (int y=Chunk.SIZE_Y; y >= 0; y--) {
        if (y == 0) {
          chunk.setBlock(x,y,z,mantle);
        }
 else         if (y < height) {
switch (type) {
case FOREST:
            chunk.setBlock(x,y,z,dirt);
          break;
case PLAINS:
        chunk.setBlock(x,y,z,dirt);
      break;
case MOUNTAINS:
    chunk.setBlock(x,y,z,stone);
  break;
case SNOW:
chunk.setBlock(x,y,z,snow);
break;
case DESERT:
chunk.setBlock(x,y,z,sand);
break;
}
}
 else if (y == height) {
switch (type) {
case FOREST:
chunk.setBlock(x,y,z,dirt);
break;
case PLAINS:
chunk.setBlock(x,y,z,grass);
break;
case MOUNTAINS:
chunk.setBlock(x,y,z,stone);
break;
case SNOW:
chunk.setBlock(x,y,z,snow);
break;
case DESERT:
chunk.setBlock(x,y,z,sand);
break;
}
}
 else {
chunk.setBlock(x,y,z,air);
}
}
}
}
}

Fixed version (ground truth):
@Override public void generateChunk(final Chunk chunk){
  for (int x=0; x < Chunk.SIZE_X; x++) {
    for (int z=0; z < Chunk.SIZE_Z; z++) {
      final WorldBiomeProvider.Biome type=biomeProvider.getBiomeAt(chunk.getBlockWorldPosX(x),chunk.getBlockWorldPosZ(z));
      for (int y=Chunk.SIZE_Y - 1; y >= 0; y--) {
        if (y == 0) {
          chunk.setBlock(x,y,z,mantle);
        }
 else         if (y < height) {
switch (type) {
case FOREST:
            chunk.setBlock(x,y,z,dirt);
          break;
case PLAINS:
        chunk.setBlock(x,y,z,dirt);
      break;
case MOUNTAINS:
    chunk.setBlock(x,y,z,stone);
  break;
case SNOW:
chunk.setBlock(x,y,z,snow);
break;
case DESERT:
chunk.setBlock(x,y,z,sand);
break;
}
}
 else if (y == height) {
switch (type) {
case FOREST:
chunk.setBlock(x,y,z,dirt);
break;
case PLAINS:
chunk.setBlock(x,y,z,grass);
break;
case MOUNTAINS:
chunk.setBlock(x,y,z,stone);
break;
case SNOW:
chunk.setBlock(x,y,z,snow);
break;
case DESERT:
chunk.setBlock(x,y,z,sand);
break;
}
}
 else {
chunk.setBlock(x,y,z,air);
}
}
}
}
}
Program: 1124
Project: 1124
Buggy source:
public boolean setSunlight(int x,int y,int z,byte amount){
  byte oldValue=(byte)sunlight.set(x,y,z,amount);
  return oldValue != amount;
}

Fixed version (ground truth):
public boolean setSunlight(int x,int y,int z,byte amount){
  Preconditions.checkArgument(amount >= 0 && amount < 16);
  int raw=light.get(x,y,z);
  int old=raw >> 4;
  if (old == amount)   return false;
  int val=(byte)((raw & 0x0F) | (amount << 4));
  light.set(x,y,z,val);
  return true;
}
Program: 1125
Project: 1125
Buggy source:
public byte getSunlight(int x,int y,int z){
  return (byte)sunlight.get(x,y,z);
}

Fixed version (ground truth):
public byte getSunlight(int x,int y,int z){
  int raw=light.get(x,y,z);
  return (byte)((raw & 0xF0) >> 4);
}
Program: 1126
Project: 1126
Buggy source:
public boolean setLight(int x,int y,int z,byte amount){
  byte oldValue=(byte)light.set(x,y,z,amount);
  return (oldValue != amount);
}

Fixed version (ground truth):
public boolean setLight(int x,int y,int z,byte amount){
  Preconditions.checkArgument(amount >= 0 && amount < 16);
  int raw=light.get(x,y,z);
  int old=raw & 0x0F;
  if (old == amount)   return false;
  int val=(byte)(raw & 0xF0) | (amount & 0x0F);
  light.set(x,y,z,val);
  return true;
}
Program: 1127
Project: 1127
Buggy source:
public byte getLight(int x,int y,int z){
  return (byte)light.get(x,y,z);
}

Fixed version (ground truth):
public byte getLight(int x,int y,int z){
  int raw=light.get(x,y,z);
  return (byte)(raw & 0x0F);
}
Program: 1128
Project: 1128
Buggy source:
public void writeExternal(ObjectOutput out) throws IOException {
  out.writeInt(pos.x);
  out.writeInt(pos.y);
  out.writeInt(pos.z);
  out.writeObject(chunkState);
  out.writeObject(blocks);
  out.writeObject(sunlight);
  out.writeObject(light);
  out.writeObject(liquid);
}

Fixed version (ground truth):
public void writeExternal(ObjectOutput out) throws IOException {
  out.writeInt(pos.x);
  out.writeInt(pos.y);
  out.writeInt(pos.z);
  out.writeObject(chunkState);
  out.writeObject(blocks);
  out.writeObject(light);
  out.writeObject(liquid);
}
Program: 1129
Project: 1129
Buggy source:
public Chunk(Chunk other){
  pos.set(other.pos);
  blocks=other.blocks.copy();
  sunlight=other.sunlight.copy();
  light=other.light.copy();
  liquid=other.liquid.copy();
  chunkState=other.chunkState;
  dirty=true;
}

Fixed version (ground truth):
public Chunk(Chunk other){
  pos.set(other.pos);
  blocks=other.blocks.copy();
  light=other.light.copy();
  liquid=other.liquid.copy();
  chunkState=other.chunkState;
  dirty=true;
}
Program: 1130
Project: 1130
Buggy source:
public void pack(){
  lock();
  try {
    TeraArray packed=blocks.pack();
    if (packed != blocks) {
      double bp=100d - (100d / blocks.getEstimatedMemoryConsumptionInBytes() * packed.getEstimatedMemoryConsumptionInBytes());
      System.out.println(String.format("String_Node_Str",pos.x,pos.y,pos.z,fpercent.format(bp)));
      blocks=packed;
    }
  }
  finally {
    unlock();
  }
}

Fixed version (ground truth):
public void pack(){
  lock();
  try {
    TeraArray packedBlocks=blocks.pack();
    TeraArray packedLight=light.pack();
    if (packedBlocks != blocks || packedLight != light) {
      double bp=100d - (100d / blocks.getEstimatedMemoryConsumptionInBytes() * packedBlocks.getEstimatedMemoryConsumptionInBytes());
      double bl=100d - (100d / light.getEstimatedMemoryConsumptionInBytes() * packedLight.getEstimatedMemoryConsumptionInBytes());
      System.out.println(String.format("String_Node_Str",pos.x,pos.y,pos.z,fpercent.format(bp),fpercent.format(bl)));
      blocks=packedBlocks;
      light=packedLight;
    }
 else {
      System.out.println(String.format("String_Node_Str",pos.x,pos.y,pos.z));
    }
  }
  finally {
    unlock();
  }
}
Program: 1131
Project: 1131
Buggy source:
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  pos.x=in.readInt();
  pos.y=in.readInt();
  pos.z=in.readInt();
  setDirty(true);
  chunkState=(State)in.readObject();
  blocks=(TeraArray)in.readObject();
  sunlight=(TeraArray)in.readObject();
  light=(TeraArray)in.readObject();
  liquid=(TeraArray)in.readObject();
}

Fixed version (ground truth):
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  pos.x=in.readInt();
  pos.y=in.readInt();
  pos.z=in.readInt();
  setDirty(true);
  chunkState=(State)in.readObject();
  blocks=(TeraArray)in.readObject();
  light=(TeraArray)in.readObject();
  liquid=(TeraArray)in.readObject();
}
Program: 1132
Project: 1132
Buggy source:
@Override public boolean set(int x,int y,int z,int value,int expected){
  if (!contains(x,y,z))   throw new IndexOutOfBoundsException();
  if (value < 0 || value > 15 || expected < 0 || expected > 15)   throw new IllegalArgumentException();
  int pos=pos(x,y,z);
  if (pos < sizeXYZHalf) {
    int raw=data[pos] & 0xFF;
    byte old=(byte)((raw & 0x0F) & 0xFF);
    if (old == expected) {
      int tmp=value & 0xFF;
      data[pos]=(byte)((tmp & 0x0F) | (raw & 0xF0));
      return true;
    }
    return false;
  }
  int raw=data[pos % sizeXYZHalf] & 0xFF;
  byte old=(byte)(raw >> 4);
  if (old == expected) {
    int tmp=value & 0xFF;
    data[pos % sizeXYZHalf]=(byte)((raw & 0x0F) | (tmp << 4) & 0xFF);
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean set(int x,int y,int z,int value,int expected){
  if (!contains(x,y,z))   throw new IndexOutOfBoundsException("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str"+ z+ "String_Node_Str");
  if (value < 0 || value > 15)   throw new IllegalArgumentException("String_Node_Str" + value + "String_Node_Str");
  if (expected < 0 || expected > 15)   throw new IllegalArgumentException("String_Node_Str" + value + "String_Node_Str");
  int pos=pos(x,y,z);
  if (pos < sizeXYZHalf) {
    int raw=data[pos] & 0xFF;
    byte old=(byte)((raw & 0x0F) & 0xFF);
    if (old == expected) {
      int tmp=value & 0xFF;
      data[pos]=(byte)((tmp & 0x0F) | (raw & 0xF0));
      return true;
    }
    return false;
  }
  int raw=data[pos % sizeXYZHalf] & 0xFF;
  byte old=(byte)(raw >> 4);
  if (old == expected) {
    int tmp=value & 0xFF;
    data[pos % sizeXYZHalf]=(byte)((raw & 0x0F) | (tmp << 4) & 0xFF);
    return true;
  }
  return false;
}
Program: 1133
Project: 1133
Buggy source:
@Override public int get(int x,int y,int z){
  if (!contains(x,y,z))   throw new IndexOutOfBoundsException();
  int pos=pos(x,y,z);
  if (pos < sizeXYZHalf) {
    int raw=data[pos] & 0xFF;
    return (byte)((raw & 0x0F) & 0xFF);
  }
  int raw=data[pos % sizeXYZHalf] & 0xFF;
  return (byte)(raw >> 4);
}

Fixed version (ground truth):
@Override public int get(int x,int y,int z){
  if (!contains(x,y,z))   throw new IndexOutOfBoundsException("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str"+ z+ "String_Node_Str");
  int pos=pos(x,y,z);
  if (pos < sizeXYZHalf) {
    int raw=data[pos] & 0xFF;
    return (byte)((raw & 0x0F) & 0xFF);
  }
  int raw=data[pos % sizeXYZHalf] & 0xFF;
  return (byte)(raw >> 4);
}
Program: 1134
Project: 1134
Buggy source:
@Override public boolean set(int x,int y,int z,int value,int expected){
  if (!contains(x,y,z))   throw new IndexOutOfBoundsException();
  if (value < 0 || value > 255 || expected < 0 || expected > 255)   throw new IllegalArgumentException();
  int pos=pos(x,y,z);
  int old=data[pos] & 0xFF;
  if (old == expected) {
    data[pos]=(byte)value;
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean set(int x,int y,int z,int value,int expected){
  if (!contains(x,y,z))   throw new IndexOutOfBoundsException("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str"+ z+ "String_Node_Str");
  if (value < -128 || value > 127)   throw new IllegalArgumentException("String_Node_Str" + value + "String_Node_Str");
  if (expected < -128 || expected > 127)   throw new IllegalArgumentException("String_Node_Str" + value + "String_Node_Str");
  int pos=pos(x,y,z);
  int old=data[pos];
  if (old == expected) {
    data[pos]=(byte)value;
    return true;
  }
  return false;
}
Program: 1135
Project: 1135
Buggy source:
@Override public int get(int x,int y,int z){
  if (!contains(x,y,z))   throw new IndexOutOfBoundsException();
  int pos=pos(x,y,z);
  return data[pos] & 0xFF;
}

Fixed version (ground truth):
@Override public int get(int x,int y,int z){
  if (!contains(x,y,z))   throw new IndexOutOfBoundsException("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str"+ z+ "String_Node_Str");
  int pos=pos(x,y,z);
  return data[pos];
}
Program: 1136
Project: 1136
Buggy source:
@Override public boolean set(int x,int y,int z,int value,int expected){
  if (!contains(x,y,z))   throw new IndexOutOfBoundsException();
  if (value < 0 || value > 255 || expected < 0 || expected > 255)   throw new IllegalArgumentException();
  if (value == expected)   return true;
  byte[] data=inflated[y];
  int pos=z * sizeX + x;
  if (data != null) {
    int old=data[pos] & 0xFF;
    if (old == expected)     data[pos]=(byte)value;
    return old == expected;
  }
  byte old=deflated[y];
  if (old == (byte)expected) {
    data=new byte[sizeXZ];
    Arrays.fill(data,old);
    data[pos]=(byte)value;
    inflated[y]=data;
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean set(int x,int y,int z,int value,int expected){
  if (!contains(x,y,z))   throw new IndexOutOfBoundsException("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str"+ z+ "String_Node_Str");
  if (value < -128 || value > 127)   throw new IllegalArgumentException("String_Node_Str" + value + "String_Node_Str");
  if (expected < -128 || expected > 127)   throw new IllegalArgumentException("String_Node_Str" + value + "String_Node_Str");
  if (value == expected)   return true;
  byte[] data=inflated[y];
  int pos=z * sizeX + x;
  if (data != null) {
    int old=data[pos];
    if (old == expected)     data[pos]=(byte)value;
    return old == expected;
  }
  byte old=deflated[y];
  if (old == (byte)expected) {
    data=new byte[sizeXZ];
    Arrays.fill(data,old);
    data[pos]=(byte)value;
    inflated[y]=data;
    return true;
  }
  return false;
}
Program: 1137
Project: 1137
Buggy source:
@Override public int get(int x,int y,int z){
  if (!contains(x,y,z))   throw new IndexOutOfBoundsException();
  byte[] data=inflated[y];
  if (data != null)   return data[z * sizeX + x];
  return deflated[y];
}

Fixed version (ground truth):
@Override public int get(int x,int y,int z){
  if (!contains(x,y,z))   throw new IndexOutOfBoundsException("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str"+ z+ "String_Node_Str");
  byte[] data=inflated[y];
  if (data != null)   return data[z * sizeX + x];
  return deflated[y];
}
Program: 1138
Project: 1138
Buggy source:
private void checkChunkReady(Vector3i pos){
  if (worldEntity.exists()) {
    for (    Vector3i adjPos : Region3i.createFromCenterExtents(pos,LOCAL_REGION_EXTENTS)) {
      Chunk chunk=getChunk(pos);
      if (chunk == null || chunk.getChunkState() != Chunk.State.COMPLETE) {
        return;
      }
    }
    worldEntity.send(new ChunkReadyEvent(pos));
  }
}

Fixed version (ground truth):
private void checkChunkReady(Vector3i pos){
  if (worldEntity.exists()) {
    for (    Vector3i adjPos : Region3i.createFromCenterExtents(pos,LOCAL_REGION_EXTENTS)) {
      Chunk chunk=getChunk(adjPos);
      if (chunk == null || chunk.getChunkState() != Chunk.State.COMPLETE) {
        return;
      }
    }
    worldEntity.send(new ChunkReadyEvent(pos));
  }
}
Program: 1141
Project: 1141
Buggy source:
private void checkChunkReady(Vector3i pos){
  if (worldEntity.exists()) {
    Chunk chunk=getChunk(pos);
    if (chunk != null && chunk.getChunkState() == Chunk.State.COMPLETE) {
      worldEntity.send(new ChunkReadyEvent(pos));
    }
  }
}

Fixed version (ground truth):
private void checkChunkReady(Vector3i pos){
  if (worldEntity.exists()) {
    for (    Vector3i adjPos : Region3i.createFromCenterExtents(pos,LOCAL_REGION_EXTENTS)) {
      Chunk chunk=getChunk(adjPos);
      if (chunk == null || chunk.getChunkState() != Chunk.State.COMPLETE) {
        return;
      }
    }
    worldEntity.send(new ChunkReadyEvent(pos));
  }
}
Program: 1142
Project: 1142
Buggy source:
private void checkChunkReady(Vector3i pos){
  if (worldEntity.exists()) {
    for (    Vector3i adjPos : Region3i.createFromCenterExtents(pos,LOCAL_REGION_EXTENTS)) {
      Chunk chunk=getChunk(pos);
      if (chunk == null || chunk.getChunkState() != Chunk.State.COMPLETE) {
        return;
      }
    }
    worldEntity.send(new ChunkReadyEvent(pos));
  }
}

Fixed version (ground truth):
private void checkChunkReady(Vector3i pos){
  if (worldEntity.exists()) {
    for (    Vector3i adjPos : Region3i.createFromCenterExtents(pos,LOCAL_REGION_EXTENTS)) {
      Chunk chunk=getChunk(adjPos);
      if (chunk == null || chunk.getChunkState() != Chunk.State.COMPLETE) {
        return;
      }
    }
    worldEntity.send(new ChunkReadyEvent(pos));
  }
}
Program: 1143
Project: 1143
Buggy source:
@Override public int begin(){
  entityManager=CoreRegistry.get(EntityManager.class);
  worldRenderer=CoreRegistry.get(WorldRenderer.class);
  chunkProvider=worldRenderer.getChunkProvider();
  Iterator<EntityRef> iterator=entityManager.iteratorEntities(LocalPlayerComponent.class).iterator();
  spawningPlayer=!iterator.hasNext();
  if (spawningPlayer) {
    spawnZoneEntity=entityManager.create();
    spawnZoneEntity.addComponent(new LocationComponent(new Vector3f(Chunk.SIZE_X / 2,Chunk.SIZE_Y / 2,Chunk.SIZE_Z / 2)));
    worldRenderer.getChunkProvider().addRegionEntity(spawnZoneEntity,1);
    targetPos=Vector3i.zero();
  }
 else {
    CoreRegistry.get(LocalPlayer.class).setEntity(iterator.next());
    worldRenderer.setPlayer(CoreRegistry.get(LocalPlayer.class));
    targetPos=TeraMath.calcChunkPos(new Vector3i(worldRenderer.getPlayer().getPosition(),0.5f));
  }
  return UNKNOWN_STEPS;
}

Fixed version (ground truth):
@Override public int begin(){
  entityManager=CoreRegistry.get(EntityManager.class);
  worldRenderer=CoreRegistry.get(WorldRenderer.class);
  chunkProvider=worldRenderer.getChunkProvider();
  Iterator<EntityRef> iterator=entityManager.iteratorEntities(LocalPlayerComponent.class).iterator();
  spawningPlayer=!iterator.hasNext();
  if (spawningPlayer) {
    spawnZoneEntity=entityManager.create();
    spawnZoneEntity.addComponent(new LocationComponent(new Vector3f(Chunk.SIZE_X / 2,Chunk.SIZE_Y / 2,Chunk.SIZE_Z / 2)));
    worldRenderer.getChunkProvider().addRegionEntity(spawnZoneEntity,4);
    targetPos=Vector3i.zero();
  }
 else {
    CoreRegistry.get(LocalPlayer.class).setEntity(iterator.next());
    worldRenderer.setPlayer(CoreRegistry.get(LocalPlayer.class));
    targetPos=TeraMath.calcChunkPos(new Vector3i(worldRenderer.getPlayer().getPosition(),0.5f));
  }
  return UNKNOWN_STEPS;
}