Program: 168817
Project: 168817
Buggy source:
Set<JoinNode> buildClause(StringBuilder sb,Set<ClauseType> clauseExclusions,String aliasPrefix,boolean collectCollectionJoinNodes,boolean externalRepresenation,List<String> whereConjuncts){
  final boolean renderFetches=!clauseExclusions.contains(ClauseType.SELECT);
  StringBuilder tempSb=null;
  collectionJoinNodes.clear();
  renderedJoins.clear();
  sb.append("String_Node_Str");
  List<JoinNode> nodes=rootNodes;
  int size=nodes.size();
  for (int i=0; i < size; i++) {
    if (i != 0) {
      sb.append("String_Node_Str");
    }
    JoinNode rootNode=nodes.get(i);
    JoinNode correlationParent=rootNode.getCorrelationParent();
    if (externalRepresenation && rootNode.getValueCount() > 0) {
      ManagedType<?> type=metamodel.getManagedType(rootNode.getPropertyClass());
      final int attributeCount=rootNode.getAttributeCount();
      if (rootNode.getPropertyClass() != ValuesEntity.class) {
        if (type instanceof EntityType<?>) {
          sb.append(((EntityType)type).getName());
        }
 else {
          sb.append(type.getJavaType().getSimpleName());
        }
      }
      sb.append("String_Node_Str");
      for (int valueNumber=0; valueNumber < rootNode.getValueCount(); valueNumber++) {
        sb.append("String_Node_Str");
        for (int j=0; j < attributeCount; j++) {
          sb.append("String_Node_Str");
        }
        sb.setCharAt(sb.length() - 1,')');
        sb.append(',');
      }
      sb.setCharAt(sb.length() - 1,')');
    }
 else {
      if (correlationParent != null) {
        sb.append(correlationParent.getAliasInfo().getAlias());
        sb.append('.');
        sb.append(rootNode.getCorrelationPath());
      }
 else {
        EntityType<?> type=metamodel.entity(rootNode.getPropertyClass());
        sb.append(type.getName());
      }
    }
    sb.append(' ');
    if (aliasPrefix != null) {
      sb.append(aliasPrefix);
    }
    sb.append(rootNode.getAliasInfo().getAlias());
    rootNode.registerDependencies();
    applyJoins(sb,rootNode.getAliasInfo(),rootNode.getNodes(),clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches);
    if (!rootNode.getEntityJoinNodes().isEmpty()) {
      boolean isCollection=true;
      if (mainQuery.jpaProvider.supportsEntityJoin()) {
        applyJoins(sb,rootNode.getAliasInfo(),new ArrayList<JoinNode>(rootNode.getEntityJoinNodes()),isCollection,clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches);
      }
 else {
        Set<JoinNode> entityNodes=rootNode.getEntityJoinNodes();
        for (        JoinNode entityNode : entityNodes) {
          if (collectCollectionJoinNodes && isCollection) {
            collectionJoinNodes.add(entityNode);
          }
          sb.append("String_Node_Str");
          EntityType<?> type=metamodel.entity(entityNode.getPropertyClass());
          sb.append(type.getName());
          sb.append(' ');
          if (aliasPrefix != null) {
            sb.append(aliasPrefix);
          }
          sb.append(entityNode.getAliasInfo().getAlias());
          entityNode.registerDependencies();
          if (entityNode.getOnPredicate() != null && !entityNode.getOnPredicate().getChildren().isEmpty()) {
            if (tempSb == null) {
              tempSb=new StringBuilder();
            }
 else {
              tempSb.setLength(0);
            }
            queryGenerator.setQueryBuffer(tempSb);
            SimpleQueryGenerator.BooleanLiteralRenderingContext oldBooleanLiteralRenderingContext=queryGenerator.setBooleanLiteralRenderingContext(SimpleQueryGenerator.BooleanLiteralRenderingContext.PREDICATE);
            entityNode.getOnPredicate().accept(queryGenerator);
            queryGenerator.setBooleanLiteralRenderingContext(oldBooleanLiteralRenderingContext);
            whereConjuncts.add(tempSb.toString());
          }
          applyJoins(sb,entityNode.getAliasInfo(),entityNode.getNodes(),clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches);
        }
      }
    }
  }
  return collectionJoinNodes;
}

Fixed version (ground truth):
Set<JoinNode> buildClause(StringBuilder sb,Set<ClauseType> clauseExclusions,String aliasPrefix,boolean collectCollectionJoinNodes,boolean externalRepresenation,List<String> whereConjuncts){
  final boolean renderFetches=!clauseExclusions.contains(ClauseType.SELECT);
  StringBuilder tempSb=null;
  collectionJoinNodes.clear();
  renderedJoins.clear();
  sb.append("String_Node_Str");
  List<JoinNode> nodes=rootNodes;
  int size=nodes.size();
  for (int i=0; i < size; i++) {
    if (i != 0) {
      sb.append("String_Node_Str");
    }
    JoinNode rootNode=nodes.get(i);
    JoinNode correlationParent=rootNode.getCorrelationParent();
    if (externalRepresenation && rootNode.getValueCount() > 0) {
      ManagedType<?> type=metamodel.getManagedType(rootNode.getPropertyClass());
      final int attributeCount=rootNode.getAttributeCount();
      if (rootNode.getPropertyClass() != ValuesEntity.class) {
        if (type instanceof EntityType<?>) {
          sb.append(((EntityType)type).getName());
        }
 else {
          sb.append(type.getJavaType().getSimpleName());
        }
      }
      sb.append("String_Node_Str");
      for (int valueNumber=0; valueNumber < rootNode.getValueCount(); valueNumber++) {
        sb.append("String_Node_Str");
        for (int j=0; j < attributeCount; j++) {
          sb.append("String_Node_Str");
        }
        sb.setCharAt(sb.length() - 1,')');
        sb.append(',');
      }
      sb.setCharAt(sb.length() - 1,')');
    }
 else {
      if (correlationParent != null) {
        sb.append(correlationParent.getAliasInfo().getAlias());
        sb.append('.');
        sb.append(rootNode.getCorrelationPath());
      }
 else {
        EntityType<?> type=metamodel.entity(rootNode.getPropertyClass());
        sb.append(type.getName());
      }
    }
    sb.append(' ');
    if (aliasPrefix != null) {
      sb.append(aliasPrefix);
    }
    sb.append(rootNode.getAliasInfo().getAlias());
    rootNode.registerDependencies();
    applyJoins(sb,rootNode.getAliasInfo(),rootNode.getNodes(),clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches);
    if (!rootNode.getEntityJoinNodes().isEmpty()) {
      boolean isCollection=true;
      if (mainQuery.jpaProvider.supportsEntityJoin()) {
        applyJoins(sb,rootNode.getAliasInfo(),new ArrayList<JoinNode>(rootNode.getEntityJoinNodes()),isCollection,clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches);
      }
 else {
        Set<JoinNode> entityNodes=rootNode.getEntityJoinNodes();
        for (        JoinNode entityNode : entityNodes) {
          if (collectCollectionJoinNodes && isCollection) {
            collectionJoinNodes.add(entityNode);
          }
          sb.append("String_Node_Str");
          EntityType<?> type=metamodel.entity(entityNode.getPropertyClass());
          sb.append(type.getName());
          sb.append(' ');
          if (aliasPrefix != null) {
            sb.append(aliasPrefix);
          }
          sb.append(entityNode.getAliasInfo().getAlias());
          entityNode.registerDependencies();
          if (entityNode.getOnPredicate() != null && !entityNode.getOnPredicate().getChildren().isEmpty()) {
            if (tempSb == null) {
              tempSb=new StringBuilder();
            }
 else {
              tempSb.setLength(0);
            }
            queryGenerator.setQueryBuffer(tempSb);
            SimpleQueryGenerator.BooleanLiteralRenderingContext oldBooleanLiteralRenderingContext=queryGenerator.setBooleanLiteralRenderingContext(SimpleQueryGenerator.BooleanLiteralRenderingContext.PREDICATE);
            entityNode.getOnPredicate().accept(queryGenerator);
            queryGenerator.setBooleanLiteralRenderingContext(oldBooleanLiteralRenderingContext);
            whereConjuncts.add(tempSb.toString());
          }
          renderedJoins.add(entityNode);
          applyJoins(sb,entityNode.getAliasInfo(),entityNode.getNodes(),clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches);
        }
      }
    }
  }
  return collectionJoinNodes;
}