Program: 95938
Project: 95938
Buggy source:
/** 
 * Currently, assume block size is uniform
 * @return Return tier permutation list and its scale factor
 */
public HashMap<List<Integer>,Double> calculateScaleFactor(AggMeta sourceAggMeta,Map<Integer,String> multipleTierTableTierInfo) throws VerdictDBValueException {
  List<HyperTableCube> cubes=sourceAggMeta.getCubes();
  ScrambleMetaSet scrambleMetaSet=this.getScrambleMeta();
  List<ScrambleMeta> metaForTablesList=new ArrayList<>();
  List<Integer> blockCountList=new ArrayList<>();
  List<Pair<Integer,Integer>> scrambleTableTierInfo=new ArrayList<>();
  for (  Dimension d : cubes.get(0).getDimensions()) {
    ScrambleMeta scrambleMeta=scrambleMetaSet.getSingleMeta(d.getSchemaName(),d.getTableName());
    blockCountList.add(scrambleMetaSet.getAggregationBlockCount(d.getSchemaName(),d.getTableName()));
    metaForTablesList.add(scrambleMeta);
    scrambleTableTierInfo.add(new ImmutablePair<>(cubes.get(0).getDimensions().indexOf(d),scrambleMetaSet.getSingleMeta(d.getSchemaName(),d.getTableName()).getNumberOfTiers()));
    if (scrambleMeta.getNumberOfTiers() > 1 && !Initiated) {
      Map<ScrambleMeta,String> scrambleTableTierColumnAlias=sourceAggMeta.getScrambleTableTierColumnAlias();
      if (scrambleTableTierColumnAlias.containsKey(scrambleMeta) == false) {
        throw new VerdictDBValueException("String_Node_Str");
      }
      multipleTierTableTierInfo.put(cubes.get(0).getDimensions().indexOf(d),scrambleTableTierColumnAlias.get(scrambleMeta));
    }
  }
  List<List<Integer>> tierPermuation=generateTierPermuation(scrambleTableTierInfo);
  HashMap<List<Integer>,Double> scaleFactor=new HashMap<>();
  for (  List<Integer> tierlist : tierPermuation) {
    double total=0;
    for (    HyperTableCube cube : cubes) {
      double scale=1;
      for (int i=0; i < tierlist.size(); i++) {
        int tier=tierlist.get(i);
        Dimension d=cube.getDimensions().get(i);
        double prob;
        if (d.getBegin() == 0) {
          prob=metaForTablesList.get(i).getCumulativeDistributionForTier(tier).get(d.getEnd());
        }
 else {
          prob=metaForTablesList.get(i).getCumulativeDistributionForTier(tier).get(d.getEnd()) - metaForTablesList.get(i).getCumulativeDistributionForTier(tier).get(d.getBegin() - 1);
        }
        scale=scale * prob;
      }
      total+=scale;
    }
    if (total == 0) {
      scaleFactor.put(tierlist,0.0);
    }
 else {
      scaleFactor.put(tierlist,1.0 / total);
    }
  }
  return scaleFactor;
}

Fixed version (ground truth):
/** 
 * Currently, assume block size is uniform
 * @return Return tier permutation list and its scale factor
 */
private HashMap<List<Integer>,Double> calculateScaleFactor(AggMeta sourceAggMeta,Map<Integer,String> multipleTierTableTierInfo) throws VerdictDBValueException {
  List<HyperTableCube> cubes=sourceAggMeta.getCubes();
  ScrambleMetaSet scrambleMetaSet=this.getScrambleMeta();
  List<ScrambleMeta> metaForTablesList=new ArrayList<>();
  List<Integer> blockCountList=new ArrayList<>();
  List<Pair<Integer,Integer>> scrambleTableTierInfo=new ArrayList<>();
  for (  Dimension d : cubes.get(0).getDimensions()) {
    ScrambleMeta scrambleMeta=scrambleMetaSet.getSingleMeta(d.getSchemaName(),d.getTableName());
    blockCountList.add(scrambleMetaSet.getAggregationBlockCount(d.getSchemaName(),d.getTableName()));
    metaForTablesList.add(scrambleMeta);
    scrambleTableTierInfo.add(new ImmutablePair<>(cubes.get(0).getDimensions().indexOf(d),scrambleMetaSet.getSingleMeta(d.getSchemaName(),d.getTableName()).getNumberOfTiers()));
    if (scrambleMeta.getNumberOfTiers() > 1) {
      Map<ScrambleMeta,String> scrambleTableTierColumnAlias=sourceAggMeta.getScrambleTableTierColumnAlias();
      if (scrambleTableTierColumnAlias.containsKey(scrambleMeta) == false) {
        throw new VerdictDBValueException("String_Node_Str");
      }
      multipleTierTableTierInfo.put(cubes.get(0).getDimensions().indexOf(d),scrambleTableTierColumnAlias.get(scrambleMeta));
    }
  }
  List<List<Integer>> tierPermuation=generateTierPermuation(scrambleTableTierInfo);
  HashMap<List<Integer>,Double> scaleFactor=new HashMap<>();
  for (  List<Integer> tierlist : tierPermuation) {
    double total=0;
    for (    HyperTableCube cube : cubes) {
      double scale=1;
      for (int i=0; i < tierlist.size(); i++) {
        int tier=tierlist.get(i);
        Dimension d=cube.getDimensions().get(i);
        double prob;
        if (d.getBegin() == 0) {
          prob=metaForTablesList.get(i).getCumulativeDistributionForTier(tier).get(d.getEnd());
        }
 else {
          prob=metaForTablesList.get(i).getCumulativeDistributionForTier(tier).get(d.getEnd()) - metaForTablesList.get(i).getCumulativeDistributionForTier(tier).get(d.getBegin() - 1);
        }
        scale=scale * prob;
      }
      total+=scale;
    }
    if (total == 0) {
      scaleFactor.put(tierlist,0.0);
    }
 else {
      scaleFactor.put(tierlist,1.0 / total);
    }
  }
  return scaleFactor;
}