Program: 13277
Project: 13277
Buggy source:
/** 
 * collect data on shard or doc level collects data from each shard in a separate thread, collecting the data into a single state through an   {@link java.util.concurrent.ArrayBlockingQueue}.
 * @param collectNode {@link io.crate.planner.node.CollectNode} containing routing information and symbols to collect
 * @return the collect results from all shards on this node that were given in {@link io.crate.planner.plan.CollectNode#routing}
 */
protected ListenableFuture<Object[][]> handleShardCollect(CollectNode collectNode){
  Function whereClause=collectNode.whereClause();
  if (whereClause != null && NormalizationHelper.evaluatesToFalse(whereClause,this.normalizer)) {
    SettableFuture<Object[][]> result=SettableFuture.create();
    result.set(Constants.EMPTY_RESULT);
    return result;
  }
  String localNodeId=clusterService.localNode().id();
  final int numShards=collectNode.routing().numShards(localNodeId);
  List<CrateCollector> shardCollectors=new ArrayList<>(numShards);
  List<Projector> projectors=extractProjectors(collectNode);
  final ShardCollectFuture result=getShardCollectFuture(numShards,projectors,collectNode);
  Map<String,Set<Integer>> shardIdMap=collectNode.routing().locations().get(localNodeId);
  for (  Map.Entry<String,Set<Integer>> entry : shardIdMap.entrySet()) {
    IndexService indexService;
    try {
      indexService=indicesService.indexServiceSafe(entry.getKey());
    }
 catch (    IndexMissingException e) {
      throw new TableUnknownException(entry.getKey(),e);
    }
    for (    Integer shardId : entry.getValue()) {
      Injector shardInjector;
      try {
        shardInjector=indexService.shardInjectorSafe(shardId);
        ShardCollectService shardCollectService=shardInjector.getInstance(ShardCollectService.class);
        CrateCollector crateCollector=shardCollectService.getCollector(collectNode,projectors.get(0));
        shardCollectors.add(crateCollector);
      }
 catch (      IndexShardMissingException e) {
        throw new CrateException(String.format("String_Node_Str",shardId,entry.getKey()));
      }
catch (      Exception e) {
        logger.error("String_Node_Str",e);
        throw new CrateException(e);
      }
    }
  }
  for (  final CrateCollector shardCollector : shardCollectors) {
    threadPool.executor(ThreadPool.Names.SEARCH).execute(new Runnable(){
      @Override public void run(){
        shardCollector.doCollect();
        result.shardFinished();
        if (logger.isTraceEnabled()) {
          logger.trace("String_Node_Str",result.numShards());
        }
      }
    }
);
  }
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str",numShards);
  }
  return result;
}

Fixed version (ground truth):
/** 
 * collect data on shard or doc level collects data from each shard in a separate thread, collecting the data into a single state through an   {@link java.util.concurrent.ArrayBlockingQueue}.
 * @param collectNode {@link io.crate.planner.node.CollectNode} containing routing information and symbols to collect
 * @return the collect results from all shards on this node that were given in {@link io.crate.planner.plan.CollectNode#routing}
 */
protected ListenableFuture<Object[][]> handleShardCollect(CollectNode collectNode){
  String localNodeId=clusterService.localNode().id();
  final int numShards=collectNode.routing().numShards(localNodeId);
  List<CrateCollector> shardCollectors=new ArrayList<>(numShards);
  List<Projector> projectors=extractProjectors(collectNode);
  final ShardCollectFuture result=getShardCollectFuture(numShards,projectors,collectNode);
  Function whereClause=collectNode.whereClause();
  if (whereClause != null && NormalizationHelper.evaluatesToFalse(whereClause,this.normalizer)) {
    result.onAllShardsFinished();
    return result;
  }
  Map<String,Set<Integer>> shardIdMap=collectNode.routing().locations().get(localNodeId);
  for (  Map.Entry<String,Set<Integer>> entry : shardIdMap.entrySet()) {
    IndexService indexService;
    try {
      indexService=indicesService.indexServiceSafe(entry.getKey());
    }
 catch (    IndexMissingException e) {
      throw new TableUnknownException(entry.getKey(),e);
    }
    for (    Integer shardId : entry.getValue()) {
      Injector shardInjector;
      try {
        shardInjector=indexService.shardInjectorSafe(shardId);
        ShardCollectService shardCollectService=shardInjector.getInstance(ShardCollectService.class);
        CrateCollector crateCollector=shardCollectService.getCollector(collectNode,projectors.get(0));
        shardCollectors.add(crateCollector);
      }
 catch (      IndexShardMissingException e) {
        throw new CrateException(String.format("String_Node_Str",shardId,entry.getKey()));
      }
catch (      Exception e) {
        logger.error("String_Node_Str",e);
        throw new CrateException(e);
      }
    }
  }
  for (  final CrateCollector shardCollector : shardCollectors) {
    threadPool.executor(ThreadPool.Names.SEARCH).execute(new Runnable(){
      @Override public void run(){
        shardCollector.doCollect();
        result.shardFinished();
        if (logger.isTraceEnabled()) {
          logger.trace("String_Node_Str",result.numShards());
        }
      }
    }
);
  }
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str",numShards);
  }
  return result;
}