Program: 20157
Project: 20157
Buggy source:
/** 
 * Executes the algorithm on the graph set earlier by setGraph()
 */
public void run() throws ClusterONEException {
  Double minDensity=parameters.getMinDensity();
  AbstractNodeSetMerger merger;
  Seed seed;
  ValuedNodeSet cluster;
  Ordered<ValuedNodeSet> orderedCluster;
  State state;
  UsedNodeSet usedNodes;
  int numGeneratedSeeds;
  int numPostedSeeds;
  int numProcessedClusters;
  ValuedNodeSetList result=new ValuedNodeSetList();
  List<Seed> submittedSeeds=new ArrayList<Seed>();
  List<Ordered<ValuedNodeSet>> tmpList=new ArrayList<Ordered<ValuedNodeSet>>();
  HashSet<NodeSet> addedNodeSets=new HashSet<NodeSet>();
  if (ArrayUtils.min(graph.getEdgeWeights()) < 0.0)   throw new ClusterONEException("String_Node_Str");
  try {
    merger=AbstractNodeSetMerger.fromString(parameters.getMergingMethodName());
  }
 catch (  InstantiationException ex) {
    throw new ClusterONEException(ex.getMessage());
  }
  if (minDensity == null) {
    monitor.setStatus("String_Node_Str");
    monitor.setPercentCompleted(0);
    if (graph.isWeighted())     minDensity=0.3;
 else {
      TransitivityCalculator calc=new TransitivityCalculator(graph);
      if (calc.getGlobalTransitivity() < 0.1)       minDensity=0.6;
 else       minDensity=0.5;
    }
    monitor.setPercentCompleted(100);
  }
  int numThreads=parameters.getNumThreads();
  if (numThreads <= 0) {
    numThreads=Math.max(1,Runtime.getRuntime().availableProcessors());
  }
  ExecutorService executor=Executors.newFixedThreadPool(numThreads);
  LinkedBlockingQueue<Ordered<Seed>> seedQueue=new LinkedBlockingQueue<Ordered<Seed>>(numThreads);
  LinkedBlockingQueue<Ordered<ValuedNodeSet>> clusterQueue=new LinkedBlockingQueue<Ordered<ValuedNodeSet>>();
  for (int i=0; i < numThreads; i++) {
    ClusterGrowthWorker worker=new ClusterGrowthWorker(graph,parameters,minDensity,seedQueue,clusterQueue);
    worker.setDebugMode(debugMode);
    executor.execute(worker);
  }
  SeedGenerator seedGenerator=parameters.getSeedGenerator();
  seedGenerator.setGraph(graph);
  usedNodes=new UsedNodeSet(graph);
  if (numThreads > 1) {
    monitor.setStatus("String_Node_Str" + numThreads + "String_Node_Str");
  }
 else {
    monitor.setStatus("String_Node_Str");
  }
  monitor.setPercentCompleted(0);
  SeedIterator it=seedGenerator.iterator();
  numGeneratedSeeds=0;
  numPostedSeeds=0;
  numProcessedClusters=0;
  state=State.START;
  while (!state.isTerminal) {
switch (state) {
case START:
      state=State.GENERATING_SEEDS;
    break;
case GENERATING_SEEDS:
  boolean seedAccepted=false;
seed=null;
while (!seedAccepted) {
if (it.hasNext()) {
  seed=it.next();
  numGeneratedSeeds++;
}
 else {
  seed=null;
}
seedAccepted=(seed == null || !parameters.shouldRejectSeedsWithOnlyUsedNodes() || !usedNodes.areAllNodesUsedFromSeed(seed));
}
if (seed == null) {
state=State.NOTIFYING_WORKERS_NO_MORE_SEEDS;
}
 else {
if (seedQueue.offer(new Ordered<Seed>(numPostedSeeds,seed))) {
usedNodes.markSeedAsUsed(seed);
numPostedSeeds++;
submittedSeeds.add(seed);
}
}
break;
case NOTIFYING_WORKERS_NO_MORE_SEEDS:
if (seedQueue.offer(new Ordered<Seed>(numPostedSeeds,ClusterGrowthWorker.NO_MORE_SEEDS))) {
state=State.WAITING_FOR_CLUSTERS;
}
break;
case WAITING_FOR_CLUSTERS:
if (numPostedSeeds == numProcessedClusters) {
state=State.FINISHED;
}
break;
case FINISHED:
case CANCELLED:
}
if (shouldStop) {
state=State.CANCELLED;
}
if (state == State.GENERATING_SEEDS || state == State.NOTIFYING_WORKERS_NO_MORE_SEEDS || state == State.WAITING_FOR_CLUSTERS) {
orderedCluster=null;
if (numProcessedClusters < numPostedSeeds) {
try {
orderedCluster=clusterQueue.take();
}
 catch (InterruptedException ignored) {
}
}
if (orderedCluster != null) {
cluster=orderedCluster.object;
if (cluster != ClusterGrowthWorker.EMPTY_CLUSTER) {
if (!addedNodeSets.contains(cluster)) {
tmpList.add(orderedCluster);
addedNodeSets.add(cluster);
usedNodes.markNodeSetAsUsed(cluster);
}
}
numProcessedClusters++;
}
}
monitor.setPercentCompleted((int)(numGeneratedSeeds * 100.0 / it.getEstimatedLength()));
if (shouldStop) {
state=State.CANCELLED;
}
}
addedNodeSets.clear();
if (state == State.FINISHED) {
Collections.sort(tmpList);
if (parameters.shouldRejectSeedsWithOnlyUsedNodes()) {
int seqNumber=0;
usedNodes.clear();
for (Ordered<ValuedNodeSet> orderedCluster2 : tmpList) {
while (seqNumber < orderedCluster2.sequenceNumber) {
usedNodes.markSeedAsUsed(submittedSeeds.get(seqNumber));
seqNumber++;
}
seed=submittedSeeds.get(seqNumber);
if (usedNodes.areAllNodesUsedFromSeed(seed)) {
continue;
}
usedNodes.markSeedAsUsed(seed);
usedNodes.markNodeSetAsUsed(orderedCluster2.object);
result.add(orderedCluster2.object);
}
}
 else {
for (Ordered<ValuedNodeSet> nodeSet : tmpList) {
result.add(nodeSet.object);
}
}
merger.setTaskMonitor(monitor);
this.result=merger.mergeOverlapping(result,parameters.getSimilarityFunction(),parameters.getOverlapThreshold());
}
executor.shutdown();
while (true) {
try {
executor.awaitTermination(1,TimeUnit.DAYS);
break;
}
 catch (InterruptedException ignored) {
}
}
}

Fixed version (ground truth):
/** 
 * Executes the algorithm on the graph set earlier by setGraph()
 */
public void run() throws ClusterONEException {
  Double minDensity=parameters.getMinDensity();
  AbstractNodeSetMerger merger;
  Seed seed;
  Seed pendingSeed=null;
  ValuedNodeSet cluster;
  Ordered<ValuedNodeSet> orderedCluster;
  State state;
  UsedNodeSet usedNodes;
  int numGeneratedSeeds;
  int numPostedSeeds;
  int numProcessedClusters;
  ValuedNodeSetList result=new ValuedNodeSetList();
  List<Seed> submittedSeeds=new ArrayList<Seed>();
  List<Ordered<ValuedNodeSet>> tmpList=new ArrayList<Ordered<ValuedNodeSet>>();
  HashSet<NodeSet> addedNodeSets=new HashSet<NodeSet>();
  if (ArrayUtils.min(graph.getEdgeWeights()) < 0.0)   throw new ClusterONEException("String_Node_Str");
  try {
    merger=AbstractNodeSetMerger.fromString(parameters.getMergingMethodName());
  }
 catch (  InstantiationException ex) {
    throw new ClusterONEException(ex.getMessage());
  }
  if (minDensity == null) {
    monitor.setStatus("String_Node_Str");
    monitor.setPercentCompleted(0);
    if (graph.isWeighted())     minDensity=0.3;
 else {
      TransitivityCalculator calc=new TransitivityCalculator(graph);
      if (calc.getGlobalTransitivity() < 0.1)       minDensity=0.6;
 else       minDensity=0.5;
    }
    monitor.setPercentCompleted(100);
  }
  int numThreads=parameters.getNumThreads();
  if (numThreads <= 0) {
    numThreads=Math.max(1,Runtime.getRuntime().availableProcessors());
  }
  ExecutorService executor=Executors.newFixedThreadPool(numThreads);
  LinkedBlockingQueue<Ordered<Seed>> seedQueue=new LinkedBlockingQueue<Ordered<Seed>>(numThreads);
  LinkedBlockingQueue<Ordered<ValuedNodeSet>> clusterQueue=new LinkedBlockingQueue<Ordered<ValuedNodeSet>>();
  for (int i=0; i < numThreads; i++) {
    ClusterGrowthWorker worker=new ClusterGrowthWorker(graph,parameters,minDensity,seedQueue,clusterQueue);
    worker.setDebugMode(debugMode);
    executor.execute(worker);
  }
  SeedGenerator seedGenerator=parameters.getSeedGenerator();
  seedGenerator.setGraph(graph);
  usedNodes=new UsedNodeSet(graph);
  if (numThreads > 1) {
    monitor.setStatus("String_Node_Str" + numThreads + "String_Node_Str");
  }
 else {
    monitor.setStatus("String_Node_Str");
  }
  monitor.setPercentCompleted(0);
  SeedIterator it=seedGenerator.iterator();
  numGeneratedSeeds=0;
  numPostedSeeds=0;
  numProcessedClusters=0;
  state=State.START;
  while (!state.isTerminal) {
switch (state) {
case START:
      state=State.GENERATING_SEEDS;
    break;
case GENERATING_SEEDS:
  boolean shouldEnqueue=true;
while (shouldEnqueue) {
  boolean seedAccepted=false;
  seed=null;
  while (!seedAccepted) {
    if (pendingSeed != null) {
      seed=pendingSeed;
      numGeneratedSeeds++;
      pendingSeed=null;
    }
 else     if (it.hasNext()) {
      seed=it.next();
      numGeneratedSeeds++;
    }
 else {
      seed=null;
    }
    seedAccepted=(seed == null || !parameters.shouldRejectSeedsWithOnlyUsedNodes() || !usedNodes.areAllNodesUsedFromSeed(seed));
  }
  if (seed == null) {
    state=State.NOTIFYING_WORKERS_NO_MORE_SEEDS;
    shouldEnqueue=false;
  }
 else {
    if (seedQueue.offer(new Ordered<Seed>(numPostedSeeds,seed))) {
      usedNodes.markSeedAsUsed(seed);
      numPostedSeeds++;
      submittedSeeds.add(seed);
    }
 else {
      pendingSeed=seed;
      numGeneratedSeeds--;
      shouldEnqueue=false;
    }
  }
}
break;
case NOTIFYING_WORKERS_NO_MORE_SEEDS:
if (seedQueue.offer(new Ordered<Seed>(numPostedSeeds,ClusterGrowthWorker.NO_MORE_SEEDS))) {
state=State.WAITING_FOR_CLUSTERS;
}
break;
case WAITING_FOR_CLUSTERS:
if (numPostedSeeds == numProcessedClusters) {
state=State.FINISHED;
}
break;
case FINISHED:
case CANCELLED:
}
if (shouldStop) {
state=State.CANCELLED;
}
if (state == State.GENERATING_SEEDS || state == State.NOTIFYING_WORKERS_NO_MORE_SEEDS || state == State.WAITING_FOR_CLUSTERS) {
orderedCluster=null;
if (numProcessedClusters < numPostedSeeds) {
try {
orderedCluster=clusterQueue.take();
}
 catch (InterruptedException ignored) {
}
}
if (orderedCluster != null) {
cluster=orderedCluster.object;
if (cluster != ClusterGrowthWorker.EMPTY_CLUSTER) {
if (!addedNodeSets.contains(cluster)) {
tmpList.add(orderedCluster);
addedNodeSets.add(cluster);
usedNodes.markNodeSetAsUsed(cluster);
}
}
numProcessedClusters++;
}
}
monitor.setPercentCompleted((int)(numGeneratedSeeds * 100.0 / it.getEstimatedLength()));
if (shouldStop) {
state=State.CANCELLED;
}
}
addedNodeSets.clear();
if (state == State.FINISHED) {
Collections.sort(tmpList);
if (parameters.shouldRejectSeedsWithOnlyUsedNodes()) {
int seqNumber=0;
usedNodes.clear();
for (Ordered<ValuedNodeSet> orderedCluster2 : tmpList) {
while (seqNumber < orderedCluster2.sequenceNumber) {
usedNodes.markSeedAsUsed(submittedSeeds.get(seqNumber));
seqNumber++;
}
seed=submittedSeeds.get(seqNumber);
if (usedNodes.areAllNodesUsedFromSeed(seed)) {
continue;
}
usedNodes.markSeedAsUsed(seed);
usedNodes.markNodeSetAsUsed(orderedCluster2.object);
result.add(orderedCluster2.object);
}
}
 else {
for (Ordered<ValuedNodeSet> nodeSet : tmpList) {
result.add(nodeSet.object);
}
}
merger.setTaskMonitor(monitor);
this.result=merger.mergeOverlapping(result,parameters.getSimilarityFunction(),parameters.getOverlapThreshold());
}
executor.shutdown();
while (true) {
try {
executor.awaitTermination(1,TimeUnit.DAYS);
break;
}
 catch (InterruptedException ignored) {
}
}
}