Program: 168874
Project: 168874
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);
  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);
  }
  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);
  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);
  }
  return correlationBuilder.getCorrelationRoot();
}