Program: 168783
Project: 168783
Buggy source:
private String applyAndGetCorrelationRoot(boolean batchCorrelationValues){
  Class<?> viewRootEntityClass=viewRootType.getEntityClass();
  String idAttributePath=getEntityIdName(viewRootEntityClass);
  FullQueryBuilder<?,?> queryBuilder=entityViewConfiguration.getCriteriaBuilder();
  Map<String,Object> optionalParameters=entityViewConfiguration.getOptionalParameters();
  Class<?> correlationBasisEntityType;
  String viewRootExpression;
  if (batchCorrelationValues) {
    correlationBasisEntityType=correlationBasisEntity;
    viewRootExpression=null;
  }
 else {
    correlationBasisEntityType=viewRootEntityClass;
    viewRootExpression=CORRELATION_KEY_ALIAS;
  }
  this.criteriaBuilder=queryBuilder.getCriteriaBuilderFactory().create(queryBuilder.getEntityManager(),Object[].class);
  this.viewRootJpqlMacro=new CorrelatedSubqueryViewRootJpqlMacro(criteriaBuilder,optionalParameters,viewRootEntityClass,idAttributePath,viewRootExpression);
  this.criteriaBuilder.registerMacro("String_Node_Str",viewRootJpqlMacro);
  SubqueryCorrelationBuilder correlationBuilder=new SubqueryCorrelationBuilder(criteriaBuilder,correlationResult,correlationBasisType,correlationBasisEntityType,CORRELATION_KEY_ALIAS,batchSize,false,attributePath);
  CorrelationProvider provider=correlationProviderFactory.create(entityViewConfiguration.getCriteriaBuilder(),entityViewConfiguration.getOptionalParameters());
  if (batchSize > 1) {
    if (batchCorrelationValues) {
      this.correlationParamName=CORRELATION_KEY_ALIAS;
    }
 else {
      this.correlationParamName=generateCorrelationParamName();
    }
    if (correlationBasisEntityType != null) {
      if (batchCorrelationValues) {
        correlationKeyExpression=CORRELATION_KEY_ALIAS + getEntityIdName(correlationBasisEntityType);
      }
 else {
        correlationKeyExpression=CORRELATION_KEY_ALIAS + '.' + idAttributePath;
      }
    }
 else {
      correlationKeyExpression=CORRELATION_KEY_ALIAS + "String_Node_Str";
    }
  }
 else {
    this.correlationParamName=generateCorrelationParamName();
    this.correlationKeyExpression=null;
  }
  if (batchSize > 1 && batchCorrelationValues) {
    provider.applyCorrelation(correlationBuilder,correlationKeyExpression);
  }
 else {
    provider.applyCorrelation(correlationBuilder,':' + correlationParamName);
  }
  if (fetches.length != 0) {
    for (int i=0; i < fetches.length; i++) {
      criteriaBuilder.fetch(correlationBuilder.getCorrelationAlias() + "String_Node_Str" + fetches[i]);
    }
  }
  return correlationBuilder.getCorrelationRoot();
}

Fixed version (ground truth):
private String applyAndGetCorrelationRoot(boolean batchCorrelationValues){
  Class<?> viewRootEntityClass=viewRootType.getEntityClass();
  String idAttributePath=getEntityIdName(viewRootEntityClass);
  FullQueryBuilder<?,?> queryBuilder=entityViewConfiguration.getCriteriaBuilder();
  Map<String,Object> optionalParameters=entityViewConfiguration.getOptionalParameters();
  Class<?> correlationBasisEntityType;
  String viewRootExpression;
  if (batchCorrelationValues) {
    correlationBasisEntityType=correlationBasisEntity;
    viewRootExpression=null;
  }
 else {
    correlationBasisEntityType=viewRootEntityClass;
    viewRootExpression=CORRELATION_KEY_ALIAS;
  }
  this.criteriaBuilder=queryBuilder.getCriteriaBuilderFactory().create(queryBuilder.getEntityManager(),Object[].class);
  this.viewRootJpqlMacro=new CorrelatedSubqueryViewRootJpqlMacro(criteriaBuilder,optionalParameters,viewRootEntityClass,idAttributePath,viewRootExpression);
  this.criteriaBuilder.registerMacro("String_Node_Str",viewRootJpqlMacro);
  SubqueryCorrelationBuilder correlationBuilder=new SubqueryCorrelationBuilder(criteriaBuilder,correlationResult,correlationBasisType,correlationBasisEntityType,CORRELATION_KEY_ALIAS,batchSize,false,attributePath);
  CorrelationProvider provider=correlationProviderFactory.create(entityViewConfiguration.getCriteriaBuilder(),entityViewConfiguration.getOptionalParameters());
  String correlationKeyExpression;
  if (batchSize > 1) {
    if (batchCorrelationValues) {
      this.correlationParamName=CORRELATION_KEY_ALIAS;
    }
 else {
      this.correlationParamName=generateCorrelationParamName();
    }
    if (correlationBasisEntityType != null) {
      correlationKeyExpression=CORRELATION_KEY_ALIAS;
      if (batchCorrelationValues) {
        correlationSelectExpression=CORRELATION_KEY_ALIAS + '.' + getEntityIdName(correlationBasisEntityType);
      }
 else {
        correlationSelectExpression=CORRELATION_KEY_ALIAS + '.' + idAttributePath;
      }
    }
 else {
      correlationSelectExpression=correlationKeyExpression=CORRELATION_KEY_ALIAS + "String_Node_Str";
    }
  }
 else {
    this.correlationParamName=generateCorrelationParamName();
    this.correlationSelectExpression=correlationKeyExpression=null;
  }
  if (batchSize > 1 && batchCorrelationValues) {
    provider.applyCorrelation(correlationBuilder,correlationKeyExpression);
  }
 else {
    provider.applyCorrelation(correlationBuilder,':' + correlationParamName);
  }
  if (fetches.length != 0) {
    for (int i=0; i < fetches.length; i++) {
      criteriaBuilder.fetch(correlationBuilder.getCorrelationAlias() + "String_Node_Str" + fetches[i]);
    }
  }
  return correlationBuilder.getCorrelationRoot();
}