Program: 887
Project: 887
Buggy source:
/** 
 * @param unsavedEntities currently loaded persistent entities without owner that have not been saved yet.This method removes entities it saves.
 */
private void addChunksToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder,ChunkProvider chunkProvider,Set<EntityRef> unsavedEntities){
  unloadedAndSavingChunkMap.clear();
  Iterator<Map.Entry<Vector3i,CompressedChunkBuilder>> unsavedEntryIterator=unloadedAndUnsavedChunkMap.entrySet().iterator();
  while (unsavedEntryIterator.hasNext()) {
    Map.Entry<Vector3i,CompressedChunkBuilder> entry=unsavedEntryIterator.next();
    unloadedAndSavingChunkMap.put(entry.getKey(),entry.getValue());
    unsavedEntryIterator.remove();
  }
  Map<Vector3i,Collection<EntityRef>> chunkPosToEntitiesMap=createChunkPosToUnsavedEntitiesMap();
  for (  Chunk chunk : chunkProvider.getAllChunks()) {
    if (chunk.isReady()) {
      unloadedAndSavingChunkMap.remove(chunk.getPosition());
      Collection<EntityRef> entitiesToStore=chunkPosToEntitiesMap.get(chunk.getPosition());
      if (entitiesToStore == null) {
        entitiesToStore=Collections.EMPTY_SET;
      }
      unsavedEntities.removeAll(entitiesToStore);
      CompressedChunkBuilder compressedChunkBuilder=createCompressedChunkBuilder(chunk,entitiesToStore,false);
      saveTransactionBuilder.addCompressedChunkBuilder(chunk.getPosition(),compressedChunkBuilder);
    }
  }
  for (  Map.Entry<Vector3i,CompressedChunkBuilder> entry : unloadedAndSavingChunkMap.entrySet()) {
    saveTransactionBuilder.addCompressedChunkBuilder(entry.getKey(),entry.getValue());
  }
}

Fixed version (ground truth):
/** 
 * @param unsavedEntities currently loaded persistent entities without owner that have not been saved yet.This method removes entities it saves.
 */
private void addChunksToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder,ChunkProvider chunkProvider,Set<EntityRef> unsavedEntities){
  unloadedAndSavingChunkMap.clear();
  Iterator<Map.Entry<Vector3i,CompressedChunkBuilder>> unsavedEntryIterator=unloadedAndUnsavedChunkMap.entrySet().iterator();
  while (unsavedEntryIterator.hasNext()) {
    Map.Entry<Vector3i,CompressedChunkBuilder> entry=unsavedEntryIterator.next();
    unloadedAndSavingChunkMap.put(entry.getKey(),entry.getValue());
    unsavedEntryIterator.remove();
  }
  Map<Vector3i,Collection<EntityRef>> chunkPosToEntitiesMap=createChunkPosToUnsavedEntitiesMap();
  for (  Chunk chunk : chunkProvider.getAllChunks()) {
    if (chunk.isReady()) {
      unloadedAndSavingChunkMap.remove(chunk.getPosition());
      Collection<EntityRef> entitiesToStore=chunkPosToEntitiesMap.get(chunk.getPosition());
      if (entitiesToStore == null) {
        entitiesToStore=Collections.emptySet();
      }
      unsavedEntities.removeAll(entitiesToStore);
      CompressedChunkBuilder compressedChunkBuilder=createCompressedChunkBuilder(chunk,entitiesToStore,false);
      saveTransactionBuilder.addCompressedChunkBuilder(chunk.getPosition(),compressedChunkBuilder);
    }
  }
  for (  Map.Entry<Vector3i,CompressedChunkBuilder> entry : unloadedAndSavingChunkMap.entrySet()) {
    saveTransactionBuilder.addCompressedChunkBuilder(entry.getKey(),entry.getValue());
  }
}