Program: 39262
Project: 39262
Buggy source:
@Monitorable(threshold=500) @RequestMapping(value={CONTROLLER_PATH},method=RequestMethod.POST) @ResponseBody public Object generatePdf(@PathVariable(PLUGIN_IDENTIFIER_VARIABLE) final String pluginIdentifier,@PathVariable(VIEW_NAME_VARIABLE) final String viewName,@RequestBody final JSONObject body,final Locale locale){
  try {
    changeMaxResults(body);
    ViewDefinitionState state=crudService.invokeEvent(pluginIdentifier,viewName,body,locale);
    GridComponent grid=(GridComponent)state.getComponentByReference("String_Node_Str");
    Document document=new Document(PageSize.A4.rotate());
    String date=DateFormat.getDateInstance().format(new Date());
    File file=fileService.createExportFile("String_Node_Str" + grid.getName() + "String_Node_Str"+ date+ "String_Node_Str");
    FileOutputStream fileOutputStream=new FileOutputStream(file);
    PdfWriter writer=PdfWriter.getInstance(document,fileOutputStream);
    Entity company=dataDefinitionService.get("String_Node_Str","String_Node_Str").find().add(SearchRestrictions.eq("String_Node_Str",true)).setMaxResults(1).uniqueResult();
    writer.setPageEvent(new PdfPageNumbering(translationService.translate("String_Node_Str",locale),translationService.translate("String_Node_Str",locale),"String_Node_Str",company,translationService.translate("String_Node_Str",locale),securityService.getCurrentUserName()));
    document.setMargins(40,40,60,60);
    document.addTitle("String_Node_Str");
    pdfHelper.addMetaData(document);
    writer.createXmpMetadata();
    document.open();
    String title=translationService.translate(pluginIdentifier + "String_Node_Str" + viewName+ "String_Node_Str"+ grid.getName()+ "String_Node_Str",locale);
    Date generationDate=new Date();
    pdfHelper.addDocumentHeader(document,"String_Node_Str",title,translationService.translate("String_Node_Str",locale),generationDate,securityService.getCurrentUserName());
    int columns=0;
    List<String> exportToPDFTableHeader=new ArrayList<String>();
    for (    String name : grid.getColumnNames().values()) {
      exportToPDFTableHeader.add(name);
      columns++;
    }
    PdfPTable table=pdfHelper.createTableWithHeader(columns,exportToPDFTableHeader,false);
    List<Map<String,String>> rows;
    if (grid.getSelectedEntitiesIds().isEmpty()) {
      rows=grid.getColumnValuesOfAllRecords();
    }
 else {
      rows=grid.getColumnValuesOfSelectedRecords();
    }
    for (    Map<String,String> row : rows) {
      for (      String value : row.values()) {
        table.addCell(new Phrase(value,FontUtils.getDejavuRegular9Dark()));
      }
    }
    document.add(table);
    pdfHelper.addEndOfDocument(document,writer,translationService.translate("String_Node_Str",locale));
    document.close();
    state.redirectTo(fileService.getUrl(file.getAbsolutePath()) + "String_Node_Str",true,false);
    return crudService.renderView(state);
  }
 catch (  JSONException e) {
    throw new IllegalStateException(e.getMessage(),e);
  }
catch (  FileNotFoundException e) {
    throw new IllegalStateException(e.getMessage(),e);
  }
catch (  DocumentException e) {
    throw new IllegalStateException(e.getMessage(),e);
  }
}

Fixed version (ground truth):
@Monitorable(threshold=500) @ResponseBody @RequestMapping(value={CONTROLLER_PATH},method=RequestMethod.POST) public Object generatePdf(@PathVariable(PLUGIN_IDENTIFIER_VARIABLE) final String pluginIdentifier,@PathVariable(VIEW_NAME_VARIABLE) final String viewName,@RequestBody final JSONObject body,final Locale locale){
  try {
    changeMaxResults(body);
    ViewDefinitionState state=crudService.invokeEvent(pluginIdentifier,viewName,body,locale);
    GridComponent grid=(GridComponent)state.getComponentByReference("String_Node_Str");
    Document document=new Document(PageSize.A4.rotate());
    String date=DateFormat.getDateInstance().format(new Date());
    File file=fileService.createExportFile("String_Node_Str" + grid.getName() + "String_Node_Str"+ date+ "String_Node_Str");
    FileOutputStream fileOutputStream=new FileOutputStream(file);
    PdfWriter writer=PdfWriter.getInstance(document,fileOutputStream);
    Entity company=dataDefinitionService.get("String_Node_Str","String_Node_Str").find().add(SearchRestrictions.eq("String_Node_Str",true)).setMaxResults(1).uniqueResult();
    writer.setPageEvent(new PdfPageNumbering(translationService.translate("String_Node_Str",locale),translationService.translate("String_Node_Str",locale),"String_Node_Str",company,translationService.translate("String_Node_Str",locale),securityService.getCurrentUserName()));
    document.setMargins(40,40,60,60);
    document.addTitle("String_Node_Str");
    pdfHelper.addMetaData(document);
    writer.createXmpMetadata();
    document.open();
    String title=translationService.translate(pluginIdentifier + "String_Node_Str" + viewName+ "String_Node_Str"+ grid.getName()+ "String_Node_Str",locale);
    Date generationDate=new Date();
    pdfHelper.addDocumentHeader(document,"String_Node_Str",title,translationService.translate("String_Node_Str",locale),generationDate,securityService.getCurrentUserName());
    int columns=0;
    List<String> exportToPDFTableHeader=new ArrayList<String>();
    for (    String name : grid.getColumnNames().values()) {
      exportToPDFTableHeader.add(name);
      columns++;
    }
    PdfPTable table=pdfHelper.createTableWithHeader(columns,exportToPDFTableHeader,false);
    List<Map<String,String>> rows;
    if (grid.getSelectedEntitiesIds().isEmpty()) {
      rows=grid.getColumnValuesOfAllRecords();
    }
 else {
      rows=grid.getColumnValuesOfSelectedRecords();
    }
    for (    Map<String,String> row : rows) {
      for (      String value : row.values()) {
        table.addCell(new Phrase(value,FontUtils.getDejavuRegular9Dark()));
      }
    }
    document.add(table);
    pdfHelper.addEndOfDocument(document,writer,translationService.translate("String_Node_Str",locale));
    document.close();
    state.redirectTo(fileService.getUrl(file.getAbsolutePath()) + "String_Node_Str",true,false);
    return crudService.renderView(state);
  }
 catch (  JSONException e) {
    throw new IllegalStateException(e.getMessage(),e);
  }
catch (  FileNotFoundException e) {
    throw new IllegalStateException(e.getMessage(),e);
  }
catch (  DocumentException e) {
    throw new IllegalStateException(e.getMessage(),e);
  }
}