Program: 189871
Project: 189871
Buggy source:
public void execute(HierarchicalUndirectedGraph hgraph,AttributeModel attributeModel){
  isCanceled=false;
  Progress.start(progress);
  Random rand=new Random();
  hgraph.readLock();
  structure=new CommunityStructure(hgraph);
  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;
        double current=q(i,structure.nodeCommunities[i]);
        Community bestCommunity=null;
        int smallest=Integer.MAX_VALUE;
        Set<Community> iter=structure.nodeConnections[i].keySet();
        for (        Community com : iter) {
          double qValue=q(i,com) - current;
          if (qValue > best) {
            best=qValue;
            bestCommunity=com;
            smallest=com.getMin();
          }
 else           if ((qValue == best) && (com.getMin() < smallest)) {
            best=qValue;
            bestCommunity=com;
            smallest=com.getMin();
          }
        }
        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);
    degreeCount[comStructure[index]]+=hgraph.getTotalDegree(node);
  }
  modularity=finalQ(comStructure,degreeCount,hgraph,attributeModel);
  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 CommunityStructure(hgraph);
  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);
    degreeCount[comStructure[index]]+=hgraph.getTotalDegree(node);
  }
  modularity=finalQ(comStructure,degreeCount,hgraph,attributeModel);
  hgraph.readUnlock();
}