Program: 14309
Project: 14309
Buggy source:
public static void addMetric(String accountId,String metricName,String namespace,Map<String,String> dimensionMap,MetricType metricType){
  if (dimensionMap == null) {
    dimensionMap=new HashMap<String,String>();
  }
 else   if (dimensionMap.size() > ListMetric.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);
  }
  Set<Set<DimensionEntity>> permutations=null;
  if (metricType == MetricType.System) {
    if (!metricName.equals("String_Node_Str")) {
      permutations=Sets.powerSet(dimensions);
    }
 else {
      permutations=Sets.filter(Sets.powerSet(dimensions),new Predicate<Set<DimensionEntity>>(){
        public boolean apply(        @Nullable Set<DimensionEntity> candidate){
          return (candidate != null && candidate.size() < 2);
        }
      }
);
    }
  }
 else {
    permutations=Sets.newHashSet();
    permutations.add(dimensions);
  }
  Multimap<Class,MetricEntity> metricMap=ArrayListMultimap.<Class,MetricEntity>create();
  EntityTransaction db=Entities.get(ListMetric.class);
  try {
    for (    Set<DimensionEntity> dimensionsPermutation : permutations) {
      ListMetric metric=new ListMetric();
      metric.setAccountId(accountId);
      metric.setMetricName(metricName);
      metric.setNamespace(namespace);
      metric.setDimensions(dimensionsPermutation);
      metric.setMetricType(metricType);
      Criteria criteria=Entities.createCriteria(ListMetric.class).add(Restrictions.eq("String_Node_Str",accountId)).add(Restrictions.eq("String_Node_Str",metricName)).add(Restrictions.eq("String_Node_Str",namespace));
      int dimIndex=1;
      for (      DimensionEntity d : dimensionsPermutation) {
        criteria.add(Restrictions.eq("String_Node_Str" + dimIndex + "String_Node_Str",d.getName()));
        criteria.add(Restrictions.eq("String_Node_Str" + dimIndex + "String_Node_Str",d.getValue()));
        dimIndex++;
      }
      while (dimIndex <= ListMetric.MAX_DIM_NUM) {
        criteria.add(Restrictions.isNull("String_Node_Str" + dimIndex + "String_Node_Str"));
        criteria.add(Restrictions.isNull("String_Node_Str" + dimIndex + "String_Node_Str"));
        dimIndex++;
      }
      ListMetric inDbMetric=(ListMetric)criteria.uniqueResult();
      if (inDbMetric != null) {
        inDbMetric.setVersion(1 + inDbMetric.getVersion());
      }
 else {
        Entities.persist(metric);
      }
    }
    db.commit();
  }
 catch (  RuntimeException ex) {
    Logs.extreme().error(ex,ex);
    throw ex;
  }
 finally {
    if (db.isActive())     db.rollback();
  }
}

Fixed version (ground truth):
public static void addMetric(String accountId,String metricName,String namespace,Map<String,String> dimensionMap,MetricType metricType){
  if (dimensionMap == null) {
    dimensionMap=new HashMap<String,String>();
  }
 else   if (dimensionMap.size() > ListMetric.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);
  }
  Set<Set<DimensionEntity>> permutations=null;
  if (metricType == MetricType.System) {
    if (!namespace.equals("String_Node_Str")) {
      permutations=Sets.powerSet(dimensions);
    }
 else {
      permutations=Sets.filter(Sets.powerSet(dimensions),new Predicate<Set<DimensionEntity>>(){
        public boolean apply(        @Nullable Set<DimensionEntity> candidate){
          return (candidate != null && candidate.size() < 2);
        }
      }
);
    }
  }
 else {
    permutations=Sets.newHashSet();
    permutations.add(dimensions);
  }
  Multimap<Class,MetricEntity> metricMap=ArrayListMultimap.<Class,MetricEntity>create();
  EntityTransaction db=Entities.get(ListMetric.class);
  try {
    for (    Set<DimensionEntity> dimensionsPermutation : permutations) {
      ListMetric metric=new ListMetric();
      metric.setAccountId(accountId);
      metric.setMetricName(metricName);
      metric.setNamespace(namespace);
      metric.setDimensions(dimensionsPermutation);
      metric.setMetricType(metricType);
      Criteria criteria=Entities.createCriteria(ListMetric.class).add(Restrictions.eq("String_Node_Str",accountId)).add(Restrictions.eq("String_Node_Str",metricName)).add(Restrictions.eq("String_Node_Str",namespace));
      int dimIndex=1;
      for (      DimensionEntity d : dimensionsPermutation) {
        criteria.add(Restrictions.eq("String_Node_Str" + dimIndex + "String_Node_Str",d.getName()));
        criteria.add(Restrictions.eq("String_Node_Str" + dimIndex + "String_Node_Str",d.getValue()));
        dimIndex++;
      }
      while (dimIndex <= ListMetric.MAX_DIM_NUM) {
        criteria.add(Restrictions.isNull("String_Node_Str" + dimIndex + "String_Node_Str"));
        criteria.add(Restrictions.isNull("String_Node_Str" + dimIndex + "String_Node_Str"));
        dimIndex++;
      }
      ListMetric inDbMetric=(ListMetric)criteria.uniqueResult();
      if (inDbMetric != null) {
        inDbMetric.setVersion(1 + inDbMetric.getVersion());
      }
 else {
        Entities.persist(metric);
      }
    }
    db.commit();
  }
 catch (  RuntimeException ex) {
    Logs.extreme().error(ex,ex);
    throw ex;
  }
 finally {
    if (db.isActive())     db.rollback();
  }
}