Program: 168798
Project: 168798
Buggy source:
Set<JoinNode> buildClause(StringBuilder sb,Set<ClauseType> clauseExclusions,String aliasPrefix,boolean collectCollectionJoinNodes,boolean externalRepresenation,List<String> whereConjuncts,Map<Class<?>,Map<String,DbmsModificationState>> explicitVersionEntities,Set<JoinNode> nodesToFetch){
  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=rootNode.getManagedType();
      final int attributeCount=rootNode.getAttributeCount();
      if (type.getJavaType() != 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 (externalRepresenation && explicitVersionEntities.get(rootNode.getType()) != null) {
      DbmsModificationState state=explicitVersionEntities.get(rootNode.getType()).get(rootNode.getAlias());
      EntityType<?> type=rootNode.getEntityType();
      if (state == DbmsModificationState.NEW) {
        sb.append("String_Node_Str");
      }
 else {
        sb.append("String_Node_Str");
      }
      sb.append(type.getName());
      sb.append(')');
    }
 else {
      if (correlationParent != null) {
        renderCorrelationJoinPath(sb,correlationParent.getAliasInfo(),rootNode);
      }
 else {
        EntityType<?> type=rootNode.getEntityType();
        sb.append(type.getName());
      }
    }
    sb.append(' ');
    if (aliasPrefix != null) {
      sb.append(aliasPrefix);
    }
    sb.append(rootNode.getAliasInfo().getAlias());
    renderedJoins.add(rootNode);
    rootNode.registerDependencies();
    applyJoins(sb,rootNode.getAliasInfo(),rootNode.getNodes(),clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches,nodesToFetch);
    for (    JoinNode treatedNode : rootNode.getTreatedJoinNodes().values()) {
      applyJoins(sb,treatedNode.getAliasInfo(),treatedNode.getNodes(),clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches,nodesToFetch);
    }
    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,nodesToFetch);
      }
 else {
        Set<JoinNode> entityNodes=rootNode.getEntityJoinNodes();
        for (        JoinNode entityNode : entityNodes) {
          if (collectCollectionJoinNodes && isCollection) {
            collectionJoinNodes.add(entityNode);
          }
          sb.append("String_Node_Str");
          EntityType<?> type=entityNode.getEntityType();
          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.setClauseType(ClauseType.JOIN);
            queryGenerator.setQueryBuffer(tempSb);
            SimpleQueryGenerator.BooleanLiteralRenderingContext oldBooleanLiteralRenderingContext=queryGenerator.setBooleanLiteralRenderingContext(SimpleQueryGenerator.BooleanLiteralRenderingContext.PREDICATE);
            entityNode.getOnPredicate().accept(queryGenerator);
            queryGenerator.setBooleanLiteralRenderingContext(oldBooleanLiteralRenderingContext);
            queryGenerator.setClauseType(null);
            whereConjuncts.add(tempSb.toString());
          }
          renderedJoins.add(entityNode);
          applyJoins(sb,entityNode.getAliasInfo(),entityNode.getNodes(),clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches,nodesToFetch);
          for (          JoinNode treatedNode : entityNode.getTreatedJoinNodes().values()) {
            applyJoins(sb,treatedNode.getAliasInfo(),treatedNode.getNodes(),clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches,nodesToFetch);
          }
        }
      }
    }
  }
  return collectionJoinNodes;
}

Fixed version (ground truth):
Set<JoinNode> buildClause(StringBuilder sb,Set<ClauseType> clauseExclusions,String aliasPrefix,boolean collectCollectionJoinNodes,boolean externalRepresenation,List<String> whereConjuncts,Map<Class<?>,Map<String,DbmsModificationState>> explicitVersionEntities,Set<JoinNode> nodesToFetch){
  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=rootNode.getManagedType();
      final int attributeCount=rootNode.getAttributeCount();
      if (type.getJavaType() != 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 (externalRepresenation && explicitVersionEntities.get(rootNode.getType()) != null) {
      DbmsModificationState state=explicitVersionEntities.get(rootNode.getType()).get(rootNode.getAlias());
      EntityType<?> type=rootNode.getEntityType();
      if (state == DbmsModificationState.NEW) {
        sb.append("String_Node_Str");
      }
 else {
        sb.append("String_Node_Str");
      }
      sb.append(type.getName());
      sb.append(')');
    }
 else {
      if (correlationParent != null) {
        renderCorrelationJoinPath(sb,correlationParent.getAliasInfo(),rootNode);
      }
 else {
        EntityType<?> type=rootNode.getEntityType();
        sb.append(type.getName());
      }
    }
    sb.append(' ');
    if (aliasPrefix != null) {
      sb.append(aliasPrefix);
    }
    sb.append(rootNode.getAliasInfo().getAlias());
    renderedJoins.add(rootNode);
    rootNode.registerDependencies();
    applyJoins(sb,rootNode.getAliasInfo(),rootNode.getNodes(),clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches,nodesToFetch,whereConjuncts);
    for (    JoinNode treatedNode : rootNode.getTreatedJoinNodes().values()) {
      applyJoins(sb,treatedNode.getAliasInfo(),treatedNode.getNodes(),clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches,nodesToFetch,whereConjuncts);
    }
    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,nodesToFetch,whereConjuncts);
      }
 else {
        Set<JoinNode> entityNodes=rootNode.getEntityJoinNodes();
        for (        JoinNode entityNode : entityNodes) {
          if (collectCollectionJoinNodes && isCollection) {
            collectionJoinNodes.add(entityNode);
          }
          sb.append("String_Node_Str");
          EntityType<?> type=entityNode.getEntityType();
          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.setClauseType(ClauseType.JOIN);
            queryGenerator.setQueryBuffer(tempSb);
            SimpleQueryGenerator.BooleanLiteralRenderingContext oldBooleanLiteralRenderingContext=queryGenerator.setBooleanLiteralRenderingContext(SimpleQueryGenerator.BooleanLiteralRenderingContext.PREDICATE);
            entityNode.getOnPredicate().accept(queryGenerator);
            queryGenerator.setBooleanLiteralRenderingContext(oldBooleanLiteralRenderingContext);
            queryGenerator.setClauseType(null);
            whereConjuncts.add(tempSb.toString());
          }
          renderedJoins.add(entityNode);
          applyJoins(sb,entityNode.getAliasInfo(),entityNode.getNodes(),clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches,nodesToFetch,whereConjuncts);
          for (          JoinNode treatedNode : entityNode.getTreatedJoinNodes().values()) {
            applyJoins(sb,treatedNode.getAliasInfo(),treatedNode.getNodes(),clauseExclusions,aliasPrefix,collectCollectionJoinNodes,renderFetches,nodesToFetch,whereConjuncts);
          }
        }
      }
    }
  }
  return collectionJoinNodes;
}