Program: 162960
Project: 162960
Buggy source:
/** 
 * Replaces value in existing entry. May cause entry relocation, because there may be not enough space for new value in location already allocated for this entry.
 * @param pos          index of the first chunk occupied by the entry
 * @param offset       relative offset of the entry in Segment bytes (before, i. e.including metaData)
 * @param entry        relative pointer in Segment bytes
 * @param valueSizePos relative position of value size in entry
 * @param entryEndAddr absolute address of the entry end
 * @return relative offset of the entry in Segment bytes after putting value (that may causeentry relocation)
 */
final <E,EW>long putValue(long pos,long offset,MultiStoreBytes entry,long valueSizePos,long entryEndAddr,SegmentState segmentState,MetaBytesWriter<E,? super EW> metaElemWriter,EW elemWriter,E newElem,long newElemSize,MultiMap searchedHashLookup){
  long entryStartAddr=entry.address();
  long valueSizeAddr=entryStartAddr + valueSizePos;
  long newValueAddr=alignment.alignAddr(valueSizeAddr + valueSizeMarshaller.sizeEncodingSize(newElemSize));
  long newEntryEndAddr=newValueAddr + newElemSize;
  newValueDoesNotFit:   if (newEntryEndAddr != entryEndAddr) {
    long oldEntrySize=entryEndAddr - entryStartAddr;
    int oldSizeInChunks=inChunks(oldEntrySize);
    int newSizeInChunks=inChunks(newEntryEndAddr - entryStartAddr);
    if (newSizeInChunks > oldSizeInChunks) {
      if (newSizeInChunks > maxChunksPerEntry) {
        throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str" + newSizeInChunks + "String_Node_Str"+ maxChunksPerEntry+ "String_Node_Str");
      }
      if (realloc(pos,oldSizeInChunks,newSizeInChunks))       break newValueDoesNotFit;
      free(pos,oldSizeInChunks);
      onRelocation(this,pos);
      pos=alloc(newSizeInChunks);
      searchedHashLookup.replacePrevPos(segmentState.searchState,pos);
      offset=offsetFromPos(pos);
      long newEntryStartAddr=entry.address();
      NativeBytes.UNSAFE.copyMemory(entryStartAddr,newEntryStartAddr,valueSizeAddr - entryStartAddr);
      entry=reuse(entry,offset);
    }
 else     if (newSizeInChunks < oldSizeInChunks) {
      freeList.clear(pos + newSizeInChunks,pos + oldSizeInChunks);
    }
  }
  entry.position(valueSizePos);
  valueSizeMarshaller.writeSize(entry,newElemSize);
  alignment.alignPositionAddr(entry);
  metaElemWriter.write(elemWriter,entry,newElem);
  segmentState.pos=pos;
  return offset;
}

Fixed version (ground truth):
/** 
 * Replaces value in existing entry. May cause entry relocation, because there may be not enough space for new value in location already allocated for this entry.
 * @param pos          index of the first chunk occupied by the entry
 * @param offset       relative offset of the entry in Segment bytes (before, i. e.including metaData)
 * @param entry        relative pointer in Segment bytes
 * @param valueSizePos relative position of value size in entry
 * @param entryEndAddr absolute address of the entry end
 * @return relative offset of the entry in Segment bytes after putting value (that may causeentry relocation)
 */
final <E,EW>long putValue(long pos,long offset,MultiStoreBytes entry,long valueSizePos,long entryEndAddr,SegmentState segmentState,MetaBytesWriter<E,? super EW> metaElemWriter,EW elemWriter,E newElem,long newElemSize,MultiMap searchedHashLookup,long sizeOfEverythingBeforeValue){
  long entryStartAddr=entry.address();
  long valueSizeAddr=entryStartAddr + valueSizePos;
  long newValueAddr=alignment.alignAddr(valueSizeAddr + valueSizeMarshaller.sizeEncodingSize(newElemSize));
  long newEntryEndAddr=newValueAddr + newElemSize;
  newValueDoesNotFit:   if (newEntryEndAddr != entryEndAddr) {
    long oldEntrySize=entryEndAddr - entryStartAddr;
    int oldSizeInChunks=inChunks(oldEntrySize);
    int newSizeInChunks=inChunks(newEntryEndAddr - entryStartAddr);
    if (newSizeInChunks > oldSizeInChunks) {
      if (newSizeInChunks > maxChunksPerEntry) {
        throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str" + newSizeInChunks + "String_Node_Str"+ maxChunksPerEntry+ "String_Node_Str");
      }
      if (realloc(pos,oldSizeInChunks,newSizeInChunks))       break newValueDoesNotFit;
      free(pos,oldSizeInChunks);
      onRelocation(this,pos);
      int allocatedChunks=inChunks(innerEntrySize(sizeOfEverythingBeforeValue,newElemSize));
      pos=alloc(allocatedChunks);
      searchedHashLookup.replacePrevPos(segmentState.searchState,pos);
      offset=offsetFromPos(pos);
      long newEntryStartAddr=entry.address();
      NativeBytes.UNSAFE.copyMemory(entryStartAddr,newEntryStartAddr,valueSizeAddr - entryStartAddr);
      entry=reuse(entry,offset);
      entry.position(valueSizePos);
      valueSizeMarshaller.writeSize(entry,newElemSize);
      alignment.alignPositionAddr(entry);
      metaElemWriter.write(elemWriter,entry,newElem);
      freeExtraAllocatedChunks(pos,allocatedChunks,entry);
      segmentState.pos=pos;
      return offset;
    }
 else     if (newSizeInChunks < oldSizeInChunks) {
      freeList.clear(pos + newSizeInChunks,pos + oldSizeInChunks);
    }
  }
  entry.position(valueSizePos);
  valueSizeMarshaller.writeSize(entry,newElemSize);
  alignment.alignPositionAddr(entry);
  metaElemWriter.write(elemWriter,entry,newElem);
  segmentState.pos=pos;
  return offset;
}