Author: fschumacher Date: Sat Jan 24 13:45:30 2015 New Revision: 1654515 URL: http://svn.apache.org/r1654515 Log: Close input stream for including jsp. Issue reported by Coverity Scan.
Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/examples/ShowSource.java Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/examples/ShowSource.java URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/examples/ShowSource.java?rev=1654515&r1=1654514&r2=1654515&view=diff ============================================================================== --- tomcat/trunk/webapps/examples/WEB-INF/classes/examples/ShowSource.java (original) +++ tomcat/trunk/webapps/examples/WEB-INF/classes/examples/ShowSource.java Sat Jan 24 13:45:30 2015 @@ -45,27 +45,29 @@ public class ShowSource extends TagSuppo (jspFile.toUpperCase(Locale.ENGLISH).indexOf("/META-INF/") != 0)) throw new JspTagException("Invalid JSP file " + jspFile); - InputStream in - = pageContext.getServletContext().getResourceAsStream(jspFile); + try (InputStream in + = pageContext.getServletContext().getResourceAsStream(jspFile)) { - if (in == null) - throw new JspTagException("Unable to find JSP file: "+jspFile); + if (in == null) + throw new JspTagException("Unable to find JSP file: " + jspFile); - JspWriter out = pageContext.getOut(); + JspWriter out = pageContext.getOut(); - - try { - out.println("<body>"); - out.println("<pre>"); - for(int ch = in.read(); ch != -1; ch = in.read()) - if (ch == '<') - out.print("<"); - else - out.print((char) ch); - out.println("</pre>"); - out.println("</body>"); - } catch (IOException ex) { - throw new JspTagException("IOException: "+ex.toString()); + try { + out.println("<body>"); + out.println("<pre>"); + for (int ch = in.read(); ch != -1; ch = in.read()) + if (ch == '<') + out.print("<"); + else + out.print((char) ch); + out.println("</pre>"); + out.println("</body>"); + } catch (IOException ex) { + throw new JspTagException("IOException: " + ex.toString()); + } + } catch (IOException ex2) { + throw new JspTagException("IOException: " + ex2.toString()); } return super.doEndTag(); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org