Program: 14302
Project: 14302
Buggy source:
public static Collection<MetricStatistics> getMetricStatistics(String accountId,String metricName,String namespace,Map<String,String> dimensionMap,MetricType metricType,Units units,Date startTime,Date endTime,Integer period){
  if (dimensionMap == null) {
    dimensionMap=new HashMap<String,String>();
  }
 else   if (dimensionMap.size() > MetricEntity.MAX_DIM_NUM) {
    throw new IllegalArgumentException("String_Node_Str" + dimensionMap.size());
  }
  TreeSet<DimensionEntity> dimensions=new TreeSet<DimensionEntity>();
  for (  Map.Entry<String,String> entry : dimensionMap.entrySet()) {
    DimensionEntity d=new DimensionEntity();
    d.setName(entry.getKey());
    d.setValue(entry.getValue());
    dimensions.add(d);
  }
  Date now=new Date();
  if (endTime == null)   endTime=now;
  if (startTime == null)   startTime=new Date(now.getTime() - 60 * 60 * 1000L);
  startTime=stripSeconds(startTime);
  endTime=stripSeconds(endTime);
  if (startTime.after(endTime)) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (period == null) {
    period=60;
  }
  if (period % 60 != 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (period < 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (period == 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (metricType == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (accountId == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (metricName == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (namespace == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  String hash=hash(dimensions);
  Class metricEntityClass=MetricEntityFactory.getClassForEntitiesGet(metricType,hash);
  Map<GetMetricStatisticsAggregationKey,MetricStatistics> aggregationMap=Maps.newLinkedHashMap();
  EntityTransaction db=Entities.get(metricEntityClass);
  try {
    Criteria criteria=Entities.createCriteria(metricEntityClass);
    criteria=criteria.add(Restrictions.eq("String_Node_Str",accountId));
    criteria=criteria.add(Restrictions.eq("String_Node_Str",metricName));
    criteria=criteria.add(Restrictions.eq("String_Node_Str",namespace));
    criteria=criteria.add(Restrictions.lt("String_Node_Str",endTime));
    criteria=criteria.add(Restrictions.ge("String_Node_Str",startTime));
    criteria=criteria.add(Restrictions.eq("String_Node_Str",hash));
    if (units != null) {
      criteria=criteria.add(Restrictions.eq("String_Node_Str",units));
    }
    criteria=criteria.addOrder(Order.asc("String_Node_Str"));
    criteria=criteria.addOrder(Order.asc("String_Node_Str"));
    Collection results=criteria.list();
    for (    Object o : results) {
      MetricEntity me=(MetricEntity)o;
      GetMetricStatisticsAggregationKey key=new GetMetricStatisticsAggregationKey(me,startTime,period);
      MetricStatistics item=new MetricStatistics(me,startTime,period);
      if (!aggregationMap.containsKey(key)) {
        aggregationMap.put(key,item);
      }
 else {
        MetricStatistics totalSoFar=aggregationMap.get(key);
        totalSoFar.setSampleMax(Math.max(item.getSampleMax(),totalSoFar.getSampleMax()));
        totalSoFar.setSampleMin(Math.min(item.getSampleMin(),totalSoFar.getSampleMin()));
        totalSoFar.setSampleSize(totalSoFar.getSampleSize() + item.getSampleSize());
        totalSoFar.setSampleSum(totalSoFar.getSampleSum() + item.getSampleSum());
      }
    }
    db.commit();
  }
 catch (  RuntimeException ex) {
    Logs.extreme().error(ex,ex);
    throw ex;
  }
 finally {
    if (db.isActive())     db.rollback();
  }
  return Lists.newArrayList(aggregationMap.values());
}

Fixed version (ground truth):
public static Collection<MetricStatistics> getMetricStatistics(String accountId,String metricName,String namespace,Map<String,String> dimensionMap,MetricType metricType,Units units,Date startTime,Date endTime,Integer period){
  if (dimensionMap == null) {
    dimensionMap=new HashMap<String,String>();
  }
 else   if (dimensionMap.size() > MetricEntity.MAX_DIM_NUM) {
    throw new IllegalArgumentException("String_Node_Str" + dimensionMap.size());
  }
  TreeSet<DimensionEntity> dimensions=new TreeSet<DimensionEntity>();
  for (  Map.Entry<String,String> entry : dimensionMap.entrySet()) {
    DimensionEntity d=new DimensionEntity();
    d.setName(entry.getKey());
    d.setValue(entry.getValue());
    dimensions.add(d);
  }
  Date now=new Date();
  if (endTime == null)   endTime=now;
  if (startTime == null)   startTime=new Date(now.getTime() - 60 * 60 * 1000L);
  startTime=stripSeconds(startTime);
  endTime=stripSeconds(endTime);
  if (startTime.after(endTime)) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (period == null) {
    period=60;
  }
  if (period % 60 != 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (period < 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (period == 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (metricType == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (accountId == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (metricName == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (namespace == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  String hash=hash(dimensions);
  Class metricEntityClass=MetricEntityFactory.getClassForEntitiesGet(metricType,hash);
  Map<GetMetricStatisticsAggregationKey,MetricStatistics> aggregationMap=new TreeMap<GetMetricStatisticsAggregationKey,MetricStatistics>(GetMetricStatisticsAggregationKey.COMPARATOR_WITH_NULLS.INSTANCE);
  EntityTransaction db=Entities.get(metricEntityClass);
  try {
    Criteria criteria=Entities.createCriteria(metricEntityClass);
    criteria=criteria.add(Restrictions.eq("String_Node_Str",accountId));
    criteria=criteria.add(Restrictions.eq("String_Node_Str",metricName));
    criteria=criteria.add(Restrictions.eq("String_Node_Str",namespace));
    criteria=criteria.add(Restrictions.lt("String_Node_Str",endTime));
    criteria=criteria.add(Restrictions.ge("String_Node_Str",startTime));
    criteria=criteria.add(Restrictions.eq("String_Node_Str",hash));
    if (units != null) {
      criteria=criteria.add(Restrictions.eq("String_Node_Str",units));
    }
    criteria=criteria.addOrder(Order.asc("String_Node_Str"));
    criteria=criteria.addOrder(Order.asc("String_Node_Str"));
    Collection results=criteria.list();
    for (    Object o : results) {
      MetricEntity me=(MetricEntity)o;
      GetMetricStatisticsAggregationKey key=new GetMetricStatisticsAggregationKey(me,startTime,period,hash);
      MetricStatistics item=new MetricStatistics(me,startTime,period,dimensions);
      if (!aggregationMap.containsKey(key)) {
        aggregationMap.put(key,item);
      }
 else {
        MetricStatistics totalSoFar=aggregationMap.get(key);
        totalSoFar.setSampleMax(Math.max(item.getSampleMax(),totalSoFar.getSampleMax()));
        totalSoFar.setSampleMin(Math.min(item.getSampleMin(),totalSoFar.getSampleMin()));
        totalSoFar.setSampleSize(totalSoFar.getSampleSize() + item.getSampleSize());
        totalSoFar.setSampleSum(totalSoFar.getSampleSum() + item.getSampleSum());
      }
    }
    db.commit();
  }
 catch (  RuntimeException ex) {
    Logs.extreme().error(ex,ex);
    throw ex;
  }
 finally {
    if (db.isActive())     db.rollback();
  }
  return Lists.newArrayList(aggregationMap.values());
}