Program: 189994
Project: 189994
Buggy source:
public void triangles(HierarchicalGraph graph,AttributeModel attributeModel){
  int ProgressCount=0;
  Progress.start(progress,7 * graph.getNodeCount());
  graph.readLock();
  N=graph.getNodeCount();
  nodeClustering=new double[N];
  network=new ArrayWrapper[N];
  HashMap<Node,Integer> indicies=new HashMap<Node,Integer>();
  int index=0;
  for (  Node s : graph.getNodes()) {
    indicies.put(s,index);
    network[index]=new ArrayWrapper();
    index++;
    Progress.progress(progress,++ProgressCount);
  }
  index=0;
  for (  Node node : graph.getNodes()) {
    HashMap<Node,EdgeWrapper> neighborTable=new HashMap<Node,EdgeWrapper>();
    if (!isDirected) {
      for (      Node neighbor : graph.getNeighbors(node)) {
        neighborTable.put(neighbor,new EdgeWrapper(1,network[indicies.get(neighbor)]));
      }
    }
 else {
      for (      Edge in : ((HierarchicalDirectedGraph)graph).getInEdges(node)) {
        Node neighbor=in.getSource();
        neighborTable.put(neighbor,new EdgeWrapper(1,network[indicies.get(neighbor)]));
      }
      for (      Edge out : ((HierarchicalDirectedGraph)graph).getOutEdges(node)) {
        Node neighbor=out.getTarget();
        EdgeWrapper ew=neighborTable.get(neighbor);
        if (ew == null) {
          neighborTable.put(neighbor,new EdgeWrapper(1,network[indicies.get(neighbor)]));
        }
 else {
          ew.count++;
        }
      }
    }
    EdgeWrapper[] edges=new EdgeWrapper[neighborTable.size()];
    int i=0;
    for (    EdgeWrapper e : neighborTable.values()) {
      edges[i]=e;
      i++;
    }
    network[index].node=node;
    network[index].setArray(edges);
    index++;
    Progress.progress(progress,++ProgressCount);
    if (isCanceled) {
      graph.readUnlockAll();
      return;
    }
  }
  Arrays.sort(network);
  for (int j=0; j < N; j++) {
    network[j].setID(j);
    Progress.progress(progress,++ProgressCount);
  }
  for (int j=0; j < N; j++) {
    Arrays.sort(network[j].getArray(),new Renumbering());
    Progress.progress(progress,++ProgressCount);
  }
  triangles=new int[N];
  K=(int)Math.sqrt(N);
  for (int v=0; v < K && v < N; v++) {
    newVertex(v);
    Progress.progress(progress,++ProgressCount);
  }
  for (int v=N - 1; (v >= 0) && (v >= K); v--) {
    for (int i=closest_in_array(v); i >= 0; i--) {
      int u=network[v].get(i);
      if (u >= K) {
        tr_link_nohigh(u,v,network[v].getCount(i));
      }
    }
    Progress.progress(progress,++ProgressCount);
    if (isCanceled) {
      graph.readUnlockAll();
      return;
    }
  }
  avgClusteringCoeff=0;
  AttributeTable nodeTable=attributeModel.getNodeTable();
  AttributeColumn clusteringCol=nodeTable.getColumn(CLUSTERING_COEFF);
  if (clusteringCol == null) {
    clusteringCol=nodeTable.addColumn(CLUSTERING_COEFF,"String_Node_Str",AttributeType.DOUBLE,AttributeOrigin.COMPUTED,new Double(0));
  }
  for (  Node s : graph.getNodes()) {
    int v=indicies.get(s);
    if (network[v].length() > 1) {
      double cc=triangles[v];
      totalTriangles+=triangles[v];
      cc/=(network[v].length() * (network[v].length() - 1));
      if (!isDirected) {
        cc*=2.0f;
      }
      nodeClustering[v]=cc;
      AttributeRow row=(AttributeRow)s.getNodeData().getAttributes();
      row.setValue(clusteringCol,cc);
      avgClusteringCoeff+=cc;
    }
    Progress.progress(progress,++ProgressCount);
    if (isCanceled) {
      graph.readUnlockAll();
      return;
    }
  }
  totalTriangles/=3;
  avgClusteringCoeff/=N;
  graph.readUnlock();
}

Fixed version (ground truth):
private void triangles(HierarchicalGraph hgraph,AttributeModel attributeModel){
  int ProgressCount=0;
  Progress.start(progress,7 * hgraph.getNodeCount());
  hgraph.readLock();
  N=hgraph.getNodeCount();
  nodeClustering=new double[N];
  network=new ArrayWrapper[N];
  HashMap<Node,Integer> indicies=new HashMap<Node,Integer>();
  int index=0;
  for (  Node s : hgraph.getNodes()) {
    indicies.put(s,index);
    network[index]=new ArrayWrapper();
    index++;
    Progress.progress(progress,++ProgressCount);
  }
  index=0;
  for (  Node node : hgraph.getNodes()) {
    HashMap<Node,EdgeWrapper> neighborTable=new HashMap<Node,EdgeWrapper>();
    if (!isDirected) {
      for (      Node neighbor : hgraph.getNeighbors(node)) {
        neighborTable.put(neighbor,new EdgeWrapper(1,network[indicies.get(neighbor)]));
      }
    }
 else {
      for (      Edge in : ((HierarchicalDirectedGraph)hgraph).getInEdgesAndMetaInEdges(node)) {
        Node neighbor=in.getSource();
        neighborTable.put(neighbor,new EdgeWrapper(1,network[indicies.get(neighbor)]));
      }
      for (      Edge out : ((HierarchicalDirectedGraph)hgraph).getOutEdgesAndMetaOutEdges(node)) {
        Node neighbor=out.getTarget();
        EdgeWrapper ew=neighborTable.get(neighbor);
        if (ew == null) {
          neighborTable.put(neighbor,new EdgeWrapper(1,network[indicies.get(neighbor)]));
        }
 else {
          ew.count++;
        }
      }
    }
    EdgeWrapper[] edges=new EdgeWrapper[neighborTable.size()];
    int i=0;
    for (    EdgeWrapper e : neighborTable.values()) {
      edges[i]=e;
      i++;
    }
    network[index].node=node;
    network[index].setArray(edges);
    index++;
    Progress.progress(progress,++ProgressCount);
    if (isCanceled) {
      hgraph.readUnlockAll();
      return;
    }
  }
  Arrays.sort(network);
  for (int j=0; j < N; j++) {
    network[j].setID(j);
    Progress.progress(progress,++ProgressCount);
  }
  for (int j=0; j < N; j++) {
    Arrays.sort(network[j].getArray(),new Renumbering());
    Progress.progress(progress,++ProgressCount);
  }
  triangles=new int[N];
  K=(int)Math.sqrt(N);
  for (int v=0; v < K && v < N; v++) {
    newVertex(v);
    Progress.progress(progress,++ProgressCount);
  }
  for (int v=N - 1; (v >= 0) && (v >= K); v--) {
    for (int i=closest_in_array(v); i >= 0; i--) {
      int u=network[v].get(i);
      if (u >= K) {
        tr_link_nohigh(u,v,network[v].getCount(i));
      }
    }
    Progress.progress(progress,++ProgressCount);
    if (isCanceled) {
      hgraph.readUnlockAll();
      return;
    }
  }
  avgClusteringCoeff=0;
  AttributeTable nodeTable=attributeModel.getNodeTable();
  AttributeColumn clusteringCol=nodeTable.getColumn(CLUSTERING_COEFF);
  if (clusteringCol == null) {
    clusteringCol=nodeTable.addColumn(CLUSTERING_COEFF,"String_Node_Str",AttributeType.DOUBLE,AttributeOrigin.COMPUTED,new Double(0));
  }
  for (  Node s : hgraph.getNodes()) {
    int v=indicies.get(s);
    if (network[v].length() > 1) {
      double cc=triangles[v];
      totalTriangles+=triangles[v];
      cc/=(network[v].length() * (network[v].length() - 1));
      if (!isDirected) {
        cc*=2.0f;
      }
      nodeClustering[v]=cc;
      AttributeRow row=(AttributeRow)s.getNodeData().getAttributes();
      row.setValue(clusteringCol,cc);
      avgClusteringCoeff+=cc;
    }
    Progress.progress(progress,++ProgressCount);
    if (isCanceled) {
      hgraph.readUnlockAll();
      return;
    }
  }
  totalTriangles/=3;
  avgClusteringCoeff/=N;
  hgraph.readUnlock();
}