Program: 15869
Project: 15869
Buggy source:
private long storeNow(){
  int currentUnsavedPageCount=unsavedPageCount;
  long storeVersion=currentStoreVersion;
  long version=++currentVersion;
  setWriteVersion(version);
  long time=getTime();
  lastCommitTime=time;
  retainChunk=null;
  Chunk lastChunk=chunks.get(lastChunkId);
  if (lastChunk != null) {
    meta.put("String_Node_Str" + lastChunk.id,lastChunk.asString());
    time=Math.max(lastChunk.time,time);
  }
  Chunk c;
  c=new Chunk(++lastChunkId);
  c.maxLength=Long.MAX_VALUE;
  c.maxLengthLive=Long.MAX_VALUE;
  c.start=Long.MAX_VALUE;
  c.length=Integer.MAX_VALUE;
  c.time=time;
  c.version=version;
  chunks.put(c.id,c);
  meta.put("String_Node_Str" + c.id,c.asString());
  ArrayList<MVMap<?,?>> list=New.arrayList(maps.values());
  ArrayList<MVMap<?,?>> changed=New.arrayList();
  for (  MVMap<?,?> m : list) {
    m.setWriteVersion(version);
    long v=m.getVersion();
    if (m.getCreateVersion() > storeVersion) {
      continue;
    }
    if (v >= 0 && v >= lastStoredVersion) {
      m.waitUntilWritten(storeVersion);
      MVMap<?,?> r=m.openVersion(storeVersion);
      if (r.getRoot().getPos() == 0) {
        changed.add(r);
      }
    }
  }
  for (  MVMap<?,?> m : changed) {
    Page p=m.getRoot();
    if (p.getTotalCount() == 0) {
      meta.put("String_Node_Str" + m.getId(),"String_Node_Str");
    }
 else {
      meta.put("String_Node_Str" + m.getId(),String.valueOf(Integer.MAX_VALUE));
    }
  }
  Set<Chunk> removedChunks=applyFreedSpace(storeVersion,time);
  WriteBuffer buff=getWriteBuffer();
  c.writeHeader(buff);
  c.maxLength=0;
  c.maxLengthLive=0;
  for (  MVMap<?,?> m : changed) {
    Page p=m.getRoot();
    if (p.getTotalCount() > 0) {
      p.writeUnsavedRecursive(c,buff);
      long root=p.getPos();
      meta.put("String_Node_Str" + m.getId(),"String_Node_Str" + root);
    }
  }
  meta.put("String_Node_Str" + c.id,c.asString());
  meta.setWriteVersion(version);
  Page metaRoot=meta.getRoot();
  metaRoot.writeUnsavedRecursive(c,buff);
  int chunkLength=buff.position();
  int length=MathUtils.roundUpInt(chunkLength,BLOCK_SIZE) + BLOCK_SIZE;
  buff.limit(length);
  for (  Chunk x : removedChunks) {
    int len=MathUtils.roundUpInt(x.length,BLOCK_SIZE) + BLOCK_SIZE;
    fileStore.free(x.start,len);
  }
  long end=getEndPosition();
  long filePos;
  if (reuseSpace) {
    filePos=fileStore.allocate(length);
  }
 else {
    filePos=end;
    fileStore.markUsed(end,length);
  }
  boolean storeAtEndOfFile=filePos + length >= end;
  c.start=filePos;
  c.length=chunkLength;
  c.metaRootPos=metaRoot.getPos();
  buff.position(0);
  c.writeHeader(buff);
  rootChunkStart=filePos;
  revertTemp(storeVersion);
  buff.position(buff.limit() - BLOCK_SIZE);
  byte[] header=getStoreHeaderBytes();
  buff.put(header);
  buff.put(new byte[BLOCK_SIZE - header.length]);
  buff.position(0);
  fileStore.writeFully(filePos,buff.getBuffer());
  releaseWriteBuffer(buff);
  if (!storeAtEndOfFile) {
    writeStoreHeader();
    shrinkFileIfPossible(1);
  }
  for (  MVMap<?,?> m : changed) {
    Page p=m.getRoot();
    if (p.getTotalCount() > 0) {
      p.writeEnd();
    }
  }
  metaRoot.writeEnd();
  unsavedPageCount=Math.max(0,unsavedPageCount - currentUnsavedPageCount);
  metaChanged=false;
  lastStoredVersion=storeVersion;
  return version;
}

Fixed version (ground truth):
private long storeNow(){
  int currentUnsavedPageCount=unsavedPageCount;
  long storeVersion=currentStoreVersion;
  long version=++currentVersion;
  setWriteVersion(version);
  long time=getTime();
  lastCommitTime=time;
  retainChunk=null;
  Chunk lastChunk=chunks.get(lastChunkId);
  if (lastChunk != null) {
    meta.put("String_Node_Str" + lastChunk.id,lastChunk.asString());
    time=Math.max(lastChunk.time,time);
  }
  Chunk c;
  c=new Chunk(++lastChunkId);
  c.maxLength=Long.MAX_VALUE;
  c.maxLengthLive=Long.MAX_VALUE;
  c.start=Long.MAX_VALUE;
  c.length=Integer.MAX_VALUE;
  c.time=time;
  c.version=version;
  chunks.put(c.id,c);
  meta.put("String_Node_Str" + c.id,c.asString());
  ArrayList<MVMap<?,?>> list=New.arrayList(maps.values());
  ArrayList<MVMap<?,?>> changed=New.arrayList();
  for (  MVMap<?,?> m : list) {
    m.setWriteVersion(version);
    long v=m.getVersion();
    if (m.getCreateVersion() > storeVersion) {
      continue;
    }
    if (v >= 0 && v >= lastStoredVersion) {
      m.waitUntilWritten(storeVersion);
      MVMap<?,?> r=m.openVersion(storeVersion);
      if (r.getRoot().getPos() == 0) {
        changed.add(r);
      }
    }
  }
  for (  MVMap<?,?> m : changed) {
    Page p=m.getRoot();
    if (p.getTotalCount() == 0) {
      meta.put("String_Node_Str" + m.getId(),"String_Node_Str");
    }
 else {
      meta.put("String_Node_Str" + m.getId(),String.valueOf(Integer.MAX_VALUE));
    }
  }
  Set<Chunk> removedChunks=applyFreedSpace(storeVersion,time);
  WriteBuffer buff=getWriteBuffer();
  c.writeHeader(buff);
  c.maxLength=0;
  c.maxLengthLive=0;
  for (  MVMap<?,?> m : changed) {
    Page p=m.getRoot();
    if (p.getTotalCount() > 0) {
      p.writeUnsavedRecursive(c,buff);
      long root=p.getPos();
      meta.put("String_Node_Str" + m.getId(),"String_Node_Str" + root);
    }
  }
  meta.put("String_Node_Str" + c.id,c.asString());
  meta.setWriteVersion(version);
  Page metaRoot=meta.getRoot();
  metaRoot.writeUnsavedRecursive(c,buff);
  int chunkLength=buff.position();
  int length=MathUtils.roundUpInt(chunkLength,BLOCK_SIZE) + BLOCK_SIZE;
  buff.limit(length);
  for (  Chunk x : removedChunks) {
    int len=MathUtils.roundUpInt(x.length,BLOCK_SIZE) + BLOCK_SIZE;
    fileStore.free(x.start,len);
  }
  long end=getFileLengthInUse();
  long filePos;
  if (reuseSpace) {
    filePos=fileStore.allocate(length);
  }
 else {
    filePos=end;
    fileStore.markUsed(end,length);
  }
  boolean storeAtEndOfFile=filePos + length >= fileStore.size();
  c.start=filePos;
  c.length=chunkLength;
  c.metaRootPos=metaRoot.getPos();
  buff.position(0);
  c.writeHeader(buff);
  rootChunkStart=filePos;
  revertTemp(storeVersion);
  buff.position(buff.limit() - BLOCK_SIZE);
  byte[] header=getStoreHeaderBytes();
  buff.put(header);
  buff.put(new byte[BLOCK_SIZE - header.length]);
  buff.position(0);
  fileStore.writeFully(filePos,buff.getBuffer());
  releaseWriteBuffer(buff);
  if (!storeAtEndOfFile) {
    writeStoreHeader();
    shrinkFileIfPossible(1);
  }
  for (  MVMap<?,?> m : changed) {
    Page p=m.getRoot();
    if (p.getTotalCount() > 0) {
      p.writeEnd();
    }
  }
  metaRoot.writeEnd();
  unsavedPageCount=Math.max(0,unsavedPageCount - currentUnsavedPageCount);
  metaChanged=false;
  lastStoredVersion=storeVersion;
  return version;
}