ASF Bugzilla – Attachment 16679 Details for
Bug 37062
More helpful message when exceptions are raised on JSPs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch file generated against SVN on October 12th 2005
svn-diff.patch (text/plain), 8.11 KB, created by
Tim Fennell
on 2005-10-13 03:43:08 UTC
(
hide
)
Description:
Patch file generated against SVN on October 12th 2005
Filename:
MIME Type:
Creator:
Tim Fennell
Created:
2005-10-13 03:43:08 UTC
Size:
8.11 KB
patch
obsolete
>Index: tc5.5.x/jasper2/src/share/org/apache/jasper/servlet/JspServletWrapper.java >=================================================================== >2c2 >< * Copyright 1999,2004 The Apache Software Foundation. >--- >> * Copyright 1999,2005 The Apache Software Foundation. >19,21c19,28 >< import java.io.FileNotFoundException; >< import java.io.IOException; >< import java.net.URL; >--- >> import org.apache.commons.logging.Log; >> import org.apache.commons.logging.LogFactory; >> import org.apache.jasper.JasperException; >> import org.apache.jasper.JspCompilationContext; >> import org.apache.jasper.Options; >> import org.apache.jasper.compiler.JspRuntimeContext; >> import org.apache.jasper.compiler.Localizer; >> import org.apache.jasper.compiler.ErrorDispatcher; >> import org.apache.jasper.compiler.JavacErrorDetail; >> import org.apache.jasper.runtime.JspSourceDependent; >32,40c39,47 >< >< import org.apache.commons.logging.Log; >< import org.apache.commons.logging.LogFactory; >< import org.apache.jasper.JasperException; >< import org.apache.jasper.JspCompilationContext; >< import org.apache.jasper.Options; >< import org.apache.jasper.compiler.JspRuntimeContext; >< import org.apache.jasper.compiler.Localizer; >< import org.apache.jasper.runtime.JspSourceDependent; >--- >> import java.io.FileNotFoundException; >> import java.io.IOException; >> import java.io.InputStream; >> import java.io.BufferedReader; >> import java.io.InputStreamReader; >> import java.io.FileInputStream; >> import java.net.URL; >> import java.util.List; >> import java.util.ArrayList; >56a64 >> * @author Tim Fennell >273d280 >< >363,364c370,373 >< } catch (ServletException ex) { >< throw ex; >--- >> } >> catch (ServletException ex) { >> if (options.getDevelopment()) throw handleJspException(ex); >> else throw ex; >366c375,376 >< throw ex; >--- >> if (options.getDevelopment()) throw handleJspException(ex); >> else throw ex; >368c378,379 >< throw ex; >--- >> if (options.getDevelopment()) throw handleJspException(ex); >> else throw ex; >369a381,430 >> throw options.getDevelopment() ? handleJspException(ex) : >> new JasperException(ex); >> } >> } >> >> /** >> * <p>Attempts to construct a JasperException that contains helpful information >> * about what went wrong. Uses the JSP compiler system to translate the line >> * number in the generated servlet that originated the exception to a line >> * number in the JSP. Then constructs an exception containing that >> * information, and a snippet of the JSP to help debugging.</p> >> * >> * @param ex the exception that was the cause of the problem. >> * @return a JasperException with more detailed information >> */ >> protected JasperException handleJspException(Exception ex) { >> try { >> Throwable realException = ex; >> if (ex instanceof ServletException) { >> realException = ((ServletException) ex).getRootCause(); >> } >> >> // First identify the stack frame in the trace that represents the JSP >> StackTraceElement[] frames = realException.getStackTrace(); >> StackTraceElement jspFrame = null; >> >> for (int i=0; i<frames.length; ++i) { >> if ( frames[i].getClassName().equals(this.getServlet().getClass().getName()) ) { >> jspFrame = frames[i]; >> break; >> } >> } >> >> if (jspFrame == null) { >> // If we couldn't find a frame in the stack trace corresponding >> // to the generated servlet class, we can't really add anything >> return new JasperException(ex); >> } >> else { >> int javaLineNumber = jspFrame.getLineNumber(); >> JavacErrorDetail detail = ErrorDispatcher.createJavacError( >> jspFrame.getMethodName(), >> this.ctxt.getCompiler().getPageNodes(), >> null, >> javaLineNumber); >> >> // If the line number is less than one we couldn't find out >> // where in the JSP things went wrong >> int jspLineNumber = detail.getJspBeginLineNumber(); >> if (jspLineNumber < 1) { >371a433,451 >> >> // Read both files in, so we can inspect them >> String[] jspLines = readFile >> (this.ctxt.getResourceAsStream(this.ctxt.getJspFile())); >> >> String[] javaLines = readFile >> (new FileInputStream(this.ctxt.getServletJavaFileName())); >> >> // If the line contains the opening of a multi-line scriptlet >> // block, then the JSP line number we got back is probably >> // faulty. Scan forward to match the java line... >> if (jspLines[jspLineNumber-1].lastIndexOf("<%") > >> jspLines[jspLineNumber-1].lastIndexOf("%>")) { >> String javaLine = javaLines[javaLineNumber-1].trim(); >> >> for (int i=jspLineNumber-1; i<jspLines.length; i++) { >> if (jspLines[i].contains(javaLine)) { >> jspLineNumber = i+1; >> break; >372a453,493 >> } >> } >> >> // copy out a fragment of JSP to display to the user >> StringBuffer buffer = new StringBuffer(1024); >> int startIndex = Math.max(0, jspLineNumber-1-3); >> int endIndex = Math.min(jspLines.length-1, jspLineNumber-1+3); >> >> for (int i=startIndex;i<=endIndex; ++i) { >> buffer.append(i+1); >> buffer.append(": "); >> buffer.append(jspLines[i]); >> buffer.append("\n"); >> } >> >> return new JasperException( >> "Exception in JSP: " + detail.getJspFileName() + ":" + >> jspLineNumber + "\n\n" + buffer + "\n\nStacktrace:", ex); >> } >> } catch (Exception je) { >> // If anything goes wrong, just revert to the original behaviour >> return new JasperException(ex); >> } >> } >> >> /** >> * Reads a text file from an input stream into a String[]. Used to read in >> * the JSP and generated Java file when generating error messages. >> */ >> private String[] readFile(InputStream s) throws IOException { >> BufferedReader reader = new BufferedReader(new InputStreamReader(s)); >> List lines = new ArrayList(); >> String line; >> >> while ( (line = reader.readLine()) != null ) { >> lines.add(line); >> } >> >> return (String[]) lines.toArray( new String[lines.size()] ); >> } >> >Index: tc5.5.x/jasper2/src/share/org/apache/jasper/compiler/Compiler.java >=================================================================== >2c2 >< * Copyright 1999,2004 The Apache Software Foundation. >--- >> * Copyright 1999,2005 The Apache Software Foundation. >18a19,23 >> import org.apache.jasper.JasperException; >> import org.apache.jasper.JspCompilationContext; >> import org.apache.jasper.Options; >> import org.apache.jasper.servlet.JspServletWrapper; >> >30,34d34 >< import org.apache.jasper.JasperException; >< import org.apache.jasper.JspCompilationContext; >< import org.apache.jasper.Options; >< import org.apache.jasper.servlet.JspServletWrapper; >< >293a294 >> >297c298,303 >< // memory footprint. >--- >> // memory footprint...but only get rid of the pageNodes if >> // in production mode, since they're used to generated errors >> if (!this.options.getDevelopment()) { >> pageNodes = null; >> } >> >301d306 >< pageNodes = null; >482a488,495 >> >> /** >> * <p>Retrieves the parsed nodes of the JSP page, if they are available. >> * May return null.</p> >> */ >> public Node.Nodes getPageNodes() { >> return this.pageNodes; >> }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 37062
: 16679