Program: 15874
Project: 15874
Buggy source:
/** 
 * Apply the freed space to the chunk metadata. The metadata is updated, but freed chunks are not removed yet.
 * @param storeVersion apply up to the given version
 * @return the set of completely freed chunks (might be empty)
 */
private Set<Chunk> applyFreedSpace(long storeVersion,long time){
  Set<Chunk> removedChunks=New.hashSet();
  while (true) {
    ArrayList<Chunk> modified=New.arrayList();
    ArrayList<Long> keys=new ArrayList<Long>(freedPageSpace.keySet());
    for (Iterator<Long> it=keys.iterator(); it.hasNext(); ) {
      long v=it.next();
      if (v > storeVersion) {
        continue;
      }
      Map<Integer,Chunk> freed=freedPageSpace.get(v);
      for (      Chunk f : freed.values()) {
        Chunk c=chunks.get(f.id);
        if (c == null) {
          continue;
        }
        c.maxLengthLive+=f.maxLengthLive;
        c.pageCountLive+=f.pageCountLive;
        if (c.pageCountLive < 0) {
          throw DataUtils.newIllegalStateException(DataUtils.ERROR_INTERNAL,"String_Node_Str",c.pageCountLive);
        }
        if (c.maxLengthLive < 0) {
          throw DataUtils.newIllegalStateException(DataUtils.ERROR_INTERNAL,"String_Node_Str",c.maxLengthLive);
        }
        if (c.pageCount == 0 && c.maxLengthLive > 0) {
          throw DataUtils.newIllegalStateException(DataUtils.ERROR_INTERNAL,"String_Node_Str",c.maxLengthLive);
        }
        modified.add(c);
      }
      freedPageSpace.remove(v);
    }
    for (    Chunk c : modified) {
      if (c.maxLengthLive == 0) {
        if (canOverwriteChunk(c,time)) {
          removedChunks.add(c);
          chunks.remove(c.id);
          meta.remove("String_Node_Str" + c.id);
        }
 else {
          registerFreePage(storeVersion + 1,c.id,0,0);
        }
      }
 else {
        meta.put("String_Node_Str" + c.id,c.asString());
      }
    }
    if (modified.size() == 0) {
      break;
    }
  }
  return removedChunks;
}

Fixed version (ground truth):
/** 
 * Apply the freed space to the chunk metadata. The metadata is updated, but freed chunks are not removed yet.
 * @param storeVersion apply up to the given version
 * @return the set of completely freed chunks (might be empty)
 */
private Set<Chunk> applyFreedSpace(long storeVersion,long time){
  Set<Chunk> removedChunks=New.hashSet();
  while (true) {
    ArrayList<Chunk> modified=New.arrayList();
    Iterator<Entry<Long,HashMap<Integer,Chunk>>> it;
    it=freedPageSpace.entrySet().iterator();
    while (it.hasNext()) {
      Entry<Long,HashMap<Integer,Chunk>> e=it.next();
      long v=e.getKey();
      if (v > storeVersion) {
        continue;
      }
      Map<Integer,Chunk> freed=e.getValue();
      for (      Chunk f : freed.values()) {
        Chunk c=chunks.get(f.id);
        if (c == null) {
          continue;
        }
        c.maxLengthLive+=f.maxLengthLive;
        c.pageCountLive+=f.pageCountLive;
        if (c.pageCountLive < 0) {
          throw DataUtils.newIllegalStateException(DataUtils.ERROR_INTERNAL,"String_Node_Str",c.pageCountLive);
        }
        if (c.maxLengthLive < 0) {
          throw DataUtils.newIllegalStateException(DataUtils.ERROR_INTERNAL,"String_Node_Str",c.maxLengthLive);
        }
        if (c.pageCount == 0 && c.maxLengthLive > 0) {
          throw DataUtils.newIllegalStateException(DataUtils.ERROR_INTERNAL,"String_Node_Str",c.maxLengthLive);
        }
        modified.add(c);
      }
      it.remove();
    }
    for (    Chunk c : modified) {
      if (c.maxLengthLive == 0) {
        if (canOverwriteChunk(c,time)) {
          removedChunks.add(c);
          chunks.remove(c.id);
          meta.remove("String_Node_Str" + c.id);
        }
 else {
          registerFreePage(storeVersion + 1,c.id,0,0);
        }
      }
 else {
        meta.put("String_Node_Str" + c.id,c.asString());
      }
    }
    if (modified.size() == 0) {
      break;
    }
  }
  return removedChunks;
}