Program: 189664
Project: 189664
Buggy source:
public FileDownload controller(@RequestParam("String_Node_Str") ReportRequest reportRequest,@RequestParam("String_Node_Str") String dataSetName,@RequestParam("String_Node_Str") String columnName,PageRequest pageRequest,@SpringBean ReportManager reportManager,@SpringBean KenyaUiUtils kenyaUi,@SpringBean ReportService reportService,@SpringBean CsvCreator csvCreator){
  ReportDefinition definition=reportRequest.getReportDefinition().getParameterizable();
  ReportDescriptor report=reportManager.getReportDescriptor(definition);
  CoreUtils.checkAccess(report,kenyaUi.getCurrentApp(pageRequest));
  ReportData reportData=reportService.loadReportData(reportRequest);
  MapDataSet dataSet=(MapDataSet)reportData.getDataSets().get(dataSetName);
  DataSetColumn dataSetColumn=dataSet.getMetaData().getColumn(columnName);
  Object result=dataSet.getData(dataSetColumn);
  Cohort cohort=null;
  if (result instanceof CohortIndicatorAndDimensionResult) {
    CohortIndicatorAndDimensionResult cidr=(CohortIndicatorAndDimensionResult)dataSet.getData(dataSetColumn);
    cohort=cidr.getCohortIndicatorAndDimensionCohort();
  }
 else   if (result instanceof Cohort) {
    cohort=(Cohort)result;
  }
  List<Patient> patients=Context.getPatientSetService().getPatients(cohort.getMemberIds());
  PatientCalculationService calculationService=Context.getService(PatientCalculationService.class);
  PatientCalculationContext calculationContext=calculationService.createCalculationContext();
  Date endDate=(Date)reportRequest.getReportDefinition().getParameterMappings().get("String_Node_Str");
  calculationContext.setNow(endDate);
  DateOfEnrollmentArtCalculation dateOfEnrollmentArtCalculation=new DateOfEnrollmentArtCalculation();
  CalculationResultMap enrollmentDates=dateOfEnrollmentArtCalculation.evaluate(cohort.getMemberIds(),null,calculationContext);
  InitialArtStartDateCalculation initialArtStartDateCalculation=new InitialArtStartDateCalculation();
  CalculationResultMap artInitializationDates=initialArtStartDateCalculation.evaluate(cohort.getMemberIds(),null,calculationContext);
  List<Object> data=new ArrayList<Object>();
  List<Object> headerRow=new ArrayList<Object>();
  List<Object> header=new ArrayList<Object>();
  header.add("String_Node_Str");
  header.add("String_Node_Str");
  header.add("String_Node_Str");
  header.add("String_Node_Str");
  header.add("String_Node_Str");
  header.add("String_Node_Str");
  headerRow.add(header.toArray());
  for (  Patient patient : patients) {
    List<Object> row=new ArrayList<Object>();
    row.add(patient.getPersonName().getFullName());
    row.add(patient.getAge());
    row.add(patient.getGender());
    row.add(new ArrayList<PatientIdentifier>(patient.getIdentifiers()).get(0));
    String enrollmentDate=null;
    CalculationResult enrollmentDateCalcResult=enrollmentDates.get(patient.getId());
    if (enrollmentDateCalcResult != null) {
      enrollmentDate=DATE_FORMAT.format((Date)enrollmentDateCalcResult.getValue());
    }
    row.add(enrollmentDate);
    String artInitializationDate=null;
    CalculationResult artInitializationDateCalcResult=artInitializationDates.get(patient.getId());
    if (artInitializationDateCalcResult != null) {
      artInitializationDate=DATE_FORMAT.format((Date)artInitializationDateCalcResult.getValue());
    }
    row.add(artInitializationDate);
    data.add(row.toArray());
  }
  System.out.println("String_Node_Str");
  FileDownload fileDownload=new FileDownload("String_Node_Str","String_Node_Str",csvCreator.createCsv(data,header));
  return fileDownload;
}

Fixed version (ground truth):
public FileDownload controller(@RequestParam("String_Node_Str") ReportRequest reportRequest,@RequestParam("String_Node_Str") String dataSetName,@RequestParam("String_Node_Str") String columnName,PageRequest pageRequest,@SpringBean ReportManager reportManager,@SpringBean KenyaUiUtils kenyaUi,@SpringBean ReportService reportService,@SpringBean CsvMaker csvMaker){
  ReportDefinition definition=reportRequest.getReportDefinition().getParameterizable();
  ReportDescriptor report=reportManager.getReportDescriptor(definition);
  CoreUtils.checkAccess(report,kenyaUi.getCurrentApp(pageRequest));
  ReportData reportData=reportService.loadReportData(reportRequest);
  MapDataSet dataSet=(MapDataSet)reportData.getDataSets().get(dataSetName);
  DataSetColumn dataSetColumn=dataSet.getMetaData().getColumn(columnName);
  Object result=dataSet.getData(dataSetColumn);
  Cohort cohort=null;
  if (result instanceof CohortIndicatorAndDimensionResult) {
    CohortIndicatorAndDimensionResult cidr=(CohortIndicatorAndDimensionResult)dataSet.getData(dataSetColumn);
    cohort=cidr.getCohortIndicatorAndDimensionCohort();
  }
 else   if (result instanceof Cohort) {
    cohort=(Cohort)result;
  }
  List<Patient> patients=Context.getPatientSetService().getPatients(cohort.getMemberIds());
  PatientCalculationService calculationService=Context.getService(PatientCalculationService.class);
  PatientCalculationContext calculationContext=calculationService.createCalculationContext();
  Date endDate=(Date)reportRequest.getReportDefinition().getParameterMappings().get("String_Node_Str");
  calculationContext.setNow(endDate);
  DateOfEnrollmentArtCalculation dateOfEnrollmentArtCalculation=new DateOfEnrollmentArtCalculation();
  CalculationResultMap enrollmentDates=dateOfEnrollmentArtCalculation.evaluate(cohort.getMemberIds(),null,calculationContext);
  InitialArtStartDateCalculation initialArtStartDateCalculation=new InitialArtStartDateCalculation();
  CalculationResultMap artInitializationDates=initialArtStartDateCalculation.evaluate(cohort.getMemberIds(),null,calculationContext);
  List<Object> data=new ArrayList<Object>();
  List<Object> headerRow=new ArrayList<Object>();
  List<Object> header=new ArrayList<Object>();
  header.add("String_Node_Str");
  header.add("String_Node_Str");
  header.add("String_Node_Str");
  header.add("String_Node_Str");
  header.add("String_Node_Str");
  header.add("String_Node_Str");
  headerRow.add(header.toArray());
  for (  Patient patient : patients) {
    List<Object> row=new ArrayList<Object>();
    row.add(patient.getPersonName().getFullName());
    row.add(patient.getAge());
    row.add(patient.getGender());
    row.add(new ArrayList<PatientIdentifier>(patient.getIdentifiers()).get(0));
    String enrollmentDate=null;
    CalculationResult enrollmentDateCalcResult=enrollmentDates.get(patient.getId());
    if (enrollmentDateCalcResult != null && enrollmentDateCalcResult.getValue() != null) {
      enrollmentDate=DATE_FORMAT.format((Date)enrollmentDateCalcResult.getValue());
    }
    row.add(enrollmentDate);
    String artInitializationDate=null;
    CalculationResult artInitializationDateCalcResult=artInitializationDates.get(patient.getId());
    if (artInitializationDateCalcResult != null && artInitializationDateCalcResult.getValue() != null) {
      artInitializationDate=DATE_FORMAT.format((Date)artInitializationDateCalcResult.getValue());
    }
    row.add(artInitializationDate);
    data.add(row.toArray());
  }
  System.out.println("String_Node_Str");
  FileDownload fileDownload=new FileDownload("String_Node_Str","String_Node_Str",csvMaker.createCsv(data,header));
  return fileDownload;
}