Program: 49055
Project: 49055
Buggy source:
private boolean checkLimits(MapContainer mapContainer){
  MaxSizeConfig maxSizeConfig=mapContainer.getMapConfig().getMaxSizeConfig();
  MaxSizeConfig.MaxSizePolicy maxSizePolicy=maxSizeConfig.getMaxSizePolicy();
  String mapName=mapContainer.getName();
  int maxSize=maxSizeConfig.getSize() * 95 / 100;
  if (maxSizePolicy == MaxSizeConfig.MaxSizePolicy.PER_NODE || maxSizePolicy == MaxSizeConfig.MaxSizePolicy.PER_PARTITION) {
    int totalSize=0;
    for (int i=0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
      Address owner=nodeEngine.getPartitionService().getPartitionOwner(i);
      if (nodeEngine.getThisAddress().equals(owner)) {
        final PartitionContainer container=partitionContainers[i];
        if (container == null) {
          return false;
        }
        int size=container.getRecordStore(mapName).getRecords().size();
        if (maxSizePolicy == MaxSizeConfig.MaxSizePolicy.PER_PARTITION) {
          if (size >= maxSize) {
            return true;
          }
        }
 else {
          totalSize+=size;
        }
      }
    }
    return maxSizePolicy == MaxSizeConfig.MaxSizePolicy.PER_NODE && totalSize >= maxSize;
  }
  if (maxSizePolicy == MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE || maxSizePolicy == MaxSizeConfig.MaxSizePolicy.USED_HEAP_PERCENTAGE) {
    long total=Runtime.getRuntime().totalMemory();
    long used=(total - Runtime.getRuntime().freeMemory());
    if (maxSizePolicy == MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE) {
      return maxSize > (used / 1024 / 1024);
    }
 else {
      return maxSize > (used / total);
    }
  }
  return false;
}

Fixed version (ground truth):
private boolean checkLimits(MapContainer mapContainer){
  MaxSizeConfig maxSizeConfig=mapContainer.getMapConfig().getMaxSizeConfig();
  MaxSizeConfig.MaxSizePolicy maxSizePolicy=maxSizeConfig.getMaxSizePolicy();
  String mapName=mapContainer.getName();
  int maxSize=maxSizeConfig.getSize() * 95 / 100;
  if (maxSizePolicy == MaxSizeConfig.MaxSizePolicy.PER_NODE || maxSizePolicy == MaxSizeConfig.MaxSizePolicy.PER_PARTITION) {
    int totalSize=0;
    for (int i=0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
      Address owner=nodeEngine.getPartitionService().getPartitionOwner(i);
      if (nodeEngine.getThisAddress().equals(owner)) {
        final PartitionContainer container=partitionContainers[i];
        if (container == null) {
          return false;
        }
        int size=container.getRecordStore(mapName).getRecords().size();
        if (maxSizePolicy == MaxSizeConfig.MaxSizePolicy.PER_PARTITION) {
          if (size >= maxSize) {
            return true;
          }
        }
 else {
          totalSize+=size;
        }
      }
    }
    return maxSizePolicy == MaxSizeConfig.MaxSizePolicy.PER_NODE && totalSize >= maxSize;
  }
  if (maxSizePolicy == MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE || maxSizePolicy == MaxSizeConfig.MaxSizePolicy.USED_HEAP_PERCENTAGE) {
    long total=Runtime.getRuntime().totalMemory();
    long used=(total - Runtime.getRuntime().freeMemory());
    if (maxSizePolicy == MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE) {
      return maxSize < (used / 1024 / 1024);
    }
 else {
      return maxSize < (used / total);
    }
  }
  return false;
}