Program: 189784
Project: 189784
Buggy source:
public void execute(HierarchicalUndirectedGraph hgraph,AttributeModel attributeModel){
  isCanceled=false;
  Progress.start(progress);
  Random rand=new Random();
  hgraph.readLock();
  structure=new Modularity.CommunityStructure(hgraph);
  double totalWeight=structure.graphWeightSum;
  double[] nodeDegrees=structure.weights.clone();
  if (isCanceled) {
    hgraph.readUnlockAll();
    return;
  }
  boolean someChange=true;
  while (someChange) {
    someChange=false;
    boolean localChange=true;
    while (localChange) {
      localChange=false;
      int start=0;
      if (isRandomized) {
        start=Math.abs(rand.nextInt()) % structure.N;
      }
      int step=0;
      for (int i=start; step < structure.N; i=(i + 1) % structure.N) {
        step++;
        double best=0.;
        Community bestCommunity=null;
        Community nodecom=structure.nodeCommunities[i];
        Set<Community> iter=structure.nodeConnections[i].keySet();
        for (        Community com : iter) {
          double qValue=q(i,com);
          if (qValue > best) {
            best=qValue;
            bestCommunity=com;
          }
        }
        if ((structure.nodeCommunities[i] != bestCommunity) && (bestCommunity != null)) {
          structure.moveNodeTo(i,bestCommunity);
          localChange=true;
        }
        if (isCanceled) {
          hgraph.readUnlockAll();
          return;
        }
      }
      someChange=localChange || someChange;
      if (isCanceled) {
        hgraph.readUnlockAll();
        return;
      }
    }
    if (someChange) {
      structure.zoomOut();
    }
  }
  int[] comStructure=new int[hgraph.getNodeCount()];
  int count=0;
  double[] degreeCount=new double[structure.communities.size()];
  for (  Community com : structure.communities) {
    for (    Integer node : com.nodes) {
      Community hidden=structure.invMap.get(node);
      for (      Integer nodeInt : hidden.nodes) {
        comStructure[nodeInt]=count;
      }
    }
    count++;
  }
  for (  Node node : hgraph.getNodes()) {
    int index=structure.map.get(node);
    if (useWeight) {
      degreeCount[comStructure[index]]+=nodeDegrees[index];
    }
 else {
      degreeCount[comStructure[index]]+=hgraph.getTotalDegree(node);
    }
  }
  modularity=finalQ(comStructure,degreeCount,hgraph,attributeModel,totalWeight);
  hgraph.readUnlock();
}

Fixed version (ground truth):
public void execute(HierarchicalUndirectedGraph hgraph,AttributeModel attributeModel){
  isCanceled=false;
  Progress.start(progress);
  Random rand=new Random();
  hgraph.readLock();
  structure=new Modularity.CommunityStructure(hgraph);
  double totalWeight=structure.graphWeightSum;
  double[] nodeDegrees=structure.weights.clone();
  if (isCanceled) {
    hgraph.readUnlockAll();
    return;
  }
  boolean someChange=true;
  while (someChange) {
    someChange=false;
    boolean localChange=true;
    while (localChange) {
      localChange=false;
      int start=0;
      if (isRandomized) {
        start=Math.abs(rand.nextInt()) % structure.N;
      }
      int step=0;
      for (int i=start; step < structure.N; i=(i + 1) % structure.N) {
        step++;
        double best=0.;
        Community bestCommunity=null;
        Community nodecom=structure.nodeCommunities[i];
        Set<Community> iter=structure.nodeConnectionsWeight[i].keySet();
        for (        Community com : iter) {
          double qValue=q(i,com);
          if (qValue > best) {
            best=qValue;
            bestCommunity=com;
          }
        }
        if ((structure.nodeCommunities[i] != bestCommunity) && (bestCommunity != null)) {
          structure.moveNodeTo(i,bestCommunity);
          localChange=true;
        }
        if (isCanceled) {
          hgraph.readUnlockAll();
          return;
        }
      }
      someChange=localChange || someChange;
      if (isCanceled) {
        hgraph.readUnlockAll();
        return;
      }
    }
    if (someChange) {
      structure.zoomOut();
    }
  }
  int[] comStructure=new int[hgraph.getNodeCount()];
  int count=0;
  double[] degreeCount=new double[structure.communities.size()];
  for (  Community com : structure.communities) {
    for (    Integer node : com.nodes) {
      Community hidden=structure.invMap.get(node);
      for (      Integer nodeInt : hidden.nodes) {
        comStructure[nodeInt]=count;
      }
    }
    count++;
  }
  for (  Node node : hgraph.getNodes()) {
    int index=structure.map.get(node);
    if (useWeight) {
      degreeCount[comStructure[index]]+=nodeDegrees[index];
    }
 else {
      degreeCount[comStructure[index]]+=hgraph.getTotalDegree(node);
    }
  }
  modularity=finalQ(comStructure,degreeCount,hgraph,attributeModel,totalWeight);
  hgraph.readUnlock();
}