Program: 49172
Project: 49172
Buggy source:
public LocalMapStatsImpl createLocalMapStats(String mapName){
  MapContainer mapContainer=getMapContainer(mapName);
  LocalMapStatsImpl localMapStats=getLocalMapStatsImpl(mapName);
  if (!mapContainer.getMapConfig().isStatisticsEnabled()) {
    return localMapStats;
  }
  long ownedEntryCount=0;
  long backupEntryCount=0;
  long dirtyCount=0;
  long ownedEntryMemoryCost=0;
  long backupEntryMemoryCost=0;
  long hits=0;
  long lockedEntryCount=0;
  int backupCount=mapContainer.getTotalBackupCount();
  ClusterService clusterService=nodeEngine.getClusterService();
  final com.hazelcast.partition.PartitionService partitionService=nodeEngine.getPartitionService();
  Address thisAddress=clusterService.getThisAddress();
  for (int partitionId=0; partitionId < partitionService.getPartitionCount(); partitionId++) {
    PartitionView partition=partitionService.getPartitionView(partitionId);
    if (partition.getOwner().equals(thisAddress)) {
      PartitionContainer partitionContainer=getPartitionContainer(partitionId);
      RecordStore recordStore=partitionContainer.getRecordStore(mapName);
      Map<Data,Record> records=recordStore.getRecords();
      for (      Record record : records.values()) {
        RecordStatistics stats=record.getStatistics();
        ownedEntryCount++;
        ownedEntryMemoryCost+=record.getCost();
        localMapStats.setLastAccessTime(stats.getLastAccessTime());
        hits+=stats.getHits();
        if (recordStore.isLocked(record.getKey())) {
          lockedEntryCount++;
        }
      }
    }
 else {
      for (int replica=1; replica <= backupCount; replica++) {
        Address replicaAddress=partition.getReplicaAddress(replica);
        int tryCount=30;
        while (replicaAddress == null && clusterService.getSize() > backupCount && tryCount-- > 0) {
          try {
            Thread.sleep(100);
          }
 catch (          InterruptedException e) {
            throw ExceptionUtil.rethrow(e);
          }
          replicaAddress=partition.getReplicaAddress(replica);
        }
        if (replicaAddress != null && replicaAddress.equals(thisAddress)) {
          PartitionContainer partitionContainer=getPartitionContainer(partitionId);
          RecordStore recordStore=partitionContainer.getRecordStore(mapName);
          Map<Data,Record> records=recordStore.getRecords();
          for (          Record record : records.values()) {
            backupEntryCount++;
            backupEntryMemoryCost+=record.getCost();
          }
        }
 else         if (replicaAddress == null && clusterService.getSize() > backupCount) {
          logger.log(Level.WARNING,"String_Node_Str" + partition + "String_Node_Str"+ replica+ "String_Node_Str");
        }
      }
    }
  }
  if (mapContainer.getMapStoreWriteScheduler() != null && mapContainer.getMapStoreDeleteScheduler() != null) {
    dirtyCount=mapContainer.getMapStoreWriteScheduler().size() + mapContainer.getMapStoreDeleteScheduler().size();
  }
  localMapStats.setBackupCount(backupCount);
  localMapStats.setDirtyEntryCount(zeroOrPositive(dirtyCount));
  localMapStats.setLockedEntryCount(zeroOrPositive(lockedEntryCount));
  localMapStats.setHits(zeroOrPositive(hits));
  localMapStats.setOwnedEntryCount(zeroOrPositive(ownedEntryCount));
  localMapStats.setBackupEntryCount(zeroOrPositive(backupEntryCount));
  localMapStats.setOwnedEntryMemoryCost(zeroOrPositive(ownedEntryMemoryCost));
  localMapStats.setBackupEntryMemoryCost(zeroOrPositive(backupEntryMemoryCost));
  return localMapStats;
}

Fixed version (ground truth):
public LocalMapStatsImpl createLocalMapStats(String mapName){
  MapContainer mapContainer=getMapContainer(mapName);
  LocalMapStatsImpl localMapStats=getLocalMapStatsImpl(mapName);
  if (!mapContainer.getMapConfig().isStatisticsEnabled()) {
    return localMapStats;
  }
  long ownedEntryCount=0;
  long backupEntryCount=0;
  long dirtyCount=0;
  long ownedEntryMemoryCost=0;
  long backupEntryMemoryCost=0;
  long hits=0;
  long lockedEntryCount=0;
  int backupCount=mapContainer.getTotalBackupCount();
  ClusterService clusterService=nodeEngine.getClusterService();
  final com.hazelcast.partition.PartitionService partitionService=nodeEngine.getPartitionService();
  Address thisAddress=clusterService.getThisAddress();
  for (int partitionId=0; partitionId < partitionService.getPartitionCount(); partitionId++) {
    PartitionView partition=partitionService.getPartition(partitionId);
    if (partition.getOwner().equals(thisAddress)) {
      PartitionContainer partitionContainer=getPartitionContainer(partitionId);
      RecordStore recordStore=partitionContainer.getRecordStore(mapName);
      Map<Data,Record> records=recordStore.getRecords();
      for (      Record record : records.values()) {
        RecordStatistics stats=record.getStatistics();
        ownedEntryCount++;
        ownedEntryMemoryCost+=record.getCost();
        localMapStats.setLastAccessTime(stats.getLastAccessTime());
        hits+=stats.getHits();
        if (recordStore.isLocked(record.getKey())) {
          lockedEntryCount++;
        }
      }
    }
 else {
      for (int replica=1; replica <= backupCount; replica++) {
        Address replicaAddress=partition.getReplicaAddress(replica);
        int tryCount=30;
        while (replicaAddress == null && clusterService.getSize() > backupCount && tryCount-- > 0) {
          try {
            Thread.sleep(100);
          }
 catch (          InterruptedException e) {
            throw ExceptionUtil.rethrow(e);
          }
          replicaAddress=partition.getReplicaAddress(replica);
        }
        if (replicaAddress != null && replicaAddress.equals(thisAddress)) {
          PartitionContainer partitionContainer=getPartitionContainer(partitionId);
          RecordStore recordStore=partitionContainer.getRecordStore(mapName);
          Map<Data,Record> records=recordStore.getRecords();
          for (          Record record : records.values()) {
            backupEntryCount++;
            backupEntryMemoryCost+=record.getCost();
          }
        }
 else         if (replicaAddress == null && clusterService.getSize() > backupCount) {
          logger.log(Level.WARNING,"String_Node_Str" + partition + "String_Node_Str"+ replica+ "String_Node_Str");
        }
      }
    }
  }
  if (mapContainer.getMapStoreWriteScheduler() != null && mapContainer.getMapStoreDeleteScheduler() != null) {
    dirtyCount=mapContainer.getMapStoreWriteScheduler().size() + mapContainer.getMapStoreDeleteScheduler().size();
  }
  localMapStats.setBackupCount(backupCount);
  localMapStats.setDirtyEntryCount(zeroOrPositive(dirtyCount));
  localMapStats.setLockedEntryCount(zeroOrPositive(lockedEntryCount));
  localMapStats.setHits(zeroOrPositive(hits));
  localMapStats.setOwnedEntryCount(zeroOrPositive(ownedEntryCount));
  localMapStats.setBackupEntryCount(zeroOrPositive(backupEntryCount));
  localMapStats.setOwnedEntryMemoryCost(zeroOrPositive(ownedEntryMemoryCost));
  localMapStats.setBackupEntryMemoryCost(zeroOrPositive(backupEntryMemoryCost));
  return localMapStats;
}