Program: 168933
Project: 168933
Buggy source:
/** 
 * Builds the clauses needed for the group by clause for a query that uses aggregate functions to work.
 * @param m
 * @return
 */
void buildGroupByClauses(final Metamodel m,Set<String> clauses){
  boolean conditionalContext=queryGenerator.setConditionalContext(false);
  StringBuilder sb=new StringBuilder();
  Set<PathExpression> componentPaths=new LinkedHashSet<PathExpression>();
  EntitySelectResolveVisitor resolveVisitor=new EntitySelectResolveVisitor(m,componentPaths);
  if (selectInfos.isEmpty()) {
    List<JoinNode> roots=joinManager.getRoots();
    if (roots.size() > 1) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    JoinNode rootNode=roots.get(0);
    String rootAlias=rootNode.getAliasInfo().getAlias();
    List<PathElementExpression> path=Arrays.asList((PathElementExpression)new PropertyExpression(rootAlias));
    resolveVisitor.visit(new PathExpression(path,new SimplePathReference(rootNode,null),false,false));
    for (    PathExpression pathExpr : componentPaths) {
      sb.setLength(0);
      queryGenerator.setQueryBuffer(sb);
      pathExpr.accept(queryGenerator);
      clauses.add(sb.toString());
    }
  }
 else {
    List<SelectInfo> infos=selectInfos;
    int size=selectInfos.size();
    for (int i=0; i < size; i++) {
      final SelectInfo selectInfo=infos.get(i);
      selectInfo.getExpression().accept(resolveVisitor);
      if (componentPaths.size() > 0) {
        for (        PathExpression pathExpr : componentPaths) {
          sb.setLength(0);
          queryGenerator.setQueryBuffer(sb);
          pathExpr.accept(queryGenerator);
          clauses.add(sb.toString());
        }
      }
 else {
        GroupByUsableDetectionVisitor groupByUsableDetectionVisitor=new GroupByUsableDetectionVisitor();
        if (!Boolean.TRUE.equals(selectInfo.getExpression().accept(groupByUsableDetectionVisitor))) {
          sb.setLength(0);
          queryGenerator.setQueryBuffer(sb);
          selectInfo.getExpression().accept(queryGenerator);
          clauses.add(sb.toString());
        }
      }
    }
  }
  queryGenerator.setConditionalContext(conditionalContext);
}

Fixed version (ground truth):
/** 
 * Builds the clauses needed for the group by clause for a query that uses aggregate functions to work.
 * @param m
 * @return
 */
void buildGroupByClauses(final Metamodel m,Set<String> clauses){
  boolean conditionalContext=queryGenerator.setConditionalContext(false);
  StringBuilder sb=new StringBuilder();
  Set<PathExpression> componentPaths=new LinkedHashSet<PathExpression>();
  EntitySelectResolveVisitor resolveVisitor=new EntitySelectResolveVisitor(m,componentPaths);
  if (selectInfos.isEmpty()) {
    List<JoinNode> roots=joinManager.getRoots();
    if (roots.size() > 1) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    JoinNode rootNode=roots.get(0);
    String rootAlias=rootNode.getAliasInfo().getAlias();
    List<PathElementExpression> path=Arrays.asList((PathElementExpression)new PropertyExpression(rootAlias));
    resolveVisitor.visit(new PathExpression(path,new SimplePathReference(rootNode,null),false,false));
    for (    PathExpression pathExpr : componentPaths) {
      sb.setLength(0);
      queryGenerator.setQueryBuffer(sb);
      pathExpr.accept(queryGenerator);
      clauses.add(sb.toString());
    }
  }
 else {
    List<SelectInfo> infos=selectInfos;
    int size=selectInfos.size();
    for (int i=0; i < size; i++) {
      final SelectInfo selectInfo=infos.get(i);
      componentPaths.clear();
      selectInfo.getExpression().accept(resolveVisitor);
      if (componentPaths.size() > 0) {
        for (        PathExpression pathExpr : componentPaths) {
          sb.setLength(0);
          queryGenerator.setQueryBuffer(sb);
          pathExpr.accept(queryGenerator);
          clauses.add(sb.toString());
        }
      }
 else {
        GroupByUsableDetectionVisitor groupByUsableDetectionVisitor=new GroupByUsableDetectionVisitor();
        if (!Boolean.TRUE.equals(selectInfo.getExpression().accept(groupByUsableDetectionVisitor))) {
          sb.setLength(0);
          queryGenerator.setQueryBuffer(sb);
          selectInfo.getExpression().accept(queryGenerator);
          clauses.add(sb.toString());
        }
      }
    }
  }
  queryGenerator.setConditionalContext(conditionalContext);
}