Program: 108081
Project: 108081
Buggy source:
/** 
 * Returns the tree for the given sensitive attribute, if a generalization hierarchy is associated. Required for t-closeness with hierarchical distance EMD
 * @param attribute
 * @return tree
 */
public int[] getTree(String attribute){
  final int[][] data=dataAnalyzed.getArray();
  final int index=indexesSensitive.get(attribute);
  final int[][] hierarchy=hierarchiesSensitive.get(attribute).map;
  final int totalElementsP=subset == null ? data.length : subsetSize;
  final int height=hierarchy[0].length - 1;
  final int numLeafs=hierarchy.length;
  final ArrayList<Integer> treeList=new ArrayList<Integer>();
  treeList.add(totalElementsP);
  treeList.add(numLeafs);
  treeList.add(height);
  for (int i=0; i < numLeafs; i++) {
    treeList.add(0);
  }
  final int offsetLeafs=3;
  for (int i=0; i < data.length; i++) {
    if (subset == null || subset.contains(i)) {
      int previousFreq=treeList.get(data[i][index] + offsetLeafs);
      previousFreq++;
      treeList.set(data[i][index] + offsetLeafs,previousFreq);
    }
  }
  for (int i=0; i < numLeafs; i++) {
    treeList.add(-1);
  }
class TNode {
    IntOpenHashSet children=new IntOpenHashSet();
    int level=0;
    int offset=0;
  }
  final int offsetsExtras=offsetLeafs + numLeafs;
  final IntObjectOpenHashMap<TNode> nodes=new IntObjectOpenHashMap<TNode>();
  final ArrayList<ArrayList<TNode>> levels=new ArrayList<ArrayList<TNode>>();
  for (int i=0; i < hierarchy[0].length; i++) {
    levels.add(new ArrayList<TNode>());
  }
  for (int i=0; i < hierarchy[0].length; i++) {
    for (int j=0; j < hierarchy.length; j++) {
      final int nodeID=hierarchy[j][i];
      TNode curNode=null;
      if (!nodes.containsKey(nodeID)) {
        curNode=new TNode();
        curNode.level=i;
        nodes.put(nodeID,curNode);
        final ArrayList<TNode> level=levels.get(curNode.level);
        level.add(curNode);
      }
 else {
        curNode=nodes.get(nodeID);
      }
      if (i > 0) {
        curNode.children.add(hierarchy[j][i - 1]);
      }
    }
  }
  for (  final ArrayList<TNode> level : levels) {
    for (    final TNode node : level) {
      if (node.level > 0) {
        node.offset=treeList.size();
        treeList.add(node.children.size());
        treeList.add(node.level);
        final int[] keys=node.children.keys;
        final boolean[] allocated=node.children.allocated;
        for (int i=0; i < allocated.length; i++) {
          if (allocated[i]) {
            treeList.add(node.level == 1 ? keys[i] + offsetsExtras : nodes.get(keys[i]).offset);
          }
        }
        treeList.add(0);
        treeList.add(0);
      }
    }
  }
  final int[] treeArray=new int[treeList.size()];
  int count=0;
  for (  final int val : treeList) {
    treeArray[count++]=val;
  }
  return treeArray;
}

Fixed version (ground truth):
/** 
 * Returns the tree for the given sensitive attribute, if a generalization hierarchy is associated. Required for t-closeness with hierarchical distance EMD
 * @param attribute
 * @return tree
 */
public int[] getTree(String attribute){
  final int[][] data=dataAnalyzed.getArray();
  final int index=indexesSensitive.get(attribute);
  final int[][] hierarchy=hierarchiesSensitive.get(attribute).map;
  final int totalElementsP=subset == null ? data.length : subsetSize;
  final int height=hierarchy[0].length - 1;
  final int numLeafs=hierarchy.length;
  final ArrayList<Integer> treeList=new ArrayList<Integer>();
  treeList.add(totalElementsP);
  treeList.add(numLeafs);
  treeList.add(height);
  for (int i=0; i < numLeafs; i++) {
    treeList.add(0);
  }
  final int offsetLeafs=3;
  for (int i=0; i < data.length; i++) {
    if (subset == null || subset.contains(i)) {
      int previousFreq=treeList.get(data[i][index] + offsetLeafs);
      previousFreq++;
      treeList.set(data[i][index] + offsetLeafs,previousFreq);
    }
  }
  for (int i=0; i < numLeafs; i++) {
    treeList.add(-1);
  }
class TNode {
    IntOpenHashSet children=new IntOpenHashSet();
    int level=0;
    int offset=0;
  }
  final int offsetsExtras=offsetLeafs + numLeafs;
  final IntObjectOpenHashMap<TNode> nodes=new IntObjectOpenHashMap<TNode>();
  final ArrayList<ArrayList<TNode>> levels=new ArrayList<ArrayList<TNode>>();
  for (int i=0; i < hierarchy[0].length; i++) {
    levels.add(new ArrayList<TNode>());
  }
  for (int i=0; i < hierarchy[0].length; i++) {
    for (int j=0; j < hierarchy.length; j++) {
      final int nodeID=hierarchy[j][i] + i * hierarchy.length;
      TNode curNode=null;
      if (!nodes.containsKey(nodeID)) {
        curNode=new TNode();
        curNode.level=i;
        nodes.put(nodeID,curNode);
        final ArrayList<TNode> level=levels.get(curNode.level);
        level.add(curNode);
      }
 else {
        curNode=nodes.get(nodeID);
      }
      if (i > 0) {
        curNode.children.add(hierarchy[j][i - 1] + (i - 1) * hierarchy.length);
      }
    }
  }
  for (  final ArrayList<TNode> level : levels) {
    for (    final TNode node : level) {
      if (node.level > 0) {
        node.offset=treeList.size();
        treeList.add(node.children.size());
        treeList.add(node.level);
        final int[] keys=node.children.keys;
        final boolean[] allocated=node.children.allocated;
        for (int i=0; i < allocated.length; i++) {
          if (allocated[i]) {
            treeList.add(node.level == 1 ? keys[i] + offsetsExtras : nodes.get(keys[i]).offset);
          }
        }
        treeList.add(0);
        treeList.add(0);
      }
    }
  }
  final int[] treeArray=new int[treeList.size()];
  int count=0;
  for (  final int val : treeList) {
    treeArray[count++]=val;
  }
  return treeArray;
}