Program: 39261
Project: 39261
Buggy source:
@Monitorable(threshold=500) @RequestMapping(value={CONTROLLER_PATH},method=RequestMethod.POST) @ResponseBody public Object generateCsv(@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");
    String date=DateFormat.getDateInstance().format(new Date());
    File file=fileService.createExportFile("String_Node_Str" + grid.getName() + "String_Node_Str"+ date+ "String_Node_Str");
    BufferedWriter output=null;
    try {
      output=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),Charset.forName("String_Node_Str")));
      boolean firstName=true;
      for (      String name : grid.getColumnNames().values()) {
        if (firstName) {
          firstName=false;
        }
 else {
          output.append(EXPORTED_DOCUMENT_SEPARATOR);
        }
        output.append("String_Node_Str").append(normalizeString(name)).append("String_Node_Str");
      }
      output.append("String_Node_Str");
      List<Map<String,String>> rows;
      if (grid.getSelectedEntitiesIds().isEmpty()) {
        rows=grid.getColumnValuesOfAllRecords();
      }
 else {
        rows=grid.getColumnValuesOfSelectedRecords();
      }
      for (      Map<String,String> row : rows) {
        boolean firstValue=true;
        for (        String value : row.values()) {
          if (firstValue) {
            firstValue=false;
          }
 else {
            output.append(EXPORTED_DOCUMENT_SEPARATOR);
          }
          output.append("String_Node_Str").append(normalizeString(value)).append("String_Node_Str");
        }
        output.append("String_Node_Str");
      }
      output.flush();
    }
 catch (    IOException e) {
      throw new IllegalStateException(e.getMessage(),e);
    }
 finally {
      IOUtils.closeQuietly(output);
    }
    state.redirectTo(fileService.getUrl(file.getAbsolutePath()) + "String_Node_Str",true,false);
    return crudService.renderView(state);
  }
 catch (  JSONException e) {
    throw new IllegalStateException(e.getMessage(),e);
  }
}

Fixed version (ground truth):
@Monitorable(threshold=500) @ResponseBody @RequestMapping(value={CONTROLLER_PATH},method=RequestMethod.POST) public Object generateCsv(@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");
    String date=DateFormat.getDateInstance().format(new Date());
    File file=fileService.createExportFile("String_Node_Str" + grid.getName() + "String_Node_Str"+ date+ "String_Node_Str");
    BufferedWriter output=null;
    try {
      output=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),Charset.forName("String_Node_Str")));
      boolean firstName=true;
      for (      String name : grid.getColumnNames().values()) {
        if (firstName) {
          firstName=false;
        }
 else {
          output.append(EXPORTED_DOCUMENT_SEPARATOR);
        }
        output.append("String_Node_Str").append(normalizeString(name)).append("String_Node_Str");
      }
      output.append("String_Node_Str");
      List<Map<String,String>> rows;
      if (grid.getSelectedEntitiesIds().isEmpty()) {
        rows=grid.getColumnValuesOfAllRecords();
      }
 else {
        rows=grid.getColumnValuesOfSelectedRecords();
      }
      for (      Map<String,String> row : rows) {
        boolean firstValue=true;
        for (        String value : row.values()) {
          if (firstValue) {
            firstValue=false;
          }
 else {
            output.append(EXPORTED_DOCUMENT_SEPARATOR);
          }
          output.append("String_Node_Str").append(normalizeString(value)).append("String_Node_Str");
        }
        output.append("String_Node_Str");
      }
      output.flush();
    }
 catch (    IOException e) {
      throw new IllegalStateException(e.getMessage(),e);
    }
 finally {
      IOUtils.closeQuietly(output);
    }
    state.redirectTo(fileService.getUrl(file.getAbsolutePath()) + "String_Node_Str",true,false);
    return crudService.renderView(state);
  }
 catch (  JSONException e) {
    throw new IllegalStateException(e.getMessage(),e);
  }
}