Got the following error on Win2K but not on Linux. It appears that the Jasper compiler misinterprets the driver letter (e.g., "D") for the line number of an error message. Line 314 of org.apache.jasper.compiler.Compiler tries to identify a drive letter on Windows platforms by the existence of two colons in the error message, but there's no conditional to compensate for the extra colon when present. ----- Root Cause ----- java.lang.NumberFormatException: D at java.lang.Integer.parseInt(Integer.java:405) at java.lang.Integer.parseInt(Integer.java:454) at org.apache.jasper.compiler.Compiler.getJspLineErrors(Unknown Source) at org.apache.jasper.compiler.Compiler.compile(Unknown Source) at org.apache.jasper.servlet.JspServlet.loadJSP(Unknown Source) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessar y(Unknown Source) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknow n Source) at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source) at org.apache.jasper.servlet.JspServlet.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationDispatcher.invoke(Unknown Source) at org.apache.catalina.core.ApplicationDispatcher.doInclude(Unknown Sour ce) at org.apache.catalina.core.ApplicationDispatcher.include(Unknown Source ) at org.apache.jasper.runtime.JspRuntimeLibrary.include(Unknown Source) at org.apache.jsp.login$jsp._jspService(login$jsp.java:70) at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknow n Source) at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source) at org.apache.jasper.servlet.JspServlet.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationDispatcher.invoke(Unknown Source) at org.apache.catalina.core.ApplicationDispatcher.doForward(Unknown Sour ce) at org.apache.catalina.core.ApplicationDispatcher.forward(Unknown Source ) at LoginServlet.doGet(LoginServlet.java:31) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unkn own Source) at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Sour ce) at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Unknown So urce) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContext.invoke(Unknown Source) at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.valves.AccessLogValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.connector.http.HttpProcessor.process(Unknown Sour ce) at org.apache.catalina.connector.http.HttpProcessor.run(Unknown Source) at java.lang.Thread.run(Thread.java:484)
Can you attach a test case that causes this problem? I am not quite sure what you meant by "the extra colon". Are you referring to the colon after the drive (such as D:)? That was being taken care of. All my tests ran as expected.
Here's a stripped-down JSP that exhibits the problem. I will admit that the cause of the problem must be very specific because the NumberFormatException does not occur if you remove the <table> element and its contents from this example. <%@page session="true" %> <jsp:useBean id="foo" class="Foo" scope="session"><% foo = new Foo("Unknown"); % ></jsp:useBean> <table> <% Boolean loggedIn = (Boolean)session.getValue("loggedIn"); if(loggedIn == null) { loggedIn = new Boolean(false); } if(loggedIn.booleanValue()) { out.println("<tr><td><a class=\"nav\" href=\"A\">A</a></td></tr>"); if(foo != null && !foo.isOut()) out.println("<tr><td><a class=\"nav\" href=\"B\">B</a></td></tr>"); out.println("<tr><td><a class=\"nav\" href=\"c.jsp\">C</a></td></tr>"); out.println("<tr><td><a class=\"nav\" href=\"d.jsp\">D</a></td></tr>"); } else { out.println("<tr><td><a class=\"nav\" href=\"E\">E</a></td></tr>"); out.println("<tr><td><a class=\"nav\" href=\"f.jsp\">F</a></td></tr>"); } %> </table>
Thanks for the test case. However, due to the added line break, I am not sure I got what you have. I guess the <jsp:useBean ... >..</jsp:useBean> is one line, not two. How about the lines out.println("<tr><td><a class=\"nav\" href=\"B\">B</a></td></tr>"); If there is a line break after the first line, then this would cause a compilation error. Is this the cause of your NumberFormatException? I tried it with and without the line break, and didn't get NumberFormatException. Can you go to tomcat/work/localhost area and locate the .java generated by jasper, and post that here. I look at the .java I got, and didn't see any extra colons that may cause NumberFormatException. However, I do notice a couple of problems with Jasper. The first is of course if there is a colon (maybe in a string literal) in the program, then you'll get the NumberFormatException like you said. I'll try to catch it locally. The second is if the string contains tags, they should be escape'd so that they won't be interpreted by the browser.
Here's the generated code for the example JSP I sent earlier. To be clear, I don't think there's a colon in the generated code that's causing the problem, but rather it's the parsing of the compiler error message when running on Windows. And also, there are no extraneous line breaks in the JSP or generated code. Those line breaks are a side effect of pasting into the Bugzilla form. package org.apache.jsp; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import org.apache.jasper.runtime.*; public class navigator$jsp extends HttpJspBase { // begin [file="/navigator.jsp";from=(1,0);to=(1,50)] // end static { } public navigator$jsp( ) { } private static boolean _jspx_inited = false; public final void _jspx_init() throws org.apache.jasper.runtime.JspException { } public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { JspFactory _jspxFactory = null; PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; String _value = null; try { if (_jspx_inited == false) { synchronized (this) { if (_jspx_inited == false) { _jspx_init(); _jspx_inited = true; } } } _jspxFactory = JspFactory.getDefaultFactory(); response.setContentType("text/html;charset=ISO-8859-1"); pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true); application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); // HTML // begin [file="/navigator.jsp";from=(0,25);to=(1,0)] out.write("\r\n"); // end // begin [file="/navigator.jsp";from=(1,0);to=(1,50)] Foo foo = null; boolean _jspx_specialfoo = false; synchronized (session) { foo= (Foo) pageContext.getAttribute("foo",PageContext.SESSION_SCOPE); if ( foo == null ) { _jspx_specialfoo = true; try { foo = (Foo) java.beans.Beans.instantiate (this.getClass().getClassLoader(), "Foo"); } catch (Exception exc) { throw new ServletException (" Cannot create bean of class "+"Foo", exc); } pageContext.setAttribute("foo", foo, PageContext.SESSION_SCOPE); } } if(_jspx_specialfoo == true) { // end // begin [file="/navigator.jsp";from=(1,52);to=(1,79)] foo = new Foo("Unknown"); // end // begin [file="/navigator.jsp";from=(1,0);to=(1,50)] } // end // HTML // begin [file="/navigator.jsp";from=(1,95);to=(4,0)] out.write("\r\n\r\n<table>\r\n"); // end // begin [file="/navigator.jsp";from=(4,2);to=(21,0)] Boolean loggedIn = (Boolean)session.getValue("loggedIn"); if(loggedIn == null) { loggedIn = new Boolean(false); } if(loggedIn.booleanValue()) { out.println("<tr><td><a class=\"nav\" href=\"A\">A</a></td></tr>"); if(foo != null && !foo.isOut()) out.println("<tr><td><a class=\"nav\" href=\"B\">B</a></td></tr>"); out.println("<tr><td><a class=\"nav\" href=\"c.jsp\">C</a></td></tr>"); out.println("<tr><td><a class=\"nav\" href=\"d.jsp\">D</a></td></tr>"); } else { out.println("<tr><td><a class=\"nav\" href=\"E\">E</a></td></tr>"); out.println("<tr><td><a class=\"nav\" href=\"f.jsp\">F</a></td></tr>"); } // end // HTML // begin [file="/navigator.jsp";from=(21,2);to=(24,0)] out.write("\r\n</table>\r\n\r\n"); // end } catch (Throwable t) { if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (pageContext != null) pageContext.handlePageException(t); } finally { if (_jspxFactory != null) _jspxFactory.releasePageContext (pageContext); } } }
If I remove the line break, then the messages I got are related to Foo not being defined etc, and that works on NT. Also I didn't see anything unusual with your .java file. Anyway I fixed Jasper so that it catches the NumberFormatException and display the error line without mapping back to the jsp file. I am closing this bug as fixed. Please try running the test again with the new fix. If you still have problems, you can reopen the bug. thanks.