nus-yam/ex-repair huggingface dataset:
Program: 48396
Project: 48396
Buggy source:
private Record getRecordInternal(Data dataKey,boolean enableIndex){
  Record record=null;
  if (mapContainer.getStore() != null) {
    final Object value=mapContainer.getStore().load(mapService.toObject(dataKey));
    if (value != null) {
      record=mapService.createRecord(name,dataKey,value,-1);
      records.put(dataKey,record);
      if (enableIndex) {
        saveIndex(record);
      }
      updateSizeEstimator(calculateRecordSize(record));
    }
  }
  return record;
}

Fixed version (ground truth):
private Record getRecordInternal(Data dataKey,boolean enableIndex){
  Record record=null;
  if (mapContainer.getStore() != null) {
    final Object value=mapContainer.getStore().load(mapService.toObject(dataKey));
    if (value != null) {
      record=mapService.createRecord(name,dataKey,value,DEFAULT_TTL);
      records.put(dataKey,record);
      if (enableIndex) {
        saveIndex(record);
      }
      updateSizeEstimator(calculateRecordSize(record));
    }
  }
  return record;
}
Program: 48397
Project: 48397
Buggy source:
public boolean merge(Data dataKey,EntryView mergingEntry,MapMergePolicy mergePolicy){
  checkIfLoaded();
  Record record=records.get(dataKey);
  Object newValue=null;
  if (record == null) {
    newValue=mergingEntry.getValue();
    record=mapService.createRecord(name,dataKey,newValue,-1);
    mapStoreWrite(record,dataKey,newValue);
    records.put(dataKey,record);
    updateSizeEstimator(calculateRecordSize(record));
  }
 else {
    Object oldValue=record.getValue();
    EntryView existingEntry=new SimpleEntryView(mapService.toObject(record.getKey()),mapService.toObject(record.getValue()),record.getStatistics(),record.getCost(),record.getVersion());
    newValue=mergePolicy.merge(name,mergingEntry,existingEntry);
    if (newValue == null) {
      deleteRecord(dataKey);
      removeIndex(dataKey);
      mapStoreDelete(record,dataKey);
      updateSizeEstimator(-calculateRecordSize(record));
      return true;
    }
    if (mapService.compare(name,newValue,oldValue)) {
      return true;
    }
    mapStoreWrite(record,dataKey,newValue);
    updateSizeEstimator(-calculateRecordSize(record));
    recordFactory.setValue(record,newValue);
    updateSizeEstimator(calculateRecordSize(record));
  }
  saveIndex(record);
  return newValue != null;
}

Fixed version (ground truth):
public boolean merge(Data dataKey,EntryView mergingEntry,MapMergePolicy mergePolicy){
  checkIfLoaded();
  Record record=records.get(dataKey);
  Object newValue=null;
  if (record == null) {
    newValue=mergingEntry.getValue();
    record=mapService.createRecord(name,dataKey,newValue,DEFAULT_TTL);
    mapStoreWrite(record,dataKey,newValue);
    records.put(dataKey,record);
    updateSizeEstimator(calculateRecordSize(record));
  }
 else {
    Object oldValue=record.getValue();
    EntryView existingEntry=new SimpleEntryView(mapService.toObject(record.getKey()),mapService.toObject(record.getValue()),record.getStatistics(),record.getCost(),record.getVersion());
    newValue=mergePolicy.merge(name,mergingEntry,existingEntry);
    if (newValue == null) {
      deleteRecord(dataKey);
      removeIndex(dataKey);
      mapStoreDelete(record,dataKey);
      updateSizeEstimator(-calculateRecordSize(record));
      return true;
    }
    if (mapService.compare(name,newValue,oldValue)) {
      return true;
    }
    mapStoreWrite(record,dataKey,newValue);
    updateSizeEstimator(-calculateRecordSize(record));
    recordFactory.setValue(record,newValue);
    updateSizeEstimator(calculateRecordSize(record));
  }
  saveIndex(record);
  return newValue != null;
}
Program: 48398
Project: 48398
Buggy source:
public boolean containsKey(Data dataKey){
  checkIfLoaded();
  Record record=records.get(dataKey);
  if (record == null) {
    if (mapContainer.getStore() != null) {
      Object value=mapContainer.getStore().load(mapService.toObject(dataKey));
      if (value != null) {
        record=mapService.createRecord(name,dataKey,value,-1);
        records.put(dataKey,record);
        updateSizeEstimator(calculateRecordSize(record));
      }
    }
  }
  boolean contains=record != null;
  if (contains) {
    accessRecord(record);
  }
  return contains;
}

Fixed version (ground truth):
public boolean containsKey(Data dataKey){
  checkIfLoaded();
  Record record=records.get(dataKey);
  if (record == null) {
    if (mapContainer.getStore() != null) {
      Object value=mapContainer.getStore().load(mapService.toObject(dataKey));
      if (value != null) {
        record=mapService.createRecord(name,dataKey,value,DEFAULT_TTL);
        records.put(dataKey,record);
        updateSizeEstimator(calculateRecordSize(record));
      }
    }
  }
  boolean contains=record != null;
  if (contains) {
    accessRecord(record);
  }
  return contains;
}
Program: 48399
Project: 48399
Buggy source:
public Object get(Data dataKey){
  checkIfLoaded();
  Record record=records.get(dataKey);
  Object value=null;
  if (record == null) {
    if (mapContainer.getStore() != null) {
      value=mapContainer.getStore().load(mapService.toObject(dataKey));
      if (value != null) {
        record=mapService.createRecord(name,dataKey,value,-1);
        records.put(dataKey,record);
        saveIndex(record);
        updateSizeEstimator(calculateRecordSize(record));
      }
    }
  }
 else {
    accessRecord(record);
    value=record.getValue();
  }
  value=mapService.interceptGet(name,value);
  return value;
}

Fixed version (ground truth):
public Object get(Data dataKey){
  checkIfLoaded();
  Record record=records.get(dataKey);
  Object value=null;
  if (record == null) {
    if (mapContainer.getStore() != null) {
      value=mapContainer.getStore().load(mapService.toObject(dataKey));
      if (value != null) {
        record=mapService.createRecord(name,dataKey,value,DEFAULT_TTL);
        records.put(dataKey,record);
        saveIndex(record);
        updateSizeEstimator(calculateRecordSize(record));
      }
    }
  }
 else {
    accessRecord(record);
    value=record.getValue();
  }
  value=mapService.interceptGet(name,value);
  return value;
}
Program: 48400
Project: 48400
Buggy source:
public MapEntrySet getAll(Set<Data> keySet){
  checkIfLoaded();
  final MapEntrySet mapEntrySet=new MapEntrySet();
  Map<Object,Data> keyMapForLoader=null;
  if (mapContainer.getStore() != null) {
    keyMapForLoader=new HashMap<Object,Data>();
  }
  for (  Data dataKey : keySet) {
    Record record=records.get(dataKey);
    if (record == null) {
      if (mapContainer.getStore() != null) {
        keyMapForLoader.put(mapService.toObject(dataKey),dataKey);
      }
    }
 else {
      accessRecord(record);
      Object value=record.getValue();
      value=mapService.interceptGet(name,value);
      if (value != null) {
        mapEntrySet.add(new AbstractMap.SimpleImmutableEntry(dataKey,mapService.toData(value)));
      }
    }
  }
  if (mapContainer.getStore() == null || keyMapForLoader.size() == 0) {
    return mapEntrySet;
  }
  final Map<Object,Object> loadedKeys=mapContainer.getStore().loadAll(keyMapForLoader.keySet());
  for (  Map.Entry entry : loadedKeys.entrySet()) {
    final Object objectKey=entry.getKey();
    Object value=entry.getValue();
    Data dataKey=keyMapForLoader.get(objectKey);
    if (value != null) {
      Record record=mapService.createRecord(name,dataKey,value,-1);
      records.put(dataKey,record);
      saveIndex(record);
      updateSizeEstimator(calculateRecordSize(record));
    }
    value=mapService.interceptGet(name,value);
    if (value != null) {
      mapEntrySet.add(new AbstractMap.SimpleImmutableEntry(dataKey,mapService.toData(value)));
    }
  }
  return mapEntrySet;
}

Fixed version (ground truth):
public MapEntrySet getAll(Set<Data> keySet){
  checkIfLoaded();
  final MapEntrySet mapEntrySet=new MapEntrySet();
  Map<Object,Data> keyMapForLoader=null;
  if (mapContainer.getStore() != null) {
    keyMapForLoader=new HashMap<Object,Data>();
  }
  for (  Data dataKey : keySet) {
    Record record=records.get(dataKey);
    if (record == null) {
      if (mapContainer.getStore() != null) {
        keyMapForLoader.put(mapService.toObject(dataKey),dataKey);
      }
    }
 else {
      accessRecord(record);
      Object value=record.getValue();
      value=mapService.interceptGet(name,value);
      if (value != null) {
        mapEntrySet.add(new AbstractMap.SimpleImmutableEntry(dataKey,mapService.toData(value)));
      }
    }
  }
  if (mapContainer.getStore() == null || keyMapForLoader.size() == 0) {
    return mapEntrySet;
  }
  final Map<Object,Object> loadedKeys=mapContainer.getStore().loadAll(keyMapForLoader.keySet());
  for (  Map.Entry entry : loadedKeys.entrySet()) {
    final Object objectKey=entry.getKey();
    Object value=entry.getValue();
    Data dataKey=keyMapForLoader.get(objectKey);
    if (value != null) {
      Record record=mapService.createRecord(name,dataKey,value,DEFAULT_TTL);
      records.put(dataKey,record);
      saveIndex(record);
      updateSizeEstimator(calculateRecordSize(record));
    }
    value=mapService.interceptGet(name,value);
    if (value != null) {
      mapEntrySet.add(new AbstractMap.SimpleImmutableEntry(dataKey,mapService.toData(value)));
    }
  }
  return mapEntrySet;
}
Program: 48401
Project: 48401
Buggy source:
public Object putIfAbsent(Data dataKey,Object value,long ttl){
  checkIfLoaded();
  Record record=records.get(dataKey);
  Object oldValue=null;
  if (record == null) {
    if (mapContainer.getStore() != null) {
      oldValue=mapContainer.getStore().load(mapService.toObject(dataKey));
      if (oldValue != null) {
        record=mapService.createRecord(name,dataKey,oldValue,-1);
        records.put(dataKey,record);
        updateSizeEstimator(calculateRecordSize(record));
      }
    }
  }
 else {
    accessRecord(record);
    oldValue=record.getValue();
  }
  if (oldValue == null) {
    value=mapService.interceptPut(name,null,value);
    record=mapService.createRecord(name,dataKey,value,ttl);
    mapStoreWrite(record,dataKey,value);
    records.put(dataKey,record);
    updateSizeEstimator(calculateRecordSize(record));
    updateTtl(record,ttl);
  }
  saveIndex(record);
  return oldValue;
}

Fixed version (ground truth):
public Object putIfAbsent(Data dataKey,Object value,long ttl){
  checkIfLoaded();
  Record record=records.get(dataKey);
  Object oldValue=null;
  if (record == null) {
    if (mapContainer.getStore() != null) {
      oldValue=mapContainer.getStore().load(mapService.toObject(dataKey));
      if (oldValue != null) {
        record=mapService.createRecord(name,dataKey,oldValue,DEFAULT_TTL);
        records.put(dataKey,record);
        updateSizeEstimator(calculateRecordSize(record));
      }
    }
  }
 else {
    accessRecord(record);
    oldValue=record.getValue();
  }
  if (oldValue == null) {
    value=mapService.interceptPut(name,null,value);
    record=mapService.createRecord(name,dataKey,value,ttl);
    mapStoreWrite(record,dataKey,value);
    records.put(dataKey,record);
    updateSizeEstimator(calculateRecordSize(record));
    updateTtl(record,ttl);
  }
  saveIndex(record);
  return oldValue;
}
Program: 48402
Project: 48402
Buggy source:
public void run(){
  Map.Entry<Data,Object> mapEntry=recordStore.getMapEntryForBackup(dataKey);
  if (mapEntry.getValue() != null) {
    Map.Entry<Object,Object> entry=new AbstractMap.SimpleEntry<Object,Object>(mapService.toObject(dataKey),mapService.toObject(mapEntry.getValue()));
    entryProcessor.processBackup(entry);
    if (entry.getValue() == null) {
      recordStore.remove(dataKey);
    }
 else {
      recordStore.put(new AbstractMap.SimpleImmutableEntry<Data,Object>(dataKey,entry.getValue()));
    }
  }
}

Fixed version (ground truth):
public void run(){
  Map.Entry<Data,Object> mapEntry=recordStore.getMapEntryForBackup(dataKey);
  if (mapEntry.getValue() != null) {
    Map.Entry<Object,Object> entry=new AbstractMap.SimpleEntry<Object,Object>(mapService.toObject(dataKey),mapService.toObject(mapEntry.getValue()));
    entryProcessor.processBackup(entry);
    if (entry.getValue() == null) {
      recordStore.remove(dataKey);
    }
 else {
      recordStore.putBackup(dataKey,entry.getValue());
    }
  }
}
Program: 48403
Project: 48403
Buggy source:
public void run(){
  Map.Entry entry;
  RecordStore recordStore=mapService.getRecordStore(getPartitionId(),name);
  Map<Data,Record> records=recordStore.getReadonlyRecordMap();
  for (  Map.Entry<Data,Record> recordEntry : records.entrySet()) {
    Data dataKey=recordEntry.getKey();
    Record record=recordEntry.getValue();
    entry=new AbstractMap.SimpleEntry(mapService.toObject(record.getKey()),mapService.toObject(record.getValue()));
    entryProcessor.processBackup(entry);
    if (entry.getValue() == null) {
      recordStore.remove(dataKey);
    }
 else {
      recordStore.put(new AbstractMap.SimpleImmutableEntry<Data,Object>(dataKey,entry.getValue()));
    }
  }
}

Fixed version (ground truth):
public void run(){
  Map.Entry entry;
  RecordStore recordStore=mapService.getRecordStore(getPartitionId(),name);
  Map<Data,Record> records=recordStore.getReadonlyRecordMap();
  for (  Map.Entry<Data,Record> recordEntry : records.entrySet()) {
    Data dataKey=recordEntry.getKey();
    Record record=recordEntry.getValue();
    entry=new AbstractMap.SimpleEntry(mapService.toObject(record.getKey()),mapService.toObject(record.getValue()));
    entryProcessor.processBackup(entry);
    if (entry.getValue() == null) {
      recordStore.remove(dataKey);
    }
 else {
      recordStore.putBackup(dataKey,entry.getValue());
    }
  }
}
Program: 48404
Project: 48404
Buggy source:
public void run(){
  Record record=recordStore.getRecord(dataKey);
  if (record == null) {
    record=mapService.createRecord(name,dataKey,dataValue,ttl,false);
    updateSizeEstimator(calculateRecordSize(record));
    recordStore.putRecord(dataKey,record);
  }
 else {
    updateSizeEstimator(-calculateRecordSize(record));
    mapContainer.getRecordFactory().setValue(record,dataValue);
    updateSizeEstimator(calculateRecordSize(record));
  }
  if (unlockKey) {
    recordStore.forceUnlock(dataKey);
  }
}

Fixed version (ground truth):
public void run(){
  recordStore.putBackup(dataKey,dataValue,ttl,false);
  if (unlockKey) {
    recordStore.forceUnlock(dataKey);
  }
}
Program: 48405
Project: 48405
Buggy source:
public Object getAttribute(final String name){
  IMap<String,Object> clusterMap=getClusterMap();
  if (deferredWrite) {
    LocalCacheEntry cacheEntry=localCache.get(name);
    if (cacheEntry == null || cacheEntry.reload) {
      Object value=clusterMap.get(buildAttributeName(name));
      if (value == null) {
        cacheEntry=NULL_ENTRY;
      }
 else {
        cacheEntry=new LocalCacheEntry();
        cacheEntry.value=value;
        cacheEntry.reload=false;
      }
      localCache.put(name,NULL_ENTRY);
    }
    return cacheEntry != NULL_ENTRY ? cacheEntry.value : null;
  }
  return clusterMap.get(buildAttributeName(name));
}

Fixed version (ground truth):
public Object getAttribute(final String name){
  IMap<String,Object> clusterMap=getClusterMap();
  if (deferredWrite) {
    LocalCacheEntry cacheEntry=localCache.get(name);
    if (cacheEntry == null || cacheEntry.reload) {
      Object value=clusterMap.get(buildAttributeName(name));
      if (value == null) {
        cacheEntry=NULL_ENTRY;
      }
 else {
        cacheEntry=new LocalCacheEntry();
        cacheEntry.value=value;
        cacheEntry.reload=false;
      }
      localCache.put(name,cacheEntry);
    }
    return cacheEntry != NULL_ENTRY ? cacheEntry.value : null;
  }
  return clusterMap.get(buildAttributeName(name));
}
Program: 48406
Project: 48406
Buggy source:
public void run(){
  oldValue=recordStore.getMapEntry(dataKey).getValue();
  final Object valueBeforeProcess=mapService.toObject(oldValue);
  final MapEntrySimple entry=new MapEntrySimple(mapService.toObject(dataKey),valueBeforeProcess);
  response=mapService.toData(entryProcessor.process(entry));
  final Object valueAfterProcess=entry.getValue();
  if (oldValue == null && valueAfterProcess == null) {
    eventType=__NO_NEED_TO_FIRE_EVENT;
  }
 else   if (valueAfterProcess == null) {
    recordStore.remove(dataKey);
    eventType=EntryEventType.REMOVED;
  }
 else {
    if (oldValue == null) {
      eventType=EntryEventType.ADDED;
    }
 else     if (!entry.isModified()) {
      eventType=__NO_NEED_TO_FIRE_EVENT;
    }
 else {
      eventType=EntryEventType.UPDATED;
      invalidateLocalNearCache(dataKey);
    }
    if (eventType != __NO_NEED_TO_FIRE_EVENT) {
      dataValue=mapService.toData(entry.getValue());
      recordStore.put(new AbstractMap.SimpleImmutableEntry<Data,Object>(dataKey,dataValue));
    }
  }
}

Fixed version (ground truth):
public void run(){
  oldValue=recordStore.getMapEntry(dataKey).getValue();
  final Object valueBeforeProcess=mapService.toObject(oldValue);
  final MapEntrySimple entry=new MapEntrySimple(mapService.toObject(dataKey),valueBeforeProcess);
  response=mapService.toData(entryProcessor.process(entry));
  final Object valueAfterProcess=entry.getValue();
  if (oldValue == null && valueAfterProcess == null) {
    eventType=__NO_NEED_TO_FIRE_EVENT;
  }
 else   if (valueAfterProcess == null) {
    recordStore.remove(dataKey);
    eventType=EntryEventType.REMOVED;
  }
 else {
    if (oldValue == null) {
      eventType=EntryEventType.ADDED;
    }
 else     if (!entry.isModified()) {
      eventType=__NO_NEED_TO_FIRE_EVENT;
    }
 else {
      eventType=EntryEventType.UPDATED;
    }
    if (eventType != __NO_NEED_TO_FIRE_EVENT) {
      dataValue=mapService.toData(entry.getValue());
      recordStore.put(new AbstractMap.SimpleImmutableEntry<Data,Object>(dataKey,dataValue));
    }
  }
}
Program: 48407
Project: 48407
Buggy source:
@Before public void setUp() throws Exception {
  Config config=new XmlConfigBuilder().build();
  MapConfig mapConfig=config.getMapConfig(mapName);
  NearCacheConfig nearCacheConfig=new NearCacheConfig();
  nearCacheConfig.setEvictionPolicy("String_Node_Str");
  nearCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
  nearCacheConfig.setCacheLocalEntries(true);
  mapConfig.setNearCacheConfig(nearCacheConfig);
  final TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(instanceCount);
  hcInstance=factory.newHazelcastInstance(config);
  hcInstance2=factory.newHazelcastInstance(config);
}

Fixed version (ground truth):
@Before public void setUp() throws Exception {
  Config config=new Config();
  MapConfig mapConfig=config.getMapConfig(mapName);
  NearCacheConfig nearCacheConfig=new NearCacheConfig();
  nearCacheConfig.setEvictionPolicy("String_Node_Str");
  nearCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
  nearCacheConfig.setCacheLocalEntries(true);
  mapConfig.setNearCacheConfig(nearCacheConfig);
  final TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(instanceCount);
  hcInstance=factory.newHazelcastInstance(config);
  hcInstance2=factory.newHazelcastInstance(config);
}
Program: 48408
Project: 48408
Buggy source:
public ICompletableFuture executeOnKeyInternal(Data key,EntryProcessor entryProcessor,ExecutionCallback callback){
  final NodeEngine nodeEngine=getNodeEngine();
  int partitionId=nodeEngine.getPartitionService().getPartitionId(key);
  EntryOperation operation=new EntryOperation(name,key,entryProcessor);
  operation.setThreadId(ThreadUtil.getThreadId());
  try {
    if (callback == null) {
      return nodeEngine.getOperationService().invokeOnPartition(SERVICE_NAME,operation,partitionId);
    }
 else {
      return nodeEngine.getOperationService().createInvocationBuilder(SERVICE_NAME,operation,partitionId).setCallback(new MapExecutionCallbackAdapter(callback)).invoke();
    }
  }
 catch (  Throwable t) {
    throw ExceptionUtil.rethrow(t);
  }
}

Fixed version (ground truth):
public ICompletableFuture executeOnKeyInternal(Data key,EntryProcessor entryProcessor,ExecutionCallback callback){
  final NodeEngine nodeEngine=getNodeEngine();
  int partitionId=nodeEngine.getPartitionService().getPartitionId(key);
  EntryOperation operation=new EntryOperation(name,key,entryProcessor);
  operation.setThreadId(ThreadUtil.getThreadId());
  try {
    if (callback == null) {
      return nodeEngine.getOperationService().invokeOnPartition(SERVICE_NAME,operation,partitionId);
    }
 else {
      ICompletableFuture future=nodeEngine.getOperationService().createInvocationBuilder(SERVICE_NAME,operation,partitionId).setCallback(new MapExecutionCallbackAdapter(callback)).invoke();
      invalidateLocalNearCache(key);
      return future;
    }
  }
 catch (  Throwable t) {
    throw ExceptionUtil.rethrow(t);
  }
}
Program: 48409
Project: 48409
Buggy source:
private void invalidateLocalNearCache(Data key){
  final MapConfig config=mapConfig;
  final boolean nearCacheEnabled=config.isNearCacheEnabled();
  if (!nearCacheEnabled) {
    return;
  }
  final boolean cacheLocalEntries=config.getNearCacheConfig().isCacheLocalEntries();
  if (!cacheLocalEntries) {
    return;
  }
  final MapService mapService=getService();
  mapService.invalidateNearCache(name,key);
}

Fixed version (ground truth):
private void invalidateLocalNearCache(Set<Data> keys){
  if (keys == null || keys.isEmpty()) {
    return;
  }
  getService().invalidateLocalNearCache(name,keys);
}
Program: 48410
Project: 48410
Buggy source:
public Map executeOnEntries(EntryProcessor entryProcessor,Predicate predicate){
  Map result=new HashMap();
  try {
    NodeEngine nodeEngine=getNodeEngine();
    Map<Integer,Object> results=nodeEngine.getOperationService().invokeOnAllPartitions(SERVICE_NAME,new PartitionWideEntryWithPredicateOperationFactory(name,entryProcessor,predicate));
    for (    Object o : results.values()) {
      if (o != null) {
        final MapService service=getService();
        final MapEntrySet mapEntrySet=(MapEntrySet)o;
        for (        Entry<Data,Data> entry : mapEntrySet.getEntrySet()) {
          result.put(service.toObject(entry.getKey()),service.toObject(entry.getValue()));
        }
      }
    }
  }
 catch (  Throwable t) {
    throw ExceptionUtil.rethrow(t);
  }
  return result;
}

Fixed version (ground truth):
public Map executeOnEntries(EntryProcessor entryProcessor,Predicate predicate){
  Map result=new HashMap();
  try {
    NodeEngine nodeEngine=getNodeEngine();
    Map<Integer,Object> results=nodeEngine.getOperationService().invokeOnAllPartitions(SERVICE_NAME,new PartitionWideEntryWithPredicateOperationFactory(name,entryProcessor,predicate));
    for (    Object o : results.values()) {
      if (o != null) {
        final MapService service=getService();
        final MapEntrySet mapEntrySet=(MapEntrySet)o;
        for (        Entry<Data,Data> entry : mapEntrySet.getEntrySet()) {
          final Data key=entry.getKey();
          result.put(service.toObject(key),service.toObject(entry.getValue()));
          invalidateLocalNearCache(key);
        }
      }
    }
  }
 catch (  Throwable t) {
    throw ExceptionUtil.rethrow(t);
  }
  return result;
}
Program: 48411
Project: 48411
Buggy source:
public Map executeOnKeysInternal(Set<Data> keys,EntryProcessor entryProcessor){
  Map result=new HashMap();
  final NodeEngine nodeEngine=getNodeEngine();
  final Collection<Integer> partitionsForKeys=getPartitionsForKeys(keys);
  try {
    MultipleEntryOperationFactory operationFactory=new MultipleEntryOperationFactory(name,keys,entryProcessor);
    Map<Integer,Object> results=nodeEngine.getOperationService().invokeOnPartitions(SERVICE_NAME,operationFactory,partitionsForKeys);
    for (    Object o : results.values()) {
      if (o != null) {
        final MapService service=getService();
        final MapEntrySet mapEntrySet=(MapEntrySet)o;
        for (        Entry<Data,Data> entry : mapEntrySet.getEntrySet()) {
          result.put(service.toObject(entry.getKey()),service.toObject(entry.getValue()));
        }
      }
    }
  }
 catch (  Throwable t) {
    throw ExceptionUtil.rethrow(t);
  }
  return result;
}

Fixed version (ground truth):
public Map executeOnKeysInternal(Set<Data> keys,EntryProcessor entryProcessor){
  Map result=new HashMap();
  final NodeEngine nodeEngine=getNodeEngine();
  final Collection<Integer> partitionsForKeys=getPartitionsForKeys(keys);
  try {
    MultipleEntryOperationFactory operationFactory=new MultipleEntryOperationFactory(name,keys,entryProcessor);
    Map<Integer,Object> results=nodeEngine.getOperationService().invokeOnPartitions(SERVICE_NAME,operationFactory,partitionsForKeys);
    for (    Object o : results.values()) {
      if (o != null) {
        final MapService service=getService();
        final MapEntrySet mapEntrySet=(MapEntrySet)o;
        for (        Entry<Data,Data> entry : mapEntrySet.getEntrySet()) {
          result.put(service.toObject(entry.getKey()),service.toObject(entry.getValue()));
        }
      }
    }
    invalidateLocalNearCache(keys);
  }
 catch (  Throwable t) {
    throw ExceptionUtil.rethrow(t);
  }
  return result;
}
Program: 48412
Project: 48412
Buggy source:
@Override public Object process(Map.Entry<String,Text> entry){
  Text text=entry.getValue();
  text.setContent("String_Node_Str");
  entry.setValue(text);
  return "String_Node_Str";
}

Fixed version (ground truth):
@Override public Object process(Map.Entry<String,String> entry){
  entry.setValue("String_Node_Str");
  return "String_Node_Str";
}
Program: 48413
Project: 48413
Buggy source:
@Test public void testExecuteOnKeys(){
  final IMap<String,Text> map=hcInstance.getMap(mapName);
  for (int k=0; k < numIterations; k++) {
    String key="String_Node_Str" + String.valueOf(k);
    Text value0=new Text("String_Node_Str" + k);
    map.put(key,value0);
    map.get(key);
    Text value1=map.get(key);
    Text value2=map.get(key);
    assertTrue("String_Node_Str" + k + "String_Node_Str"+ value1+ "String_Node_Str"+ value2,value1 == value2);
    final HashSet<String> keys=new HashSet<String>();
    keys.add(key);
    map.executeOnKeys(keys,new ReadingEntryProcessor());
    map.executeOnKeys(keys,new WritingEntryProcessor());
    Text value4=map.get(key);
    assertFalse("String_Node_Str" + k + "String_Node_Str",value1 == value4);
  }
}

Fixed version (ground truth):
@Test public void testExecuteOnKeys(){
  final IMap<String,String> map=hcInstance.getMap(mapName);
  for (int k=0; k < numIterations; k++) {
    String key="String_Node_Str" + String.valueOf(k);
    final String expectedNull=map.get(key);
    assertNull(expectedNull);
    final HashSet<String> keys=new HashSet<String>();
    keys.add(key);
    final Object o=map.executeOnKeys(keys,new WritingEntryProcessor());
    final Map<String,String> result=(Map)o;
    for (    Map.Entry<String,String> e : result.entrySet()) {
      final String newValue=e.getValue();
      final String cachedValue=map.get(e.getKey());
      assertEquals(newValue,cachedValue);
    }
  }
}
Program: 48414
Project: 48414
Buggy source:
@After public void tearDown() throws Exception {
  hcInstance.getLifecycleService().shutdown();
}

Fixed version (ground truth):
@After public void tearDown() throws Exception {
  hcInstance.getLifecycleService().shutdown();
  hcInstance2.getLifecycleService().shutdown();
}
Program: 48415
Project: 48415
Buggy source:
@Test public void testExecuteOnKey(){
  final IMap<String,Text> map=hcInstance.getMap(mapName);
  for (int k=0; k < numIterations; k++) {
    String key="String_Node_Str" + String.valueOf(k);
    Text value0=new Text("String_Node_Str" + k);
    map.put(key,value0);
    map.get(key);
    Text value1=map.get(key);
    Text value2=map.get(key);
    assertTrue("String_Node_Str" + k + "String_Node_Str"+ value1+ "String_Node_Str"+ value2,value1 == value2);
    final HashSet<String> strings=new HashSet<String>();
    strings.add(key);
    map.executeOnKey(key,new ReadingEntryProcessor());
    map.executeOnKey(key,new WritingEntryProcessor());
    Text value4=map.get(key);
    assertFalse("String_Node_Str" + k + "String_Node_Str",value1 == value4);
  }
}

Fixed version (ground truth):
@Test public void testExecuteOnKey(){
  final IMap<String,String> map=hcInstance.getMap(mapName);
  for (int k=0; k < numIterations; k++) {
    String key="String_Node_Str" + String.valueOf(k);
    final String expectedNull=map.get(key);
    assertNull(expectedNull);
    final Object o=map.executeOnKey(key,new WritingEntryProcessor());
    final String newValue=(String)o;
    String value2=map.get(key);
    assertEquals(newValue,value2);
  }
}
Program: 48416
Project: 48416
Buggy source:
@Before public void setUp() throws Exception {
  Config config=new XmlConfigBuilder().build();
  MapConfig mapConfig=config.getMapConfig(mapName);
  NearCacheConfig nearCacheConfig=new NearCacheConfig();
  nearCacheConfig.setEvictionPolicy("String_Node_Str");
  nearCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
  nearCacheConfig.setCacheLocalEntries(true);
  mapConfig.setNearCacheConfig(nearCacheConfig);
  final TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(1);
  hcInstance=factory.newHazelcastInstance(config);
}

Fixed version (ground truth):
@Before public void setUp() throws Exception {
  Config config=new XmlConfigBuilder().build();
  MapConfig mapConfig=config.getMapConfig(mapName);
  NearCacheConfig nearCacheConfig=new NearCacheConfig();
  nearCacheConfig.setEvictionPolicy("String_Node_Str");
  nearCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
  nearCacheConfig.setCacheLocalEntries(true);
  mapConfig.setNearCacheConfig(nearCacheConfig);
  final TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(instanceCount);
  hcInstance=factory.newHazelcastInstance(config);
  hcInstance2=factory.newHazelcastInstance(config);
}
Program: 48417
Project: 48417
Buggy source:
private PortableContext getPortableContext(int factoryId){
  final PortableContext ctx=portableContextMap.get(factoryId);
  if (ctx == null) {
    throw new HazelcastSerializationException("String_Node_Str" + factoryId);
  }
  return ctx;
}

Fixed version (ground truth):
private PortableContext getPortableContext(int factoryId){
  return ConcurrencyUtil.getOrPutIfAbsent(portableContextMap,factoryId,constructorFunction);
}
Program: 48418
Project: 48418
Buggy source:
SerializationContextImpl(SerializationServiceImpl serializationService,Collection<Integer> portableFactories,int version){
  this.serializationService=serializationService;
  this.version=version;
  final Map<Integer,PortableContext> portableMap=new HashMap<Integer,PortableContext>();
  for (  int factoryId : portableFactories) {
    portableMap.put(factoryId,new PortableContext());
  }
  portableContextMap=portableMap;
}

Fixed version (ground truth):
SerializationContextImpl(SerializationServiceImpl serializationService,Collection<Integer> portableFactories,int version){
  this.serializationService=serializationService;
  this.version=version;
  for (  int factoryId : portableFactories) {
    portableContextMap.put(factoryId,new PortableContext());
  }
}
Program: 48419
Project: 48419
Buggy source:
private PortableContext getPortableContext(int factoryId){
  final PortableContext ctx=portableContextMap.get(factoryId);
  if (ctx == null) {
    throw new HazelcastSerializationException("String_Node_Str" + factoryId);
  }
  return ctx;
}

Fixed version (ground truth):
private PortableContext getPortableContext(int factoryId){
  return ConcurrencyUtil.getOrPutIfAbsent(portableContextMap,factoryId,constructorFunction);
}
Program: 48420
Project: 48420
Buggy source:
SerializationContextImpl(SerializationServiceImpl serializationService,Collection<Integer> portableFactories,int version){
  this.serializationService=serializationService;
  this.version=version;
  final Map<Integer,PortableContext> portableMap=new HashMap<Integer,PortableContext>();
  for (  int factoryId : portableFactories) {
    portableMap.put(factoryId,new PortableContext());
  }
  portableContextMap=portableMap;
}

Fixed version (ground truth):
SerializationContextImpl(SerializationServiceImpl serializationService,Collection<Integer> portableFactories,int version){
  this.serializationService=serializationService;
  this.version=version;
  for (  int factoryId : portableFactories) {
    portableContextMap.put(factoryId,new PortableContext());
  }
}
Program: 48421
Project: 48421
Buggy source:
@Test(timeout=1000 * 60) @Category(ProblematicTest.class) public void testQueryDuringAndAfterMigrationWithIndex() throws Exception {
  Config cfg=new Config();
  TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(4);
  HazelcastInstance h1=nodeFactory.newHazelcastInstance(cfg);
  IMap imap=h1.getMap("String_Node_Str");
  imap.addIndex("String_Node_Str",false);
  imap.addIndex("String_Node_Str",true);
  imap.addIndex("String_Node_Str",false);
  int size=50000;
  for (int i=0; i < size; i++) {
    imap.put(String.valueOf(i),new Employee("String_Node_Str" + i,i % 60,((i & 1) == 1),(double)i));
  }
  assertEquals(size,imap.size());
  HazelcastInstance h2=nodeFactory.newHazelcastInstance(cfg);
  HazelcastInstance h3=nodeFactory.newHazelcastInstance(cfg);
  HazelcastInstance h4=nodeFactory.newHazelcastInstance(cfg);
  long startNow=Clock.currentTimeMillis();
  while ((Clock.currentTimeMillis() - startNow) < 10000) {
    Collection<Employee> values=imap.values(new SqlPredicate("String_Node_Str"));
    for (    Employee employee : values) {
      assertTrue(employee.isActive());
    }
    assertEquals(556,values.size());
  }
}

Fixed version (ground truth):
@Test public void testQueryDuringAndAfterMigrationWithIndex() throws Exception {
  Config cfg=new Config();
  TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(4);
  final HazelcastInstance h1=nodeFactory.newHazelcastInstance(cfg);
  IMap imap=h1.getMap("String_Node_Str");
  imap.addIndex("String_Node_Str",false);
  imap.addIndex("String_Node_Str",true);
  imap.addIndex("String_Node_Str",false);
  int size=500;
  for (int i=0; i < size; i++) {
    imap.put(String.valueOf(i),new Employee("String_Node_Str" + i,i % 60,((i & 1) == 1),(double)i));
  }
  assertEquals(size,imap.size());
  HazelcastInstance h2=nodeFactory.newHazelcastInstance(cfg);
  HazelcastInstance h3=nodeFactory.newHazelcastInstance(cfg);
  HazelcastInstance h4=nodeFactory.newHazelcastInstance(cfg);
  final IMap employees=h1.getMap("String_Node_Str");
  assertTrueAllTheTime(new AssertTask(){
    @Override public void run() throws Exception {
      Collection<Employee> values=employees.values(new SqlPredicate("String_Node_Str"));
      for (      Employee employee : values) {
        assertTrue(employee.isActive());
      }
      assertEquals(6,values.size());
    }
  }
,3);
}
Program: 48423
Project: 48423
Buggy source:
@Test(timeout=1000 * 60) @Category(ProblematicTest.class) public void testQueryWithIndexesWhileMigrating() throws Exception {
  TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(4);
  HazelcastInstance h1=nodeFactory.newHazelcastInstance();
  IMap imap=h1.getMap("String_Node_Str");
  imap.addIndex("String_Node_Str",false);
  imap.addIndex("String_Node_Str",true);
  imap.addIndex("String_Node_Str",false);
  for (int i=0; i < 500; i++) {
    Map temp=new HashMap(100);
    for (int j=0; j < 100; j++) {
      String key=String.valueOf((i * 100000) + j);
      temp.put(key,new Employee("String_Node_Str" + key,i % 60,((i & 1) == 1),(double)i));
    }
    imap.putAll(temp);
  }
  assertEquals(50000,imap.size());
  Set<Map.Entry> entries=imap.entrySet(new SqlPredicate("String_Node_Str"));
  assertEquals(6400,entries.size());
  HazelcastInstance h2=nodeFactory.newHazelcastInstance();
  HazelcastInstance h3=nodeFactory.newHazelcastInstance();
  HazelcastInstance h4=nodeFactory.newHazelcastInstance();
  long startNow=Clock.currentTimeMillis();
  while ((Clock.currentTimeMillis() - startNow) < 10000) {
    entries=imap.entrySet(new SqlPredicate("String_Node_Str"));
    assertEquals(6400,entries.size());
  }
}

Fixed version (ground truth):
@Test public void testQueryWithIndexesWhileMigrating() throws Exception {
  TestHazelcastInstanceFactory nodeFactory=createHazelcastInstanceFactory(4);
  HazelcastInstance h1=nodeFactory.newHazelcastInstance();
  IMap imap=h1.getMap("String_Node_Str");
  imap.addIndex("String_Node_Str",false);
  imap.addIndex("String_Node_Str",true);
  imap.addIndex("String_Node_Str",false);
  for (int i=0; i < 50; i++) {
    Map temp=new HashMap(10);
    for (int j=0; j < 10; j++) {
      String key=String.valueOf((i * 100000) + j);
      temp.put(key,new Employee("String_Node_Str" + key,i % 60,((i & 1) == 1),(double)i));
    }
    imap.putAll(temp);
  }
  assertEquals(500,imap.size());
  Set<Map.Entry> entries=imap.entrySet(new SqlPredicate("String_Node_Str"));
  assertEquals(30,entries.size());
  HazelcastInstance h2=nodeFactory.newHazelcastInstance();
  HazelcastInstance h3=nodeFactory.newHazelcastInstance();
  HazelcastInstance h4=nodeFactory.newHazelcastInstance();
  long startNow=Clock.currentTimeMillis();
  while ((Clock.currentTimeMillis() - startNow) < 10000) {
    entries=imap.entrySet(new SqlPredicate("String_Node_Str"));
    assertEquals(30,entries.size());
  }
}
Program: 48424
Project: 48424
Buggy source:
private PortableContext getPortableContext(int factoryId){
  final PortableContext ctx=portableContextMap.get(factoryId);
  if (ctx == null) {
    throw new HazelcastSerializationException("String_Node_Str" + factoryId);
  }
  return ctx;
}

Fixed version (ground truth):
private PortableContext getPortableContext(int factoryId){
  return ConcurrencyUtil.getOrPutIfAbsent(portableContextMap,factoryId,constructorFunction);
}
Program: 48425
Project: 48425
Buggy source:
SerializationContextImpl(SerializationServiceImpl serializationService,Collection<Integer> portableFactories,int version){
  this.serializationService=serializationService;
  this.version=version;
  final Map<Integer,PortableContext> portableMap=new HashMap<Integer,PortableContext>();
  for (  int factoryId : portableFactories) {
    portableMap.put(factoryId,new PortableContext());
  }
  portableContextMap=portableMap;
}

Fixed version (ground truth):
SerializationContextImpl(SerializationServiceImpl serializationService,Collection<Integer> portableFactories,int version){
  this.serializationService=serializationService;
  this.version=version;
  for (  int factoryId : portableFactories) {
    portableContextMap.put(factoryId,new PortableContext());
  }
}
Program: 48426
Project: 48426
Buggy source:
public void run(){
  oldValue=recordStore.getMapEntry(dataKey).getValue();
  final Object valueBeforeProcess=mapService.toObject(oldValue);
  final MapEntrySimple entry=new MapEntrySimple(mapService.toObject(dataKey),valueBeforeProcess);
  response=mapService.toData(entryProcessor.process(entry));
  final Object valueAfterProcess=entry.getValue();
  if (oldValue == null && valueAfterProcess == null) {
    eventType=__NO_NEED_TO_FIRE_EVENT;
  }
 else   if (valueAfterProcess == null) {
    recordStore.remove(dataKey);
    eventType=EntryEventType.REMOVED;
  }
 else {
    if (oldValue == null) {
      eventType=EntryEventType.ADDED;
    }
 else     if (!entry.isModified()) {
      eventType=__NO_NEED_TO_FIRE_EVENT;
    }
 else {
      eventType=EntryEventType.UPDATED;
    }
    if (eventType != __NO_NEED_TO_FIRE_EVENT) {
      dataValue=mapService.toData(entry.getValue());
      recordStore.put(new AbstractMap.SimpleImmutableEntry<Data,Object>(dataKey,dataValue));
    }
  }
}

Fixed version (ground truth):
public void run(){
  oldValue=recordStore.getMapEntry(dataKey).getValue();
  final Object valueBeforeProcess=mapService.toObject(oldValue);
  final MapEntrySimple entry=new MapEntrySimple(mapService.toObject(dataKey),valueBeforeProcess);
  response=mapService.toData(entryProcessor.process(entry));
  final Object valueAfterProcess=entry.getValue();
  if (oldValue == null && valueAfterProcess == null) {
    eventType=__NO_NEED_TO_FIRE_EVENT;
  }
 else   if (valueAfterProcess == null) {
    recordStore.remove(dataKey);
    eventType=EntryEventType.REMOVED;
  }
 else {
    if (oldValue == null) {
      eventType=EntryEventType.ADDED;
    }
 else     if (!entry.isModified()) {
      eventType=__NO_NEED_TO_FIRE_EVENT;
    }
 else {
      eventType=EntryEventType.UPDATED;
      invalidateLocalNearCache(dataKey);
    }
    if (eventType != __NO_NEED_TO_FIRE_EVENT) {
      dataValue=mapService.toData(entry.getValue());
      recordStore.put(new AbstractMap.SimpleImmutableEntry<Data,Object>(dataKey,dataValue));
    }
  }
}
Program: 48431
Project: 48431
Buggy source:
public void run(){
  Map.Entry<Data,Object> mapEntry=recordStore.getMapEntryForBackup(dataKey);
  if (mapEntry.getValue() != null) {
    Map.Entry<Object,Object> entry=new AbstractMap.SimpleEntry<Object,Object>(mapService.toObject(dataKey),mapService.toObject(mapEntry.getValue()));
    entryProcessor.processBackup(entry);
    if (entry.getValue() == null) {
      recordStore.remove(dataKey);
    }
 else {
      recordStore.put(new AbstractMap.SimpleImmutableEntry<Data,Object>(dataKey,entry.getValue()));
    }
  }
}

Fixed version (ground truth):
public void run(){
  Map.Entry<Data,Object> mapEntry=recordStore.getMapEntryForBackup(dataKey);
  if (mapEntry.getValue() != null) {
    Map.Entry<Object,Object> entry=new AbstractMap.SimpleEntry<Object,Object>(mapService.toObject(dataKey),mapService.toObject(mapEntry.getValue()));
    entryProcessor.processBackup(entry);
    if (entry.getValue() == null) {
      recordStore.remove(dataKey);
    }
 else {
      recordStore.putBackup(new AbstractMap.SimpleImmutableEntry<Data,Object>(dataKey,entry.getValue()));
    }
  }
}
Program: 48432
Project: 48432
Buggy source:
@Override public void run() throws Exception {
  final InternalPartitionService partitionService=getNodeEngine().getPartitionService();
  final RecordStore recordStore=mapService.getRecordStore(getPartitionId(),name);
  MapEntrySimple entry;
  for (  Data key : keys) {
    if (partitionService.getPartitionId(key) != getPartitionId())     continue;
    Object objectKey=mapService.toObject(key);
    final Map.Entry<Data,Object> mapEntry=recordStore.getMapEntry(key);
    final Object valueBeforeProcess=mapService.toObject(mapEntry.getValue());
    entry=new MapEntrySimple(objectKey,valueBeforeProcess);
    backupProcessor.processBackup(entry);
    if (entry.getValue() == null) {
      recordStore.remove(key);
    }
 else {
      recordStore.put(new AbstractMap.SimpleImmutableEntry<Data,Object>(key,entry.getValue()));
    }
  }
}

Fixed version (ground truth):
@Override public void run() throws Exception {
  final InternalPartitionService partitionService=getNodeEngine().getPartitionService();
  final RecordStore recordStore=mapService.getRecordStore(getPartitionId(),name);
  MapEntrySimple entry;
  for (  Data key : keys) {
    if (partitionService.getPartitionId(key) != getPartitionId())     continue;
    Object objectKey=mapService.toObject(key);
    final Map.Entry<Data,Object> mapEntry=recordStore.getMapEntry(key);
    final Object valueBeforeProcess=mapService.toObject(mapEntry.getValue());
    entry=new MapEntrySimple(objectKey,valueBeforeProcess);
    backupProcessor.processBackup(entry);
    if (entry.getValue() == null) {
      recordStore.remove(key);
    }
 else {
      recordStore.putBackup(new AbstractMap.SimpleImmutableEntry<Data,Object>(key,entry.getValue()));
    }
  }
}
Program: 48433
Project: 48433
Buggy source:
public void run(){
  Map.Entry entry;
  RecordStore recordStore=mapService.getRecordStore(getPartitionId(),name);
  Map<Data,Record> records=recordStore.getReadonlyRecordMap();
  for (  Map.Entry<Data,Record> recordEntry : records.entrySet()) {
    Data dataKey=recordEntry.getKey();
    Record record=recordEntry.getValue();
    Object objectKey=mapService.toObject(record.getKey());
    Object valueBeforeProcess=mapService.toObject(record.getValue());
    if (getPredicate() != null) {
      QueryEntry queryEntry=new QueryEntry(getNodeEngine().getSerializationService(),dataKey,objectKey,valueBeforeProcess);
      if (!getPredicate().apply(queryEntry)) {
        continue;
      }
    }
    entry=new AbstractMap.SimpleEntry(objectKey,valueBeforeProcess);
    entryProcessor.processBackup(entry);
    if (entry.getValue() == null) {
      recordStore.remove(dataKey);
    }
 else {
      recordStore.put(new AbstractMap.SimpleImmutableEntry<Data,Object>(dataKey,entry.getValue()));
    }
  }
}

Fixed version (ground truth):
public void run(){
  Map.Entry entry;
  RecordStore recordStore=mapService.getRecordStore(getPartitionId(),name);
  Map<Data,Record> records=recordStore.getReadonlyRecordMap();
  for (  Map.Entry<Data,Record> recordEntry : records.entrySet()) {
    Data dataKey=recordEntry.getKey();
    Record record=recordEntry.getValue();
    Object objectKey=mapService.toObject(record.getKey());
    Object valueBeforeProcess=mapService.toObject(record.getValue());
    if (getPredicate() != null) {
      QueryEntry queryEntry=new QueryEntry(getNodeEngine().getSerializationService(),dataKey,objectKey,valueBeforeProcess);
      if (!getPredicate().apply(queryEntry)) {
        continue;
      }
    }
    entry=new AbstractMap.SimpleEntry(objectKey,valueBeforeProcess);
    entryProcessor.processBackup(entry);
    if (entry.getValue() == null) {
      recordStore.remove(dataKey);
    }
 else {
      recordStore.putBackup(new AbstractMap.SimpleImmutableEntry<Data,Object>(dataKey,entry.getValue()));
    }
  }
}
Program: 48438
Project: 48438
Buggy source:
public Data read() throws IOException {
  ClientPacket packet=new ClientPacket(serializationService.getSerializationContext());
  while (true) {
    if (readFromSocket) {
      int readBytes=socketChannelWrapper.read(readBuffer);
      if (readBytes == -1) {
        throw new EOFException("String_Node_Str");
      }
      readBuffer.flip();
    }
    boolean complete=packet.readFrom(readBuffer);
    if (complete) {
      if (readBuffer.hasRemaining()) {
        readFromSocket=false;
      }
 else {
        readBuffer.compact();
      }
      return packet.getData();
    }
    readFromSocket=true;
    readBuffer.clear();
  }
}

Fixed version (ground truth):
public Data read() throws IOException {
  ClientPacket packet=new ClientPacket(serializationService.getSerializationContext());
  while (true) {
    if (readFromSocket) {
      int readBytes=socketChannelWrapper.read(readBuffer);
      if (readBytes == -1) {
        throw new EOFException("String_Node_Str");
      }
      readBuffer.flip();
    }
    boolean complete=packet.readFrom(readBuffer);
    if (complete) {
      if (readBuffer.hasRemaining()) {
        readFromSocket=false;
      }
 else {
        readBuffer.compact();
        readFromSocket=true;
      }
      return packet.getData();
    }
    readFromSocket=true;
    readBuffer.clear();
  }
}