Program: 35590
Project: 35590
Buggy source:
public Map<String,List<String[]>> generateGlobalExportData(final Integer organizationId,EntityManager entityManager,final String localeString) throws SchedulerException {
  if (entityManager == null) {
    entityManager=injector.getInstance(EntityManager.class);
  }
  Locale locale=null;
  if (localeString != null)   locale=new Locale(localeString);
  Translator translator=new UIConstantsTranslator(new Locale("String_Node_Str"));
  final GlobalExportDAO exportDAO=new GlobalExportHibernateDAO(entityManager);
  final Organization organization=entityManager.find(Organization.class,organizationId);
  final List<ProjectModel> pModels=exportDAO.getProjectModelsByOrganization(organization);
  final List<Project> projects=exportDAO.getProjects(pModels);
  final Map<String,List<Project>> pModelProjectsMap=new HashMap<String,List<Project>>();
  for (  final Project project : projects) {
    final String pModelName=project.getProjectModel().getName();
    List<Project> pModelProjects=pModelProjectsMap.get(pModelName);
    if (pModelProjects == null) {
      pModelProjects=new ArrayList<Project>();
      pModelProjectsMap.put(pModelName,pModelProjects);
    }
    pModelProjects.add(project);
  }
  final Map<String,List<FlexibleElement>> pModelElementsMap=new HashMap<String,List<FlexibleElement>>();
  for (  final ProjectModel projectModel : pModels) {
    final String pModelName=projectModel.getName();
    final List<FlexibleElement> pModelElements=new ArrayList<FlexibleElement>();
    pModelElementsMap.put(pModelName,pModelElements);
    fillElementList(pModelElements,projectModel.getProjectDetails().getLayout());
    for (    final PhaseModel phaseModel : projectModel.getPhases()) {
      fillElementList(pModelElements,phaseModel.getLayout());
    }
  }
  final CommandHandler<GetValue> handler=new GetValueHandler(entityManager,injector.getInstance(Mapper.class));
  final Map<String,List<String[]>> pModelExportDataMap=new TreeMap<String,List<String[]>>();
  for (  final String pModelName : pModelElementsMap.keySet()) {
    final List<FlexibleElement> elements=pModelElementsMap.get(pModelName);
    final List<String[]> exportData=new ArrayList<String[]>();
    pModelExportDataMap.put(pModelName,exportData);
    final String[] titles=new String[elements.size()];
    boolean isFirstLine=true;
    for (    final Project project : pModelProjectsMap.get(pModelName)) {
      final String[] values=new String[elements.size()];
      int titleIndex=0;
      int valueIndex=0;
      for (      final FlexibleElement element : elements) {
        final String elementName="String_Node_Str" + element.getClass().getSimpleName();
        final GetValue command=new GetValue(project.getId(),element.getId(),elementName,null);
        try {
          final ValueResult valueResult=(ValueResult)handler.execute(command,null);
          ValueLabel pair=null;
          if (elementName.equals("String_Node_Str")) {
            pair=getDefElementPair(valueResult,element,project,entityManager,locale,translator);
          }
 else           if (elementName.equals("String_Node_Str")) {
            pair=getCheckboxElementPair(valueResult,element,locale,translator);
          }
 else           if (elementName.equals("String_Node_Str")) {
            pair=getTextAreaElementPair(valueResult,element);
          }
          if (elementName.equals("String_Node_Str")) {
            pair=getTripletPair(element,valueResult);
          }
          if (elementName.equals("String_Node_Str")) {
            pair=getChoicePair(element,valueResult);
          }
          if (isFirstLine) {
            titles[titleIndex++]=pair != null ? pair.getFormattedLabel() : null;
          }
          String valueStr=null;
          if (pair != null) {
            Object value=pair.getValue();
            if (value == null) {
              valueStr=null;
            }
 else             if (value instanceof String) {
              valueStr=(String)value;
            }
 else             if (value instanceof Double) {
              Double d=(Double)value;
              valueStr=LogFrameExportData.AGGR_AVG_FORMATTER.format(d.doubleValue());
            }
 else             if (value instanceof Long) {
              Long l=(Long)value;
              valueStr=LogFrameExportData.AGGR_SUM_FORMATTER.format(l.longValue());
            }
 else {
              valueStr=ExportConstants.EXPORT_DATE_FORMAT.format((Date)value);
            }
          }
          values[valueIndex++]=valueStr;
        }
 catch (        CommandException e) {
          Log.error("String_Node_Str" + e.getMessage());
        }
      }
      if (isFirstLine) {
        exportData.add(titles);
        isFirstLine=false;
      }
      exportData.add(values);
    }
  }
  return pModelExportDataMap;
}

Fixed version (ground truth):
public Map<String,List<String[]>> generateGlobalExportData(final Integer organizationId,EntityManager entityManager,final String localeString) throws SchedulerException {
  if (entityManager == null) {
    entityManager=injector.getInstance(EntityManager.class);
  }
  Locale locale=null;
  if (localeString != null)   locale=new Locale(localeString);
  Translator translator=new UIConstantsTranslator(new Locale("String_Node_Str"));
  final GlobalExportDAO exportDAO=new GlobalExportHibernateDAO(entityManager);
  final Organization organization=entityManager.find(Organization.class,organizationId);
  final List<ProjectModel> pModels=exportDAO.getProjectModelsByOrganization(organization);
  final List<Project> projects=exportDAO.getProjects(pModels);
  final Map<String,List<Project>> pModelProjectsMap=new HashMap<String,List<Project>>();
  for (  final Project project : projects) {
    final String pModelName=project.getProjectModel().getName();
    List<Project> pModelProjects=pModelProjectsMap.get(pModelName);
    if (pModelProjects == null) {
      pModelProjects=new ArrayList<Project>();
      pModelProjectsMap.put(pModelName,pModelProjects);
    }
    pModelProjects.add(project);
  }
  final Map<String,List<FlexibleElement>> pModelElementsMap=new HashMap<String,List<FlexibleElement>>();
  for (  final ProjectModel projectModel : pModels) {
    final String pModelName=projectModel.getName();
    final List<FlexibleElement> pModelElements=new ArrayList<FlexibleElement>();
    pModelElementsMap.put(pModelName,pModelElements);
    fillElementList(pModelElements,projectModel.getProjectDetails().getLayout());
    for (    final PhaseModel phaseModel : projectModel.getPhases()) {
      fillElementList(pModelElements,phaseModel.getLayout());
    }
  }
  final CommandHandler<GetValue> handler=new GetValueHandler(entityManager,injector.getInstance(Mapper.class));
  final Map<String,List<String[]>> pModelExportDataMap=new TreeMap<String,List<String[]>>();
  for (  final String pModelName : pModelElementsMap.keySet()) {
    if (pModelProjectsMap.get(pModelName) == null)     continue;
    final List<FlexibleElement> elements=pModelElementsMap.get(pModelName);
    final List<String[]> exportData=new ArrayList<String[]>();
    pModelExportDataMap.put(pModelName,exportData);
    final String[] titles=new String[elements.size()];
    boolean isFirstLine=true;
    for (    final Project project : pModelProjectsMap.get(pModelName)) {
      final String[] values=new String[elements.size()];
      int titleIndex=0;
      int valueIndex=0;
      for (      final FlexibleElement element : elements) {
        final String elementName="String_Node_Str" + element.getClass().getSimpleName();
        final GetValue command=new GetValue(project.getId(),element.getId(),elementName,null);
        try {
          final ValueResult valueResult=(ValueResult)handler.execute(command,null);
          ValueLabel pair=null;
          if (elementName.equals("String_Node_Str")) {
            pair=getDefElementPair(valueResult,element,project,entityManager,locale,translator);
          }
 else           if (elementName.equals("String_Node_Str")) {
            pair=getCheckboxElementPair(valueResult,element,locale,translator);
          }
 else           if (elementName.equals("String_Node_Str")) {
            pair=getTextAreaElementPair(valueResult,element);
          }
          if (elementName.equals("String_Node_Str")) {
            pair=getTripletPair(element,valueResult);
          }
          if (elementName.equals("String_Node_Str")) {
            pair=getChoicePair(element,valueResult);
          }
          if (isFirstLine) {
            titles[titleIndex++]=pair != null ? pair.getFormattedLabel() : null;
          }
          String valueStr=null;
          if (pair != null) {
            Object value=pair.getValue();
            if (value == null) {
              valueStr=null;
            }
 else             if (value instanceof String) {
              valueStr=(String)value;
            }
 else             if (value instanceof Double) {
              Double d=(Double)value;
              valueStr=LogFrameExportData.AGGR_AVG_FORMATTER.format(d.doubleValue());
            }
 else             if (value instanceof Long) {
              Long l=(Long)value;
              valueStr=LogFrameExportData.AGGR_SUM_FORMATTER.format(l.longValue());
            }
 else {
              valueStr=ExportConstants.EXPORT_DATE_FORMAT.format((Date)value);
            }
          }
          values[valueIndex++]=valueStr;
        }
 catch (        CommandException e) {
          Log.error("String_Node_Str" + e.getMessage());
        }
      }
      if (isFirstLine) {
        exportData.add(titles);
        isFirstLine=false;
      }
      exportData.add(values);
    }
  }
  return pModelExportDataMap;
}