Program: 95946
Project: 95946
Buggy source:
/** 
 * Currently, assume block size is uniform
 * @return Return tier permutation list and its scale factor
 */
public HashMap<List<Integer>,Double> calculateScaleFactor(List<HyperTableCube> cubes){
  ScrambleMetaSet scrambleMeta=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()) {
    blockCountList.add(scrambleMeta.getAggregationBlockCount(d.getSchemaName(),d.getTableName()));
    metaForTablesList.add(scrambleMeta.getMetaForTable(d.getSchemaName(),d.getTableName()));
    scrambleTableTierInfo.add(new ImmutablePair<>(cubes.get(0).getDimensions().indexOf(d),scrambleMeta.getMetaForTable(d.getSchemaName(),d.getTableName()).getNumberOfTiers()));
    if (scrambleMeta.getMetaForTable(d.getSchemaName(),d.getTableName()).getNumberOfTiers() > 1 && !Initiated) {
      multipleTierTableTierInfo.put(cubes.get(0).getDimensions().indexOf(d),scrambleMeta.getMetaForTable(d.getSchemaName(),d.getTableName()).getTierColumn());
    }
  }
  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=0;
        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 / total);
  }
  return scaleFactor;
}

Fixed version (ground truth):
/** 
 * Currently, assume block size is uniform
 * @return Return tier permutation list and its scale factor
 */
public HashMap<List<Integer>,Double> calculateScaleFactor(List<HyperTableCube> cubes){
  ScrambleMetaSet scrambleMeta=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()) {
    blockCountList.add(scrambleMeta.getAggregationBlockCount(d.getSchemaName(),d.getTableName()));
    metaForTablesList.add(scrambleMeta.getMetaForTable(d.getSchemaName(),d.getTableName()));
    scrambleTableTierInfo.add(new ImmutablePair<>(cubes.get(0).getDimensions().indexOf(d),scrambleMeta.getMetaForTable(d.getSchemaName(),d.getTableName()).getNumberOfTiers()));
    if (scrambleMeta.getMetaForTable(d.getSchemaName(),d.getTableName()).getNumberOfTiers() > 1 && !Initiated) {
      ScrambleMeta meta=scrambleMeta.getMetaForTable(d.getSchemaName(),d.getTableName());
      HashMap<ScrambleMeta,List<String>> scrambleTableTierColumnAlias=getScrambleTableTierColumnAlias();
      if (scrambleTableTierColumnAlias.containsKey(meta)) {
        multipleTierTableTierInfo.put(cubes.get(0).getDimensions().indexOf(d),scrambleTableTierColumnAlias.get(meta).get(0));
        scrambleTableTierColumnAlias.get(meta).remove(0);
        if (scrambleTableTierColumnAlias.get(meta).isEmpty()) {
          scrambleTableTierColumnAlias.remove(meta);
        }
      }
 else {
        multipleTierTableTierInfo.put(cubes.get(0).getDimensions().indexOf(d),scrambleMeta.getMetaForTable(d.getSchemaName(),d.getTableName()).getTierColumn());
      }
    }
  }
  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=0;
        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 / total);
  }
  return scaleFactor;
}