Buggy code:
@ Controller public class FormController { public static final String TEMPLATES_AUTOFILL_VM = "autofill.vm" ; @ Autowired private FormService formService ; @ Autowired private MessageSource messageSource ; @ Autowired private VelocityEngine velocityEngine ; @ RequestMapping ( value = "//" , method = RequestMethod . POST ) public String actionForms ( @ RequestParam ( value = "action" , required = false ) Integer action , @ RequestParam ( value = "selusers" , required = false ) String [ ] selusers , HttpServletResponse response ) throws IOException { } @ RequestMapping ( "//" ) public String listForms ( @ RequestParam ( value = "sort" , required = false ) String sort , @ RequestParam ( value = "dir" , required = false ) String dir , @ RequestParam ( value = "text" , required = false ) String text , @ RequestParam ( value = "from" , required = false ) String from , @ RequestParam ( value = "to" , required = false ) String to , @ RequestParam ( value = "not_reg" , required = false ) String not_reg , @ RequestParam ( value = "user_id" , required = false ) String user_id , @ RequestParam ( value = "clear" , required = false ) String clear , Map < String , Object > map , HttpSession session ) { } @ RequestMapping ( value = "//addform" , method = RequestMethod . GET ) public String addForm ( Map < String , Object > model ) { } @ RequestMapping ( value = "//edit//{id}" , method = RequestMethod . GET ) public String editForm ( Map < String , Object > model , @ PathVariable ( "id" ) Integer id ) { } @ RequestMapping ( value = "//import" , method = RequestMethod . POST ) public String importForm ( FileUpload fileUpload , BindingResult result , Map model , Locale locale , @ RequestParam ( "id" ) Integer id , MultipartHttpServletRequest request ) { } @ RequestMapping ( value = "//delete//{id}" , method = RequestMethod . GET ) public String deleteForm ( Map < String , Object > model , @ PathVariable ( "id" ) Integer id ) { } @ RequestMapping ( value = "//addform" , method = RequestMethod . POST ) public String processForm ( @ Valid Form form , BindingResult result , @ RequestParam ( "copy" ) String copy , @ RequestParam ( value = "is_children" , required = false ) String is_children , Map model ) { } @ RequestMapping ( "//index" ) public String home ( ) { } @ RequestMapping ( value = "//download//{id}" , method = RequestMethod . GET ) public String downloadForm ( Map < String , Object > model , @ PathVariable ( "id" ) Integer id , HttpServletResponse response ) throws IOException { Form form ; if ( id != null ) { form = formService . getForm ( id ) ; String filename = ( ( ( form . getFilename ( ) ) != null ) && ( ! ( form . getFilename ( ) . equals ( "" ) ) ) ) ? ( form . getFilename ( ) ) + ".txt" : ( "form_" + ( form . getPassnum_13 ( ) ) ) + ".txt" ; model . put ( "form" , form ) ; if ( ( form . getPassdata_12 ( ) ) != null ) { } response . setContentType ( "text//plain" ) ; String headerKey = "Content-Disposition" ; String headerValue = String . format ( "attachment;<seq2seq4repair_space>filename=\"%s\"" , filename ) ; response . setHeader ( headerKey , headerValue ) ; String textdoc = null ; try { textdoc = VelocityEngineUtils . mergeTemplateIntoString ( velocityEngine , FormController . TEMPLATES_AUTOFILL_VM , "utf-8" , model ) ; } catch ( VelocityException e ) { e . printStackTrace ( ) ; } ServletOutputStream out = response . getOutputStream ( ) ; <START_BUG> PrintWriter writer = new PrintWriter ( new OutputStreamWriter ( out , StandardCharsets . UTF_8 ) ) ; <END_BUG> writer . print ( textdoc ) ; return null ; } else { return "redirect://" ; } } private boolean is_admin ( ) { } private Map fillDictionary ( ) { } public void zipIt ( String zipFile , Set < File > fileList ) { } }

Fix:
PrintWriter writer = new PrintWriter ( new OutputStreamWriter ( out , "UTF-8" ) ) ;