Program: 49605
Project: 49605
Buggy source:
boolean startCleanup(boolean forced){
  final long now=Clock.currentTimeMillis();
  long dirtyAge=(now - lastCleanup);
  boolean shouldRun=forced || (store != null && dirty && dirtyAge >= writeDelayMillis) || (dirtyAge > cleanupDelayMillis);
  if (shouldRun && cleanupActive.compareAndSet(false,true)) {
    lastCleanup=now;
    try {
      if (nearCache != null) {
        nearCache.evict(now,false);
      }
      dirty=false;
      final Set<Record> recordsDirty=new HashSet<Record>();
      final Set<Record> recordsUnknown=new HashSet<Record>();
      final Set<Record> recordsToPurge=new HashSet<Record>();
      final Set<Record> recordsToEvict=new HashSet<Record>();
      final Set<Record> sortedRecords=new TreeSet<Record>(new ComparatorWrapper(evictionComparator));
      final Collection<Record> records=mapRecords.values();
      final boolean overCapacity=overCapacity();
      final boolean evictionAware=evictionComparator != null && overCapacity;
      int recordsStillOwned=0;
      int backupPurgeCount=0;
      long costOfRecords=0L;
      PartitionManager partitionManager=concurrentMapManager.partitionManager;
      for (      Record record : records) {
        PartitionInfo partition=partitionManager.getPartition(record.getBlockId());
        Address owner=partition.getOwner();
        boolean owned=(owner != null && thisAddress.equals(owner));
        boolean ownedOrBackup=partition.isOwnerOrBackup(thisAddress,getTotalBackupCount());
        if (owner != null && !partitionManager.isPartitionMigrating(partition.getPartitionId())) {
          if (owned) {
            if (store != null && mapStoreWrapper.isEnabled() && writeDelayMillis > 0 && record.isDirty()) {
              if (now > record.getWriteTime()) {
                recordsDirty.add(record);
                record.setDirty(false);
              }
 else {
                dirty=true;
              }
            }
 else             if (shouldPurgeRecord(record,now)) {
              recordsToPurge.add(record);
            }
 else             if (record.isActive() && !record.isValid(now)) {
              recordsToEvict.add(record);
            }
 else             if (evictionAware && record.isActive() && record.isEvictable()) {
              sortedRecords.add(record);
              recordsStillOwned++;
            }
            if (record.isActive() && record.isValid(now)) {
              costOfRecords+=record.getCost();
            }
          }
 else           if (ownedOrBackup) {
            if (shouldPurgeRecord(record,now)) {
              recordsToPurge.add(record);
              backupPurgeCount++;
            }
          }
 else {
            recordsUnknown.add(record);
          }
        }
      }
      totalCostOfRecords=costOfRecords;
      if (evictionAware && (forced || overCapacity)) {
        int numberOfRecordsToEvict=(int)(recordsStillOwned * evictionRate);
        int evictedCount=0;
        for (        Record record : sortedRecords) {
          if (record.isActive() && record.isEvictable()) {
            recordsToEvict.add(record);
            if (++evictedCount >= numberOfRecordsToEvict) {
              break;
            }
          }
        }
      }
      Level levelLog=(concurrentMapManager.LOG_STATE) ? Level.INFO : Level.FINEST;
      if (logger.isLoggable(levelLog)) {
        logger.log(levelLog,name + "String_Node_Str" + "String_Node_Str"+ recordsDirty.size()+ "String_Node_Str"+ recordsToPurge.size()+ "String_Node_Str"+ recordsToEvict.size()+ "String_Node_Str"+ recordsUnknown.size()+ "String_Node_Str"+ recordsStillOwned+ "String_Node_Str"+ backupPurgeCount);
        logger.log(levelLog,thisAddress + "String_Node_Str" + mapRecords.size()+ "String_Node_Str"+ mapIndexService.getOwnedRecords().size()+ "String_Node_Str"+ costOfRecords);
      }
      executeStoreUpdate(recordsDirty);
      executeEviction(recordsToEvict);
      executePurge(recordsToPurge);
      executePurgeUnknowns(recordsUnknown);
    }
  finally {
      cleanupActive.set(false);
    }
    return true;
  }
 else {
    return false;
  }
}

Fixed version (ground truth):
boolean startCleanup(boolean forced){
  final long now=Clock.currentTimeMillis();
  long dirtyAge=(now - lastCleanup);
  boolean shouldRun=forced || (store != null && mapStoreWrapper.isEnabled() && dirty && dirtyAge >= writeDelayMillis) || (dirtyAge > cleanupDelayMillis);
  if (shouldRun && cleanupActive.compareAndSet(false,true)) {
    lastCleanup=now;
    try {
      if (nearCache != null) {
        nearCache.evict(now,false);
      }
      dirty=false;
      final Set<Record> recordsDirty=new HashSet<Record>();
      final Set<Record> recordsUnknown=new HashSet<Record>();
      final Set<Record> recordsToPurge=new HashSet<Record>();
      final Set<Record> recordsToEvict=new HashSet<Record>();
      final Set<Record> sortedRecords=new TreeSet<Record>(new ComparatorWrapper(evictionComparator));
      final Collection<Record> records=mapRecords.values();
      final boolean overCapacity=overCapacity();
      final boolean evictionAware=evictionComparator != null && overCapacity;
      int recordsStillOwned=0;
      int backupPurgeCount=0;
      long costOfRecords=0L;
      PartitionManager partitionManager=concurrentMapManager.partitionManager;
      for (      Record record : records) {
        PartitionInfo partition=partitionManager.getPartition(record.getBlockId());
        Address owner=partition.getOwner();
        boolean owned=(owner != null && thisAddress.equals(owner));
        boolean ownedOrBackup=partition.isOwnerOrBackup(thisAddress,getTotalBackupCount());
        if (owner != null && !partitionManager.isPartitionMigrating(partition.getPartitionId())) {
          if (owned) {
            if (store != null && mapStoreWrapper.isEnabled() && writeDelayMillis > 0 && record.isDirty()) {
              if (now > record.getWriteTime()) {
                recordsDirty.add(record);
                record.setDirty(false);
              }
 else {
                dirty=true;
              }
            }
 else             if (shouldPurgeRecord(record,now)) {
              recordsToPurge.add(record);
            }
 else             if (record.isActive() && !record.isValid(now)) {
              recordsToEvict.add(record);
            }
 else             if (evictionAware && record.isActive() && record.isEvictable()) {
              sortedRecords.add(record);
              recordsStillOwned++;
            }
            if (record.isActive() && record.isValid(now)) {
              costOfRecords+=record.getCost();
            }
          }
 else           if (ownedOrBackup) {
            if (shouldPurgeRecord(record,now)) {
              recordsToPurge.add(record);
              backupPurgeCount++;
            }
          }
 else {
            recordsUnknown.add(record);
          }
        }
      }
      totalCostOfRecords=costOfRecords;
      if (evictionAware && (forced || overCapacity)) {
        int numberOfRecordsToEvict=(int)(recordsStillOwned * evictionRate);
        int evictedCount=0;
        for (        Record record : sortedRecords) {
          if (record.isActive() && record.isEvictable()) {
            recordsToEvict.add(record);
            if (++evictedCount >= numberOfRecordsToEvict) {
              break;
            }
          }
        }
      }
      Level levelLog=(concurrentMapManager.LOG_STATE) ? Level.INFO : Level.FINEST;
      if (logger.isLoggable(levelLog)) {
        logger.log(levelLog,name + "String_Node_Str" + "String_Node_Str"+ recordsDirty.size()+ "String_Node_Str"+ recordsToPurge.size()+ "String_Node_Str"+ recordsToEvict.size()+ "String_Node_Str"+ recordsUnknown.size()+ "String_Node_Str"+ recordsStillOwned+ "String_Node_Str"+ backupPurgeCount);
        logger.log(levelLog,thisAddress + "String_Node_Str" + mapRecords.size()+ "String_Node_Str"+ mapIndexService.getOwnedRecords().size()+ "String_Node_Str"+ costOfRecords);
      }
      executeStoreUpdate(recordsDirty);
      executeEviction(recordsToEvict);
      executePurge(recordsToPurge);
      executePurgeUnknowns(recordsUnknown);
    }
  finally {
      cleanupActive.set(false);
    }
    return true;
  }
 else {
    return false;
  }
}