Program: 9674
Project: 9674
Buggy source:
private String computeQuestionOptimized(QueryTree<N> lgg,List<QueryTree<N>> negTrees,List<String> knownResources) throws TimeOutException {
  startTime=System.currentTimeMillis();
  this.lgg=lgg;
  this.negTrees=negTrees;
  determiningNodeIds=getDeterminingNodeIds(lgg,negTrees);
  logger.info("String_Node_Str");
  postLGG=getFilteredTree(lgg);
  PostLGG<N> postGen=new PostLGG<N>((SPARQLEndpointEx)endpoint);
  postGen.simplifyTree(postLGG,negTrees);
  logger.info("String_Node_Str" + TreeHelper.getAbbreviatedTreeRepresentation(postLGG,endpoint.getBaseURI(),endpoint.getPrefixes()));
  logger.info("String_Node_Str" + postLGG.toSPARQLQueryString());
  logger.info("String_Node_Str" + getAllResources(postLGG.toSPARQLQueryString()).size());
  limit=knownResources.size();
  List<GeneralisedQueryTree<N>> queue=null;
  if (generalizeSortedByNegatives) {
    queue=getAllowedGeneralisationsSortedByMatrix(new GeneralisedQueryTree<N>(postLGG),negTrees);
  }
 else {
    queue=getAllowedGeneralisationsSorted(new GeneralisedQueryTree<N>(postLGG));
  }
  logger.debug(getQueueLogInfo(queue));
  GeneralisedQueryTree<N> tree1;
  QueryTree<N> tree2;
  GeneralisedQueryTree<N> tmp;
  List<GeneralisedQueryTree<N>> gens;
  List<QueryTree<N>> neededGeneralisations;
  while (!queue.isEmpty()) {
    neededGeneralisations=new ArrayList<QueryTree<N>>();
    logger.debug("String_Node_Str");
    tree1=queue.remove(0);
    tmp=tree1;
    if (logger.isDebugEnabled()) {
      logger.debug("String_Node_Str" + tmp.getChanges());
    }
    boolean coversNegTree=coversNegativeTree(tmp.getQueryTree(),negTrees);
    neededGeneralisations.add(tmp.getQueryTree());
    logger.debug("String_Node_Str" + coversNegTree);
    while (!coversNegTree) {
      if (generalizeSortedByNegatives) {
        gens=getAllowedGeneralisationsSortedByMatrix(tmp,negTrees);
      }
 else {
        gens=getAllowedGeneralisationsSorted(tmp);
      }
      if (gens.isEmpty()) {
        if (logger.isDebugEnabled()) {
          logger.debug("String_Node_Str");
        }
        break;
      }
      tmp=gens.remove(0);
      neededGeneralisations.add(tmp.getQueryTree());
      if (logger.isDebugEnabled()) {
        logger.debug("String_Node_Str" + tmp.getChanges());
      }
      queue.addAll(0,gens);
      logger.debug(getQueueLogInfo(queue));
      coversNegTree=coversNegativeTree(tmp.getQueryTree(),negTrees);
      if (coversNegTree) {
        logger.debug("String_Node_Str");
      }
    }
    int index=neededGeneralisations.size() - 1;
    if (coversNegTree) {
      tree2=neededGeneralisations.get(index--);
    }
 else {
      tree2=tmp.getQueryTree();
    }
    String newResource=getNewResource(tree2,knownResources);
    if (isTerminationCriteriaReached()) {
      throw new TimeOutException(maxExecutionTimeInSeconds);
    }
    logger.debug("String_Node_Str" + newResource);
    if (!(newResource == null)) {
      logger.debug("String_Node_Str");
      newResource=findMostSpecificResourceTree(neededGeneralisations,knownResources,0,neededGeneralisations.size() - 1);
      logger.debug("String_Node_Str");
      return newResource;
    }
 else {
      if (logger.isDebugEnabled()) {
        logger.debug("String_Node_Str");
      }
    }
  }
  return null;
}

Fixed version (ground truth):
private String computeQuestionOptimized(QueryTree<N> lgg,List<QueryTree<N>> negTrees,List<String> knownResources) throws TimeOutException {
  startTime=System.currentTimeMillis();
  this.lgg=lgg;
  this.negTrees=negTrees;
  determiningNodeIds=getDeterminingNodeIds(lgg,negTrees);
  logger.info("String_Node_Str");
  postLGG=getFilteredTree(lgg);
  PostLGG<N> postGen=new PostLGG<N>((SPARQLEndpointEx)endpoint);
  postGen.simplifyTree(postLGG,negTrees);
  logger.info("String_Node_Str" + TreeHelper.getAbbreviatedTreeRepresentation(postLGG,endpoint.getBaseURI(),endpoint.getPrefixes()));
  logger.info("String_Node_Str" + postLGG.toSPARQLQueryString());
  logger.info("String_Node_Str" + getAllResources(postLGG.toSPARQLQueryString()).size());
  limit=knownResources.size();
  List<GeneralisedQueryTree<N>> queue=null;
  if (generalizeSortedByNegatives) {
    queue=getAllowedGeneralisationsSortedByMatrix(new GeneralisedQueryTree<N>(postLGG),negTrees);
  }
 else {
    queue=getAllowedGeneralisationsSorted(new GeneralisedQueryTree<N>(postLGG));
  }
  logger.debug(getQueueLogInfo(queue));
  GeneralisedQueryTree<N> tree1;
  QueryTree<N> tree2;
  GeneralisedQueryTree<N> tmp;
  List<GeneralisedQueryTree<N>> gens;
  List<QueryTree<N>> neededGeneralisations;
  while (!queue.isEmpty()) {
    neededGeneralisations=new ArrayList<QueryTree<N>>();
    logger.debug("String_Node_Str");
    tree1=queue.remove(0);
    tmp=tree1;
    if (logger.isDebugEnabled()) {
      logger.debug("String_Node_Str" + tmp.getChanges());
    }
    boolean coversNegTree=coversNegativeTree(tmp.getQueryTree(),negTrees);
    neededGeneralisations.add(tmp.getQueryTree());
    logger.debug("String_Node_Str" + coversNegTree);
    while (!coversNegTree) {
      if (generalizeSortedByNegatives) {
        gens=getAllowedGeneralisationsSortedByMatrix(tmp,negTrees);
      }
 else {
        gens=getAllowedGeneralisationsSorted(tmp);
      }
      if (gens.isEmpty()) {
        if (logger.isDebugEnabled()) {
          logger.debug("String_Node_Str");
        }
        break;
      }
      tmp=gens.remove(0);
      if (logger.isDebugEnabled()) {
        logger.debug("String_Node_Str" + tmp.getChanges());
      }
      queue.addAll(0,gens);
      logger.debug(getQueueLogInfo(queue));
      coversNegTree=coversNegativeTree(tmp.getQueryTree(),negTrees);
      if (coversNegTree) {
        logger.debug("String_Node_Str");
      }
 else {
        neededGeneralisations.add(tmp.getQueryTree());
      }
    }
    int index=neededGeneralisations.size() - 1;
    if (coversNegTree) {
      tree2=neededGeneralisations.get(index--);
    }
 else {
      tree2=tmp.getQueryTree();
    }
    String newResource=getNewResource(tree2,knownResources);
    if (isTerminationCriteriaReached()) {
      throw new TimeOutException(maxExecutionTimeInSeconds);
    }
    logger.debug("String_Node_Str" + newResource);
    if (!(newResource == null)) {
      logger.debug("String_Node_Str");
      newResource=findMostSpecificResourceTree(neededGeneralisations,knownResources,0,neededGeneralisations.size() - 1);
      logger.debug("String_Node_Str");
      return newResource;
    }
 else {
      if (logger.isDebugEnabled()) {
        logger.debug("String_Node_Str");
      }
    }
  }
  return null;
}