nus-yam/ex-repair huggingface dataset:
Program: 162831
Project: 162831
Buggy source:
private long forEachTierWhile(Predicate<? super E> action,long size,int currentTier,long currentTierBaseAddr,long tierIndex){
  boolean interrupted=false;
  long startPos=0L;
  CompactOffHeapLinearHashTable hashLookup=hh.h().hashLookup;
  while (!hashLookup.empty(hashLookup.readEntry(currentTierBaseAddr,startPos))) {
    startPos=hashLookup.step(startPos);
  }
  hlp.initHashLookupPos(startPos);
  long currentHashLookupPos;
  do {
    currentHashLookupPos=hashLookup.step(hlp.hashLookupPos);
    hlp.setHashLookupPos(currentHashLookupPos);
    long entry=hashLookup.readEntry(currentTierBaseAddr,currentHashLookupPos);
    initHashLookupEntry(entry);
    if (!hashLookup.empty(entry)) {
      e.readExistingEntry(hashLookup.value(entry));
      if (entryIsPresent()) {
        initEntryRemovedOnThisIteration(false);
        try {
          if (!action.test((E)this)) {
            interrupted=true;
            break;
          }
 else {
            if (--size == 0)             break;
          }
        }
  finally {
          if (s.tier != currentTier) {
            s.initSegmentTier_WithBaseAddr(currentTier,currentTierBaseAddr,tierIndex);
            currentHashLookupPos=hashLookup.stepBack(currentHashLookupPos);
            hlp.initHashLookupPos(currentHashLookupPos);
          }
        }
      }
    }
  }
 while (currentHashLookupPos != startPos);
  return interrupted ? ~size : size;
}

Fixed version (ground truth):
private long forEachTierWhile(Predicate<? super E> action,long size,int currentTier,long currentTierBaseAddr,long tierIndex){
  boolean interrupted=false;
  long startPos=0L;
  CompactOffHeapLinearHashTable hashLookup=hh.h().hashLookup;
  while (!hashLookup.empty(hashLookup.readEntry(currentTierBaseAddr,startPos))) {
    startPos=hashLookup.step(startPos);
  }
  hlp.initHashLookupPos(startPos);
  long currentHashLookupPos;
  int steps=0;
  do {
    currentHashLookupPos=hashLookup.step(hlp.hashLookupPos);
    steps++;
    hlp.setHashLookupPos(currentHashLookupPos);
    long entry=hashLookup.readEntry(currentTierBaseAddr,currentHashLookupPos);
    initHashLookupEntry(entry);
    if (!hashLookup.empty(entry)) {
      e.readExistingEntry(hashLookup.value(entry));
      if (entryIsPresent()) {
        initEntryRemovedOnThisIteration(false);
        try {
          if (!action.test((E)this)) {
            interrupted=true;
            break;
          }
 else {
            if (--size == 0)             break;
          }
        }
  finally {
          if (s.tier != currentTier) {
            s.initSegmentTier_WithBaseAddr(currentTier,currentTierBaseAddr,tierIndex);
            currentHashLookupPos=hashLookup.stepBack(currentHashLookupPos);
            steps--;
            hlp.initHashLookupPos(currentHashLookupPos);
          }
        }
      }
    }
  }
 while (currentHashLookupPos != startPos || steps == 0);
  return interrupted ? ~size : size;
}
Program: 162832
Project: 162832
Buggy source:
@Test public void testOverflowAllocationDuringIteration(){
  int entries=10000;
  String x="String_Node_Str";
  try (ChronicleMap<Integer,CharSequence> map=ChronicleMapBuilder.of(Integer.class,CharSequence.class).averageValue(x).entries(entries).maxBloatFactor(10.0).actualSegments(1).create()){
    for (int i=0; i < entries; i++) {
      map.put(i,x);
    }
    for (int i=0; i < 3; i++) {
      final String currentX=x;
      map.forEachEntry(e -> {
        String v=e.value().get().toString();
        if (!currentX.contentEquals(v)) {
          throw new AssertionError(currentX + "String_Node_Str" + v+ "String_Node_Str"+ e.key());
        }
        e.doReplaceValue(e.context().wrapValueAsData(v + v));
      }
);
      x=x + x;
      for (int j=0; j < entries; j++) {
        if (map.get(j) == null || !x.contentEquals(map.get(j))) {
          throw new AssertionError();
        }
      }
    }
  }
 }

Fixed version (ground truth):
@Test public void testOverflowAllocationDuringIteration(){
  int entries=10000;
  String x="String_Node_Str";
  try (ChronicleMap<Integer,CharSequence> map=ChronicleMapBuilder.of(Integer.class,CharSequence.class).averageValue(x).entries(entries).maxBloatFactor(10.0).actualSegments(1).create()){
    for (int i=0; i < entries; i++) {
      map.put(i,x);
    }
    for (int i=0; i < 3; i++) {
      try {
        final String currentX=x;
        map.forEachEntry(e -> {
          String v=e.value().get().toString();
          if (!currentX.contentEquals(v)) {
            throw new AssertionError(currentX + "String_Node_Str" + v+ "String_Node_Str"+ e.key());
          }
          e.doReplaceValue(e.context().wrapValueAsData(v + v));
        }
);
        x=x + x;
        for (int j=0; j < entries; j++) {
          if (map.get(j) == null || !x.contentEquals(map.get(j))) {
            throw new AssertionError();
          }
        }
      }
  finally {
        ((VanillaChronicleMap)map).verifyTierCountersAreaData();
      }
    }
  }
 }
Program: 162833
Project: 162833
Buggy source:
public long innerEntrySize(long sizeOfEverythingBeforeValue,long valueSize){
  if (mh.m().constantlySizedEntry) {
    return alignAddr(sizeOfEverythingBeforeValue + valueSize,mh.m().alignment);
  }
 else   if (mh.m().couldNotDetermineAlignmentBeforeAllocation) {
    return sizeOfEverythingBeforeValue + mh.m().worstAlignment + valueSize;
  }
 else {
    return alignAddr(sizeOfEverythingBeforeValue,mh.m().alignment) + valueSize;
  }
}

Fixed version (ground truth):
public long innerEntrySize(long sizeOfEverythingBeforeValue,long valueSize){
  long sizeWithoutChecksum;
  if (mh.m().constantlySizedEntry) {
    sizeWithoutChecksum=alignAddr(sizeOfEverythingBeforeValue + valueSize,mh.m().alignment);
  }
 else   if (mh.m().couldNotDetermineAlignmentBeforeAllocation) {
    sizeWithoutChecksum=sizeOfEverythingBeforeValue + mh.m().worstAlignment + valueSize;
  }
 else {
    sizeWithoutChecksum=alignAddr(sizeOfEverythingBeforeValue,mh.m().alignment) + valueSize;
  }
  return sizeWithoutChecksum + checksumStrategy.extraEntryBytes();
}
Program: 162834
Project: 162834
Buggy source:
@Override public void doInsert(Data<V> value){
  q.putPrefix();
  if (!q.entryPresent()) {
    if (!ks.searchStatePresent()) {
      putEntry(value);
      ks.setSearchState(PRESENT);
      q.initPresenceOfEntry(EntryPresence.PRESENT);
    }
 else {
      e.innerDefaultReplaceValue(value);
      s.deleted(s.deleted() - 1);
    }
    s.incrementModCount();
    e.writeEntryPresent();
    ru.updateChange();
    e.updatedReplicationStateOnAbsentEntry();
    e.checksumStrategy.computeAndStoreChecksum();
  }
 else {
    throw new IllegalStateException("String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void doInsert(Data<V> value){
  q.putPrefix();
  s.innerUpdateLock.lock();
  if (!q.entryPresent()) {
    if (!ks.searchStatePresent()) {
      putEntry(value);
      e.updatedReplicationStateOnAbsentEntry();
      ks.setSearchState(PRESENT);
      q.initPresenceOfEntry(EntryPresence.PRESENT);
    }
 else {
      e.innerDefaultReplaceValue(value);
      e.updatedReplicationStateOnPresentEntry();
      s.deleted(s.deleted() - 1);
    }
    s.incrementModCount();
    e.writeEntryPresent();
    ru.updateChange();
    e.checksumStrategy.computeAndStoreChecksum();
  }
 else {
    throw new IllegalStateException("String_Node_Str");
  }
}
Program: 162835
Project: 162835
Buggy source:
public ModificationIterator(int identifier,ModificationNotifier notifier){
  this(identifier);
  setModificationNotifier(notifier);
}

Fixed version (ground truth):
public ModificationIterator(int remoteIdentifier,ModificationNotifier notifier){
  this(remoteIdentifier);
  setModificationNotifier(notifier);
}
Program: 162836
Project: 162836
Buggy source:
@Override public void run(){
  final Attached attached=new Attached();
  attached.connector=ClientConnector.this;
  try {
    socketChannel.register(selector,OP_CONNECT,attached);
  }
 catch (  ClosedChannelException e) {
    if (socketChannel.isOpen())     LOG.error("String_Node_Str",e);
  }
}

Fixed version (ground truth):
@Override public void run(){
  final Attached attached=new Attached();
  attached.connector=ClientConnector.this;
  try {
    socketChannel.register(selector,OP_CONNECT,attached);
  }
 catch (  ClosedChannelException e) {
    if (socketChannel.isOpen())     LOG.error("String_Node_Str",e);
    onFail(socketChannel);
  }
}
Program: 162837
Project: 162837
Buggy source:
/** 
 * blocks until connected
 */
@Override SelectableChannel doConnect() throws IOException, InterruptedException {
  boolean success=false;
  final SocketChannel socketChannel=openSocketChannel(TcpReplicator.this.closeables);
  try {
    socketChannel.configureBlocking(false);
    socketChannel.socket().setReuseAddress(true);
    socketChannel.socket().setSoLinger(false,0);
    socketChannel.socket().setSoTimeout(0);
    socketChannel.connect(details.address());
    Thread.sleep(10);
    addPendingRegistration(new Runnable(){
      @Override public void run(){
        final Attached attached=new Attached();
        attached.connector=ClientConnector.this;
        try {
          socketChannel.register(selector,OP_CONNECT,attached);
        }
 catch (        ClosedChannelException e) {
          if (socketChannel.isOpen())           LOG.error("String_Node_Str",e);
        }
      }
    }
);
    selector.wakeup();
    success=true;
    return socketChannel;
  }
  finally {
    if (!success) {
      try {
        try {
          socketChannel.socket().close();
        }
 catch (        Exception e) {
          LOG.error("String_Node_Str",e);
        }
        socketChannel.close();
      }
 catch (      IOException e) {
        LOG.error("String_Node_Str",e);
      }
      this.connectLater();
    }
  }
}

Fixed version (ground truth):
/** 
 * blocks until connected
 */
@Override SelectableChannel doConnect() throws IOException, InterruptedException {
  boolean success=false;
  final SocketChannel socketChannel=openSocketChannel(TcpReplicator.this.closeables);
  try {
    socketChannel.configureBlocking(false);
    socketChannel.socket().setReuseAddress(true);
    socketChannel.socket().setSoLinger(false,0);
    socketChannel.socket().setSoTimeout(0);
    socketChannel.connect(details.address());
    Thread.sleep(10);
    addPendingRegistration(new Runnable(){
      @Override public void run(){
        final Attached attached=new Attached();
        attached.connector=ClientConnector.this;
        try {
          socketChannel.register(selector,OP_CONNECT,attached);
        }
 catch (        ClosedChannelException e) {
          if (socketChannel.isOpen())           LOG.error("String_Node_Str",e);
          onFail(socketChannel);
        }
      }
    }
);
    selector.wakeup();
    success=true;
    return socketChannel;
  }
  finally {
    if (!success) {
      onFail(socketChannel);
    }
  }
}
Program: 162838
Project: 162838
Buggy source:
/** 
 * called when the selector receives a OP_CONNECT message
 */
private void onConnect(@NotNull final SelectionKey key) throws IOException {
  SocketChannel channel=null;
  try {
    channel=(SocketChannel)key.channel();
  }
  finally {
    closeables.add(channel);
  }
  final Attached attached=(Attached)key.attachment();
  try {
    if (!channel.finishConnect()) {
      return;
    }
  }
 catch (  SocketException e) {
    quietClose(key,e);
    attached.connector.connectLater();
    throw e;
  }
  attached.connector.setSuccessfullyConnected();
  if (LOG.isDebugEnabled())   LOG.debug("String_Node_Str",channel.socket().getInetAddress(),localIdentifier);
  channel.configureBlocking(false);
  channel.socket().setTcpNoDelay(true);
  channel.socket().setSoTimeout(0);
  channel.socket().setSoLinger(false,0);
  attached.entryReader=new TcpSocketChannelEntryReader();
  attached.entryWriter=new TcpSocketChannelEntryWriter();
  key.interestOps(OP_WRITE | OP_READ);
  throttle(channel);
  attached.entryWriter.identifierToBuffer(localIdentifier);
}

Fixed version (ground truth):
/** 
 * called when the selector receives a OP_CONNECT message
 */
private void onConnect(@NotNull final SelectionKey key) throws IOException {
  SocketChannel channel=null;
  try {
    channel=(SocketChannel)key.channel();
  }
  finally {
    closeables.add(channel);
  }
  final Attached attached=(Attached)key.attachment();
  try {
    if (!channel.finishConnect()) {
      return;
    }
    channel.configureBlocking(false);
    channel.socket().setTcpNoDelay(true);
    channel.socket().setSoTimeout(0);
    channel.socket().setSoLinger(false,0);
  }
 catch (  IOException e) {
    quietClose(key,e);
    attached.connector.connectLater();
    throw e;
  }
  attached.connector.setSuccessfullyConnected();
  if (LOG.isDebugEnabled())   LOG.debug("String_Node_Str",channel.socket().getInetAddress(),localIdentifier);
  attached.entryReader=new TcpSocketChannelEntryReader();
  attached.entryWriter=new TcpSocketChannelEntryWriter();
  key.interestOps(OP_WRITE | OP_READ);
  throttle(channel);
  attached.entryWriter.identifierToBuffer(localIdentifier);
}
Program: 162839
Project: 162839
Buggy source:
@Override public void close() throws IOException {
  channelDataLock.writeLock().lock();
  try {
    int removedPos=chronicleChannelPositionsInList[chronicleChannel];
    if (removedPos == -1)     return;
    chronicleChannelPositionsInList[removedPos]=-1;
    chronicleChannelList.remove(removedPos);
    chronicleChannelIds.remove(removedPos);
    for (int i=0, len=chronicleChannelIds.size(); i < len; i++) {
      int channelId=chronicleChannelIds.get(i);
      int pos=chronicleChannelPositionsInList[channelId];
      if (pos > removedPos)       chronicleChannelPositionsInList[channelId]=pos - 1;
    }
    chronicleChannels[chronicleChannel]=null;
    channelEntryExternalizables[chronicleChannel]=null;
    if (chronicleChannelList.size() == 1)     ChannelProvider.this.close();
  }
  finally {
    channelDataLock.writeLock().unlock();
  }
}

Fixed version (ground truth):
@Override public void close() throws IOException {
  channelDataLock.writeLock().lock();
  try {
    int removedPos=chronicleChannelPositionsInList[chronicleChannel];
    if (removedPos == -1)     return;
    chronicleChannelPositionsInList[chronicleChannel]=-1;
    chronicleChannelList.remove(removedPos);
    chronicleChannelIds.remove(removedPos);
    for (int i=0, len=chronicleChannelIds.size(); i < len; i++) {
      int channelId=chronicleChannelIds.get(i);
      int pos=chronicleChannelPositionsInList[channelId];
      if (pos > removedPos)       chronicleChannelPositionsInList[channelId]=pos - 1;
    }
    chronicleChannels[chronicleChannel]=null;
    channelEntryExternalizables[chronicleChannel]=null;
    if (chronicleChannelList.size() == 1)     ChannelProvider.this.close();
  }
  finally {
    channelDataLock.writeLock().unlock();
  }
}
Program: 162840
Project: 162840
Buggy source:
@Override public ChronicleSetBuilder<K> aligned64BitMemoryOperationsAtomic(boolean aligned64BitMemoryOperationsAtomic){
  return null;
}

Fixed version (ground truth):
@Override public ChronicleSetBuilder<K> aligned64BitMemoryOperationsAtomic(boolean aligned64BitMemoryOperationsAtomic){
  chronicleMapBuilder.aligned64BitMemoryOperationsAtomic(aligned64BitMemoryOperationsAtomic);
  return this;
}
Program: 162841
Project: 162841
Buggy source:
/** 
 * called when the selector receives a OP_READ message
 */
private void onRead(@NotNull final SelectionKey key,final long approxTime) throws IOException, InterruptedException {
  final SocketChannel socketChannel=(SocketChannel)key.channel();
  final Attached attached=(Attached)key.attachment();
  if (attached == null) {
    LOG.info("String_Node_Str" + socketChannel + "String_Node_Str");
    socketChannel.close();
    return;
  }
  try {
    int len=attached.entryReader.readSocketToBuffer(socketChannel);
    if (len == -1) {
      socketChannel.register(selector,0);
      if (replicationConfig.autoReconnectedUponDroppedConnection()) {
        AbstractConnector connector=attached.connector;
        if (connector != null)         connector.connectLater();
      }
 else       socketChannel.close();
      return;
    }
    if (len == 0)     return;
    if (attached.entryWriter.isWorkIncomplete())     return;
  }
 catch (  IOException e) {
    if (!attached.isServer)     attached.connector.connectLater();
    throw e;
  }
  if (LOG.isDebugEnabled())   LOG.debug("String_Node_Str");
  attached.entryReader.lastHeartBeatReceived=approxTime;
  if (attached.isHandShakingComplete()) {
    attached.entryReader.entriesFromBuffer(attached,key);
  }
 else {
    doHandShaking(key,socketChannel);
  }
}

Fixed version (ground truth):
/** 
 * called when the selector receives a OP_READ message
 */
private void onRead(@NotNull final SelectionKey key,final long approxTime) throws IOException, InterruptedException {
  final SocketChannel socketChannel=(SocketChannel)key.channel();
  final Attached attached=(Attached)key.attachment();
  if (attached == null) {
    LOG.info("String_Node_Str" + socketChannel + "String_Node_Str");
    socketChannel.close();
    return;
  }
  try {
    int len=attached.entryReader.readSocketToBuffer(socketChannel);
    if (len == -1) {
      socketChannel.register(selector,0,attached);
      if (replicationConfig.autoReconnectedUponDroppedConnection()) {
        AbstractConnector connector=attached.connector;
        if (connector != null)         connector.connectLater();
      }
 else       socketChannel.close();
      return;
    }
    if (len == 0)     return;
    if (attached.entryWriter.isWorkIncomplete())     return;
  }
 catch (  IOException e) {
    if (!attached.isServer)     attached.connector.connectLater();
    throw e;
  }
  if (LOG.isDebugEnabled())   LOG.debug("String_Node_Str");
  attached.entryReader.lastHeartBeatReceived=approxTime;
  if (attached.isHandShakingComplete()) {
    attached.entryReader.entriesFromBuffer(attached,key);
  }
 else {
    doHandShaking(key,socketChannel);
  }
}
Program: 162842
Project: 162842
Buggy source:
/** 
 * closes and only logs the exception at debug
 * @param key the SelectionKey
 * @param e   the Exception that caused the issue
 */
private void quietClose(@NotNull final SelectionKey key,@NotNull final Exception e){
  if (LOG.isDebugEnabled())   LOG.debug("String_Node_Str",e);
  if (key.channel() != null && key.attachment() != null && connectionListener != null)   connectionListener.onDisconnect(((SocketChannel)key.channel()).socket().getInetAddress(),((Attached)key.attachment()).remoteIdentifier);
  closeEarlyAndQuietly(key.channel());
}

Fixed version (ground truth):
/** 
 * closes and only logs the exception at debug
 * @param key the SelectionKey
 * @param e   the Exception that caused the issue
 */
private void quietClose(@NotNull final SelectionKey key,@Nullable final Exception e){
  if (LOG.isDebugEnabled() && e != null)   LOG.debug("String_Node_Str",e);
  if (key.channel() != null && key.attachment() != null && connectionListener != null)   connectionListener.onDisconnect(((SocketChannel)key.channel()).socket().getInetAddress(),((Attached)key.attachment()).remoteIdentifier);
  closeEarlyAndQuietly(key.channel());
}
Program: 162843
Project: 162843
Buggy source:
/** 
 * check to see if we have lost connection with the remote node and if we have attempts a reconnect.
 * @param key               the key relating to the heartbeat that we are checking
 * @param approxTimeOutTime the approximate time in milliseconds
 * @throws ConnectException
 */
private void heartbeatCheckHasReceived(@NotNull final SelectionKey key,final long approxTimeOutTime){
  final Attached attached=(Attached)key.attachment();
  if (attached.isServer || !attached.isHandShakingComplete())   return;
  final SocketChannel channel=(SocketChannel)key.channel();
  if (approxTimeOutTime > attached.entryReader.lastHeartBeatReceived + attached.remoteHeartbeatInterval) {
    if (LOG.isDebugEnabled())     LOG.debug("String_Node_Str" + "String_Node_Str" + attached.remoteIdentifier);
    activeKeys.clear(attached.remoteIdentifier);
    closeables.closeQuietly(channel.socket());
    if (replicationConfig.autoReconnectedUponDroppedConnection())     attached.connector.connectLater();
  }
}

Fixed version (ground truth):
/** 
 * check to see if we have lost connection with the remote node and if we have attempts a reconnect.
 * @param key               the key relating to the heartbeat that we are checking
 * @param approxTimeOutTime the approximate time in milliseconds
 * @throws ConnectException
 */
private void heartbeatCheckHasReceived(@NotNull final SelectionKey key,final long approxTimeOutTime){
  final Attached attached=(Attached)key.attachment();
  if (attached.isServer && !attached.isHandShakingComplete())   return;
  final SocketChannel channel=(SocketChannel)key.channel();
  if (approxTimeOutTime > attached.entryReader.lastHeartBeatReceived + attached.remoteHeartbeatInterval) {
    if (LOG.isDebugEnabled())     LOG.debug("String_Node_Str" + "String_Node_Str" + attached.remoteIdentifier);
    activeKeys.clear(attached.remoteIdentifier);
    quietClose(key,null);
    closeables.closeQuietly(channel.socket());
    if (replicationConfig.autoReconnectedUponDroppedConnection())     attached.connector.connectLater();
  }
}
Program: 162844
Project: 162844
Buggy source:
public long tierIndexToBaseAddr(long tierIndex){
  tierIndex-=1;
  if (tierIndex < actualSegments)   return segmentBaseAddr((int)tierIndex);
  return extraTierIndexToBaseAddress(tierIndex);
}

Fixed version (ground truth):
public long tierIndexToBaseAddr(long tierIndex){
  long tierIndexMinusOne=tierIndex - 1;
  if (tierIndexMinusOne < actualSegments)   return segmentBaseAddr((int)tierIndexMinusOne);
  return extraTierIndexToBaseAddr(tierIndexMinusOne);
}
Program: 162845
Project: 162845
Buggy source:
private long combineExtraTier(long tierIndexMinusOne,long pos){
  long extraTierIndex=tierIndexMinusOne - actualSegments;
  long tierOffsetWithinBulk=extraTierIndex & ((1L << log2NumberOfTiersInBulk) - 1);
  return (tierOffsetWithinBulk << segmentIndexShift) | pos;
}

Fixed version (ground truth):
private long combineExtraTier(long tierIndexMinusOne,long pos){
  long extraTierIndex=tierIndexMinusOne - actualSegments;
  long tierIndexOffsetWithinBulk=extraTierIndex & (numberOfTiersInBulk - 1);
  return (tierIndexOffsetWithinBulk << segmentIndexShift) | pos;
}
Program: 162847
Project: 162847
Buggy source:
private void waitTillEqual(final int timeOutMs) throws InterruptedException {
  Map map1UnChanged=new HashMap();
  Map map2UnChanged=new HashMap();
  int numberOfTimesTheSame=0;
  long startTime=System.currentTimeMillis();
  for (int t=0; t < timeOutMs + 100; t++) {
    if (map1.entrySet().equals(map2.entrySet())) {
      if (map1.equals(map1UnChanged) && map2.equals(map2UnChanged)) {
        numberOfTimesTheSame++;
      }
 else {
        numberOfTimesTheSame=0;
        map1UnChanged=new HashMap(map1);
        map2UnChanged=new HashMap(map2);
      }
      Thread.sleep(1);
      if (numberOfTimesTheSame == 10) {
        System.out.println("String_Node_Str");
        break;
      }
    }
    Thread.sleep(1);
    if (System.currentTimeMillis() - startTime > timeOutMs)     break;
  }
}

Fixed version (ground truth):
private void waitTillEqual(final int timeOutMs) throws InterruptedException {
  Map map1UnChanged=new HashMap();
  Map map2UnChanged=new HashMap();
  int numberOfTimesTheSame=0;
  long startTime=System.currentTimeMillis();
  for (int t=0; t < timeOutMs + 100; t++) {
    if (difference(map1,map2).areEqual()) {
      if (difference(map1,map1UnChanged).areEqual() && difference(map2,map2UnChanged).areEqual()) {
        numberOfTimesTheSame++;
      }
 else {
        numberOfTimesTheSame=0;
        map1UnChanged=new HashMap(map1);
        map2UnChanged=new HashMap(map2);
      }
      Thread.sleep(1);
      if (numberOfTimesTheSame == 10) {
        System.out.println("String_Node_Str");
        break;
      }
    }
    Thread.sleep(1);
    if (System.currentTimeMillis() - startTime > timeOutMs)     break;
  }
}
Program: 162848
Project: 162848
Buggy source:
@Test public void testSoakTestWithRandomData() throws IOException, InterruptedException {
  try {
    System.out.print("String_Node_Str");
    for (int j=1; j < 2 * Builder.SIZE; j++) {
      if (j % 1000 == 0)       System.out.print("String_Node_Str");
      Random rnd=new Random(j);
      for (int i=1; i < 10; i++) {
        final ChronicleMap<Integer,Set<Integer>> map=rnd.nextBoolean() ? map1 : map2;
        int key=rnd.nextInt(Builder.SIZE);
        try (ExternalMapQueryContext<Integer,Set<Integer>,?> q=map.queryContext(key)){
          q.updateLock().lock();
          MapEntry<Integer,Set<Integer>> entry=q.entry();
          if (entry != null) {
            Set<Integer> value=entry.value().get();
            value.add(rnd.nextInt(20));
            q.replaceValue(entry,q.wrapValueAsData(value));
          }
 else {
            HashSet<Integer> value=new HashSet<>();
            q.insert(q.absentEntry(),q.wrapValueAsData(value));
          }
        }
       }
    }
    System.out.println("String_Node_Str");
    waitTillEqual(15000);
    assertEquals(map1.entrySet(),map2.entrySet());
  }
  finally {
    map1.close();
    map2.close();
  }
}

Fixed version (ground truth):
@Test public void testSoakTestWithRandomData() throws IOException, InterruptedException {
  try {
    System.out.print("String_Node_Str");
    for (int j=1; j < 2 * Builder.SIZE; j++) {
      if (j % 1000 == 0)       System.out.print("String_Node_Str");
      Random rnd=new Random(j);
      for (int i=1; i < 10; i++) {
        final ChronicleMap<Integer,Set<Integer>> map=rnd.nextBoolean() ? map1 : map2;
        int key=rnd.nextInt(Builder.SIZE);
        try (ExternalMapQueryContext<Integer,Set<Integer>,?> q=map.queryContext(key)){
          q.updateLock().lock();
          MapEntry<Integer,Set<Integer>> entry=q.entry();
          if (entry != null) {
            Set<Integer> value=entry.value().get();
            value.add(rnd.nextInt(20));
            q.replaceValue(entry,q.wrapValueAsData(value));
          }
 else {
            HashSet<Integer> value=new HashSet<>();
            q.insert(q.absentEntry(),q.wrapValueAsData(value));
          }
        }
       }
    }
    System.out.println("String_Node_Str");
    waitTillEqual(15000);
    MapDifference<Integer,Set<Integer>> difference=difference(map1,map2);
    if (difference.areEqual()) {
      System.out.println("String_Node_Str");
      return;
    }
    Map<Integer,Set<Integer>> onlyOnMap1=difference.entriesOnlyOnLeft();
    System.out.println("String_Node_Str");
    for (    Integer k : onlyOnMap1.keySet()) {
      printState(map1,k);
    }
    Map<Integer,Set<Integer>> onlyOnMap2=difference.entriesOnlyOnRight();
    System.out.println("String_Node_Str");
    for (    Integer k : onlyOnMap2.keySet()) {
      printState(map2,k);
    }
    Set<Integer> entryDifferingKeys=difference.entriesDiffering().keySet();
    System.out.println("String_Node_Str");
    for (    Integer k : entryDifferingKeys) {
      printState(map1,k);
      printState(map2,k);
    }
    throw new AssertionError(difference);
  }
  finally {
    map1.close();
    map2.close();
  }
}
Program: 162849
Project: 162849
Buggy source:
@Before public void setup() throws IOException {
  final InetSocketAddress endpoint=new InetSocketAddress("String_Node_Str",s_port + 1);
  HashSet<Integer> averageValue=new HashSet<>();
  for (int i=0; i < 10; i++) {
    averageValue.add(i);
  }
  ChronicleMapBuilder<Integer,Set<Integer>> builder=ChronicleMapBuilder.of(Integer.class,(Class<Set<Integer>>)(Class)Set.class).entries(Builder.SIZE).averageValue(averageValue).entryOperations(growOnlySetValuedMapEntryOperations()).remoteOperations(growOnlySetValuedMapRemoteOperations());
{
    final TcpTransportAndNetworkConfig tcpConfig1=TcpTransportAndNetworkConfig.of(s_port,endpoint).autoReconnectedUponDroppedConnection(true).heartBeatInterval(1,TimeUnit.SECONDS).tcpBufferSize((int)MEGABYTES.toBytes(64));
    map1=builder.replication(SingleChronicleHashReplication.builder().tcpTransportAndNetwork(tcpConfig1).name("String_Node_Str").createWithId((byte)1)).instance().name("String_Node_Str").create();
  }
{
    final TcpTransportAndNetworkConfig tcpConfig2=TcpTransportAndNetworkConfig.of(s_port + 1).autoReconnectedUponDroppedConnection(true).heartBeatInterval(1,TimeUnit.SECONDS).tcpBufferSize((int)MEGABYTES.toBytes(64));
    map2=builder.replication(SingleChronicleHashReplication.builder().tcpTransportAndNetwork(tcpConfig2).name("String_Node_Str").createWithId((byte)2)).instance().name("String_Node_Str").create();
  }
  s_port+=2;
}

Fixed version (ground truth):
@Before public void setup() throws IOException {
  final InetSocketAddress endpoint=new InetSocketAddress("String_Node_Str",s_port + 1);
  HashSet<Integer> averageValue=new HashSet<>();
  for (int i=0; i < 10; i++) {
    averageValue.add(i);
  }
  ChronicleMapBuilder<Integer,Set<Integer>> builder=ChronicleMapBuilder.of(Integer.class,(Class<Set<Integer>>)(Class)Set.class).entries(Builder.SIZE).averageValue(averageValue).entryOperations(growOnlySetValuedMapEntryOperations()).remoteOperations(growOnlySetValuedMapRemoteOperations());
{
    final TcpTransportAndNetworkConfig tcpConfig1=TcpTransportAndNetworkConfig.of(s_port,endpoint).autoReconnectedUponDroppedConnection(true).heartBeatInterval(1,TimeUnit.SECONDS).tcpBufferSize((int)MEGABYTES.toBytes(64));
    map1=builder.instance().replicated(SingleChronicleHashReplication.builder().tcpTransportAndNetwork(tcpConfig1).name("String_Node_Str").createWithId((byte)1)).name("String_Node_Str").create();
  }
{
    final TcpTransportAndNetworkConfig tcpConfig2=TcpTransportAndNetworkConfig.of(s_port + 1).autoReconnectedUponDroppedConnection(true).heartBeatInterval(1,TimeUnit.SECONDS).tcpBufferSize((int)MEGABYTES.toBytes(64));
    map2=builder.instance().replicated(SingleChronicleHashReplication.builder().tcpTransportAndNetwork(tcpConfig2).name("String_Node_Str").createWithId((byte)2)).name("String_Node_Str").create();
  }
  s_port+=2;
}
Program: 162850
Project: 162850
Buggy source:
private static <K,V>boolean trySerializeHeaderViaXStream(VanillaChronicleMap<K,?,?,V,?,?,?> map,ObjectOutputStream oos) throws IOException {
  Class<?> xStreamClass;
  try {
    xStreamClass=Class.forName("String_Node_Str");
  }
 catch (  ClassNotFoundException e) {
    xStreamClass=null;
  }
  if (xStreamClass == null) {
    LOG.info("String_Node_Str");
    return false;
  }
  try {
    oos.writeByte(XML_SERIALIZATION);
    Method toXML=xStreamClass.getMethod("String_Node_Str",Object.class,OutputStream.class);
    toXML.invoke(xStreamClass.newInstance(),map,oos);
    return true;
  }
 catch (  NoSuchMethodException|InvocationTargetException|IllegalAccessException|InstantiationException e) {
    throw new AssertionError(e);
  }
}

Fixed version (ground truth):
private static <K,V>boolean trySerializeHeaderViaXStream(VanillaChronicleMap<K,?,?,V,?,?,?> map,ObjectOutputStream oos) throws IOException {
  Class<?> xStreamClass;
  try {
    xStreamClass=Class.forName("String_Node_Str");
  }
 catch (  ClassNotFoundException|NoClassDefFoundError e) {
    xStreamClass=null;
  }
  if (xStreamClass == null) {
    LOG.info("String_Node_Str");
    return false;
  }
  try {
    oos.writeByte(XML_SERIALIZATION);
    Method toXML=xStreamClass.getMethod("String_Node_Str",Object.class,OutputStream.class);
    toXML.invoke(xStreamClass.newInstance(),map,oos);
    return true;
  }
 catch (  NoSuchMethodException|InvocationTargetException|IllegalAccessException|InstantiationException e) {
    throw new AssertionError(e);
  }
}
Program: 162851
Project: 162851
Buggy source:
protected void relocation(Data<V> newValue,long newSizeOfEverythingBeforeValue){
  s.free(pos,entrySizeInChunks);
  long entrySize=innerEntrySize(newSizeOfEverythingBeforeValue,newValue.size());
  allocatedChunks.initEntryAndKeyCopying(entrySize,valueSizeOffset - keySizeOffset);
  writeValueAndPutPos(newValue);
}

Fixed version (ground truth):
protected void relocation(Data<V> newValue,long newSizeOfEverythingBeforeValue){
  s.innerWriteLock.lock();
  s.free(pos,entrySizeInChunks);
  long entrySize=innerEntrySize(newSizeOfEverythingBeforeValue,newValue.size());
  allocatedChunks.initEntryAndKeyCopying(entrySize,valueSizeOffset - keySizeOffset);
  writeValueAndPutPos(newValue);
}
Program: 162852
Project: 162852
Buggy source:
private <E>double preMapConstruction(SerializationBuilder<E> builder,double configuredAverageSize,E average,E sample){
  builder.objectSerializer(acquireObjectSerializer(JDKObjectSerializer.INSTANCE));
  if (sample != null) {
    builder.constantSizeBySample(sample);
    return builder.maxSize();
  }
 else {
    return averageKeyOrValueSize(configuredAverageSize,builder,average);
  }
}

Fixed version (ground truth):
private <E>double preMapConstruction(SerializationBuilder<E> builder,double configuredAverageSize,E average,E sample){
  builder.objectSerializer(acquireObjectSerializer(JDKObjectSerializer.INSTANCE));
  if (sample != null) {
    builder.maxSize(DEFAULT_KEY_OR_VALUE_SIZE);
    builder.constantSizeBySample(sample);
    return builder.maxSize();
  }
 else {
    return averageKeyOrValueSize(configuredAverageSize,builder,average);
  }
}
Program: 162853
Project: 162853
Buggy source:
public void putValueDeletedEntry(Data<V> newValue){
}

Fixed version (ground truth):
public void putValueDeletedEntry(Data<V> newValue){
  throw new AssertionError("String_Node_Str" + "String_Node_Str");
}
Program: 162854
Project: 162854
Buggy source:
public SerializationBuilder<E> maxSize(long maxSize){
  if (copyingInterop == CopyingInterop.FROM_MARSHALLER) {
    this.maxSize=maxSize;
    metaInteropProvider(CopyingMetaBytesInterop.<E,BytesMarshaller<E>>providerForBytesMarshaller(instancesAreMutable,maxSize));
  }
 else   if (copyingInterop == CopyingInterop.FROM_WRITER) {
    this.maxSize=maxSize;
    metaInteropProvider(CopyingMetaBytesInterop.<E,BytesWriter<E>>providerForBytesWriter(instancesAreMutable));
  }
  return this;
}

Fixed version (ground truth):
public long maxSize(){
  return maxSize;
}
Program: 162855
Project: 162855
Buggy source:
private double averageKeySize(){
  return averageKeySize=averageKeyOrValueSize(averageKeySize,keyBuilder,averageKey);
}

Fixed version (ground truth):
private double averageKeySize(){
  if (!isDefined(averageKeySize))   throw new AssertionError();
  return averageKeySize;
}
Program: 162856
Project: 162856
Buggy source:
private <E>void preMapConstruction(boolean replicated,SerializationBuilder<E> builder,double averageSize,E sample){
  builder.objectSerializer(acquireObjectSerializer(JDKObjectSerializer.INSTANCE));
  if (sample != null) {
    builder.constantSizeBySample(sample);
  }
 else {
    builder.maxSize(bufferSize(builder,averageSize,replicated));
  }
}

Fixed version (ground truth):
private <E>double preMapConstruction(SerializationBuilder<E> builder,double configuredAverageSize,E average,E sample){
  builder.objectSerializer(acquireObjectSerializer(JDKObjectSerializer.INSTANCE));
  if (sample != null) {
    builder.constantSizeBySample(sample);
    return builder.maxSize();
  }
 else {
    return averageKeyOrValueSize(configuredAverageSize,builder,average);
  }
}
Program: 162857
Project: 162857
Buggy source:
double averageValueSize(){
  return averageValueSize=averageKeyOrValueSize(averageValueSize,valueBuilder,averageValue);
}

Fixed version (ground truth):
double averageValueSize(){
  if (!isDefined(averageValueSize))   throw new AssertionError();
  return averageValueSize;
}
Program: 162858
Project: 162858
Buggy source:
private long bufferSize(SerializationBuilder builder,double averageSize,boolean replicated){
  if (builder.constantSizeMarshaller())   return round(ceil(averageSize));
  int maxChunksPerEntry=maxChunksPerEntry(replicated);
  int limitedMaxChunksPerEntry=Math.min(64,maxChunksPerEntry);
  long limitedMaxEntrySize=limitedMaxChunksPerEntry * chunkSize(replicated);
  long limitFactor=Math.max(2L,entries() >> 10);
  return Math.min(round(ceil(limitFactor * averageSize)),limitedMaxEntrySize);
}

Fixed version (ground truth):
private long bufferSize(SerializationBuilder builder,double averageSize,boolean replicated){
  if (builder.constantSizeMarshaller())   return round(ceil(averageSize));
  @SuppressWarnings("String_Node_Str") int maxChunksPerEntry=maxChunksPerEntry(replicated);
  int limitedMaxChunksPerEntry=Math.min(64,maxChunksPerEntry);
  long limitedMaxEntrySize=limitedMaxChunksPerEntry * chunkSize(replicated);
  long limitFactor=Math.max(2L,entries() >> 10);
  return Math.min(round(ceil(limitFactor * averageSize)),limitedMaxEntrySize);
}
Program: 162859
Project: 162859
Buggy source:
@Override public boolean onEntry(final Bytes entry,final int chronicleId){
  long startOfEntry=entry.position();
  long pos0=in.position();
  long start=0;
  try {
    in.writeByte(StatelessChronicleMap.EventId.STATEFUL_UPDATE.ordinal());
    long sizeLocation=in.position();
    in.skip(SIZE_OF_SIZE);
    start=in.position();
    externalizable.writeExternalEntry(entry,in,chronicleId);
    if (in.position() == start) {
      in.position(pos0);
      return false;
    }
    final long bytesWritten=(int)(in.position() - start);
    if (bytesWritten > Integer.MAX_VALUE)     throw new IllegalStateException("String_Node_Str" + "String_Node_Str" + Integer.MAX_VALUE);
    if (LOG.isDebugEnabled())     LOG.debug("String_Node_Str" + (int)bytesWritten);
    in.writeInt(sizeLocation,(int)bytesWritten);
  }
 catch (  IllegalArgumentException e) {
    entry.position(startOfEntry);
    in.position(pos0);
    long remaining=in.remaining();
    int entrySize=externalizable.sizeOfEntry(entry,chronicleId);
    if (entrySize > remaining) {
      long newSize=start + entrySize;
      if (newSize > Integer.MAX_VALUE)       return false;
      resizeBuffer((int)newSize);
      in.position(pos0);
      entry.position(startOfEntry);
      return onEntry(entry,chronicleId);
    }
 else     throw e;
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean onEntry(@NotNull final Bytes entry,final int chronicleId,final long bootstrapTime){
  long startOfEntry=entry.position();
  long pos0=in.position();
  long start=0;
  try {
    in.writeByte(StatelessChronicleMap.EventId.STATEFUL_UPDATE.ordinal());
    long sizeLocation=in.position();
    in.skip(SIZE_OF_SIZE);
    start=in.position();
    externalizable.writeExternalEntry(entry,in,chronicleId,bootstrapTime);
    if (in.position() == start) {
      in.position(pos0);
      return false;
    }
    final long bytesWritten=(int)(in.position() - start);
    if (bytesWritten > Integer.MAX_VALUE)     throw new IllegalStateException("String_Node_Str" + "String_Node_Str" + Integer.MAX_VALUE);
    if (LOG.isDebugEnabled())     LOG.debug("String_Node_Str" + (int)bytesWritten);
    in.writeInt(sizeLocation,(int)bytesWritten);
  }
 catch (  IllegalArgumentException e) {
    entry.position(startOfEntry);
    in.position(pos0);
    long remaining=in.remaining();
    int entrySize=externalizable.sizeOfEntry(entry,chronicleId);
    if (entrySize > remaining) {
      long newSize=start + entrySize;
      if (newSize > Integer.MAX_VALUE)       return false;
      resizeBuffer((int)newSize);
      in.position(pos0);
      entry.position(startOfEntry);
      return onEntry(entry,chronicleId,bootstrapTime);
    }
 else     throw e;
  }
  return true;
}
Program: 162860
Project: 162860
Buggy source:
@Override public ModificationIterator acquireModificationIterator(final byte remoteIdentifier){
  final ModificationIterator result=systemModificationIterator.get(remoteIdentifier);
  if (result != null)   return result;
  final PayloadProvider iterator=new PayloadProvider(){
    final Queue<Bytes> payloads=new LinkedTransferQueue<Bytes>();
    ModificationNotifier modificationNotifier0;
    @Override public boolean hasNext(){
      return payloads.peek() != null;
    }
    @Override public boolean nextEntry(    @NotNull EntryCallback callback,    int na){
      final Bytes bytes=payloads.poll();
      if (bytes == null)       return false;
      callback.onEntry(bytes,0);
      return true;
    }
    @Override public void dirtyEntries(    long fromTimeStamp){
    }
    @Override public void setModificationNotifier(    @NotNull ModificationNotifier modificationNotifier){
      modificationNotifier0=modificationNotifier;
    }
    @Override public void addPayload(    Bytes bytes){
      if (bytes.remaining() == 0)       return;
      payloads.add(bytes);
      modificationNotifier0.onChange();
    }
  }
;
  systemModificationIterator.set(remoteIdentifier,iterator);
  systemModificationIteratorBitSet.set(remoteIdentifier);
  return iterator;
}

Fixed version (ground truth):
@Override public ModificationIterator acquireModificationIterator(final byte remoteIdentifier){
  final ModificationIterator result=systemModificationIterator.get(remoteIdentifier);
  if (result != null)   return result;
  final PayloadProvider iterator=new PayloadProvider(){
    final Queue<Bytes> payloads=new LinkedTransferQueue<Bytes>();
    ModificationNotifier modificationNotifier0;
    @Override public boolean hasNext(){
      return payloads.peek() != null;
    }
    @Override public boolean nextEntry(    @NotNull EntryCallback callback,    int na){
      final Bytes bytes=payloads.poll();
      if (bytes == null)       return false;
      callback.onEntry(bytes,0,System.currentTimeMillis());
      return true;
    }
    @Override public void dirtyEntries(    long fromTimeStamp){
    }
    @Override public void setModificationNotifier(    @NotNull ModificationNotifier modificationNotifier){
      modificationNotifier0=modificationNotifier;
    }
    @Override public void addPayload(    Bytes bytes){
      if (bytes.remaining() == 0)       return;
      payloads.add(bytes);
      modificationNotifier0.onChange();
    }
  }
;
  systemModificationIterator.set(remoteIdentifier,iterator);
  systemModificationIteratorBitSet.set(remoteIdentifier);
  return iterator;
}
Program: 162861
Project: 162861
Buggy source:
@Override public void writeExternalEntry(@NotNull Bytes entry,@NotNull Bytes destination,int na){
  destination.write(entry,entry.position(),entry.remaining());
}

Fixed version (ground truth):
@Override public void writeExternalEntry(@NotNull Bytes entry,@NotNull Bytes destination,int na,long bootstrapTime){
  destination.write(entry,entry.position(),entry.remaining());
}
Program: 162862
Project: 162862
Buggy source:
@Override public boolean nextEntry(@NotNull EntryCallback callback,int na){
  final Bytes bytes=payloads.poll();
  if (bytes == null)   return false;
  callback.onEntry(bytes,0);
  return true;
}

Fixed version (ground truth):
@Override public boolean nextEntry(@NotNull EntryCallback callback,int na){
  final Bytes bytes=payloads.poll();
  if (bytes == null)   return false;
  callback.onEntry(bytes,0,System.currentTimeMillis());
  return true;
}
Program: 162863
Project: 162863
Buggy source:
/** 
 * The map implements this method to save its contents.
 * @param entry       the byte location of the entry to be stored
 * @param destination a buffer the entry will be written to, the segment may reject thisoperation and add zeroBytes, if the identifier in the entry did not match the maps local
 * @param chronicleId is the channel id used to identify the canonical map or queue
 */
void writeExternalEntry(@NotNull Bytes entry,@NotNull Bytes destination,int chronicleId);

Fixed version (ground truth):
/** 
 * The map implements this method to save its contents.
 * @param entry       the byte location of the entry to be stored
 * @param destination a buffer the entry will be written to, the segment may reject thisoperation and add zeroBytes, if the identifier in the entry did not match the maps local
 * @param chronicleId is the channel id used to identify the canonical map or queue
 */
void writeExternalEntry(@NotNull Bytes entry,@NotNull Bytes destination,int chronicleId,long bootstrapTime);
Program: 162864
Project: 162864
Buggy source:
/** 
 * Called just after   {@link #onEntry(net.openhft.lang.io.Bytes,int)}. No-op by default.
 */
public void onAfterEntry(){
}

Fixed version (ground truth):
/** 
 * Called just after   {@link #onEntry(net.openhft.lang.io.Bytes,int,long)}. No-op by default.
 */
public void onAfterEntry(){
}
Program: 162865
Project: 162865
Buggy source:
/** 
 * Called just before   {@link #onEntry(net.openhft.lang.io.Bytes,int)}. No-op by default.
 */
public void onBeforeEntry(){
}

Fixed version (ground truth):
/** 
 * Called just before   {@link #onEntry(net.openhft.lang.io.Bytes,int,long)}. No-op by default.
 */
public void onBeforeEntry(){
}
Program: 162866
Project: 162866
Buggy source:
/** 
 * Called whenever a put() or remove() has occurred to a replicating map.
 * @param entry       the entry you will receive, this does not have to be locked, aslocking is already provided from the caller.
 * @param chronicleId only assigned when clustering
 * @return {@code false} if this entry should be ignored because the identifier of thesource node is not from one of our changes, WARNING even though we check the identifier in the ModificationIterator the entry may have been updated.
 */
public abstract boolean onEntry(final Bytes entry,final int chronicleId);

Fixed version (ground truth):
/** 
 * Called whenever a put() or remove() has occurred to a replicating map.
 * @param entry       the entry you will receive, this does not have to be locked, aslocking is already provided from the caller.
 * @param chronicleId only assigned when clustering
 * @return {@code false} if this entry should be ignored because the identifier of thesource node is not from one of our changes, WARNING even though we check the identifier in the ModificationIterator the entry may have been updated.
 */
public abstract boolean onEntry(final Bytes entry,final int chronicleId,long bootstrapTime);
Program: 162867
Project: 162867
Buggy source:
void raiseChange(long segmentIndex,long pos){
  LOG.debug("String_Node_Str",localIdentifier,segmentIndex,pos);
  changesForUpdates.set(combine(segmentIndex,pos));
  if (modificationNotifier != null)   modificationNotifier.onChange();
}

Fixed version (ground truth):
void raiseChange(long segmentIndex,long pos,long timestamp){
}