Program: 189876
Project: 189876
Buggy source:
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();
}

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));
  }
  AttributeColumn triCount=nodeTable.getColumn("String_Node_Str");
  if (triCount == null) {
    triCount=nodeTable.addColumn("String_Node_Str","String_Node_Str",AttributeType.INT,AttributeOrigin.COMPUTED,new Integer(0));
  }
  for (int v=0; v < N; v++) {
    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)network[v].node.getNodeData().getAttributes();
      row.setValue(clusteringCol,cc);
      row.setValue(triCount,triangles[v]);
      avgClusteringCoeff+=cc;
    }
    Progress.progress(progress,++ProgressCount);
    if (isCanceled) {
      hgraph.readUnlockAll();
      return;
    }
  }
  totalTriangles/=3;
  avgClusteringCoeff/=N;
  hgraph.readUnlock();
}