#vulnerable code 
                                public void handleTemplateException(TemplateException te,
                                        Environment env,
                                        Writer out) {

        if (ninjaProperties.isProd()) {
            
            PrintWriter pw = (out instanceof PrintWriter) ? (PrintWriter) out
                    : new PrintWriter(out);
            pw.println(
                     "<script language=javascript>//\"></script>"
                    + "<script language=javascript>//\'></script>"
                    + "<script language=javascript>//\"></script>"
                    + "<script language=javascript>//\'></script>"
                    + "</title></xmp></script></noscript></style></object>"
                    + "</head></pre></table>"
                    + "</form></table></table></table></a></u></i></b>"
                    + "<div align=left "
                    + "style='background-color:#FFFF00; color:#FF0000; "
                    + "display:block; border-top:double; padding:2pt; "
                    + "font-size:medium; font-family:Arial,sans-serif; "
                    + "font-style: normal; font-variant: normal; "
                    + "font-weight: normal; text-decoration: none; "
                    + "text-transform: none'>");
            pw.println("<b style='font-size:medium'>Ooops. A really strange error occurred. Please contact admin if error persists.</b>");
            pw.println("</div></html>");
            pw.flush();
            pw.close();
            
            logger.log(Level.SEVERE, "Templating error. This should not happen in production", te);
            
            

        } else {
            
            // print out full stacktrace if we are in test or dev mode

            PrintWriter pw = (out instanceof PrintWriter) ? (PrintWriter) out
                    : new PrintWriter(out);
            pw.println("<!-- FREEMARKER ERROR MESSAGE STARTS HERE -->"
                    + "<script language=javascript>//\"></script>"
                    + "<script language=javascript>//\'></script>"
                    + "<script language=javascript>//\"></script>"
                    + "<script language=javascript>//\'></script>"
                    + "</title></xmp></script></noscript></style></object>"
                    + "</head></pre></table>"
                    + "</form></table></table></table></a></u></i></b>"
                    + "<div align=left "
                    + "style='background-color:#FFFF00; color:#FF0000; "
                    + "display:block; border-top:double; padding:2pt; "
                    + "font-size:medium; font-family:Arial,sans-serif; "
                    + "font-style: normal; font-variant: normal; "
                    + "font-weight: normal; text-decoration: none; "
                    + "text-transform: none'>"
                    + "<b style='font-size:medium'>FreeMarker template error!</b>"
                    + "<pre><xmp>");
            te.printStackTrace(pw);
            pw.println("</xmp></pre></div></html>");
            pw.flush();
            pw.close();
            
            logger.log(Level.SEVERE, "Templating error.", te);
        }

    } 
                            #location 62 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                public void handleTemplateException(TemplateException te,
                                        Environment env,
                                        Writer out) throws TemplateException {

        if (!ninjaProperties.isProd()) {
            // print out full stacktrace if we are in test or dev mode

            PrintWriter pw = (out instanceof PrintWriter) ? (PrintWriter) out
                    : new PrintWriter(out);
            pw.println("<!-- FREEMARKER ERROR MESSAGE STARTS HERE -->"
                    + "<script language=javascript>//\"></script>"
                    + "<script language=javascript>//\'></script>"
                    + "<script language=javascript>//\"></script>"
                    + "<script language=javascript>//\'></script>"
                    + "</title></xmp></script></noscript></style></object>"
                    + "</head></pre></table>"
                    + "</form></table></table></table></a></u></i></b>"
                    + "<div align=left "
                    + "style='background-color:#FFFF00; color:#FF0000; "
                    + "display:block; border-top:double; padding:2pt; "
                    + "font-size:medium; font-family:Arial,sans-serif; "
                    + "font-style: normal; font-variant: normal; "
                    + "font-weight: normal; text-decoration: none; "
                    + "text-transform: none'>"
                    + "<b style='font-size:medium'>FreeMarker template error!</b>"
                    + "<pre><xmp>");
            te.printStackTrace(pw);
            pw.println("</xmp></pre></div></html>");
            pw.flush();
            pw.close();
            logger.error("Templating error.", te);
        }
        // Let the exception bubble up to the central handlers
        // so the application can return the correct error page
        // or perform some other application specific action.
        throw te;

    }