--- src/share/org/apache/jasper/compiler/DefaultErrorHandler.java (revision 534336) +++ src/share/org/apache/jasper/compiler/DefaultErrorHandler.java (working copy) @@ -79,6 +79,17 @@ buf.append(details[i].getErrorMessage()); buf.append("\n"); buf.append(details[i].getJspExtract()); + } else if (details[i].getJavaLineNumber() >= 0) { + args = new Object[] { + new Integer(details[i].getJavaLineNumber()), + details[i].getJavaFileName()}; + buf.append("\n"); + buf.append(Localizer.getMessage("jsp.error.single.line.number.servlet", + args)); + buf.append("\n"); + buf.append(details[i].getErrorMessage()); + buf.append("\n"); + buf.append(details[i].getJspExtract()); } } buf.append("\n\nStacktrace:"); --- src/share/org/apache/jasper/compiler/JavacErrorDetail.java (revision 534336) +++ src/share/org/apache/jasper/compiler/JavacErrorDetail.java (working copy) @@ -18,6 +18,7 @@ package org.apache.jasper.compiler; import java.io.BufferedReader; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -54,10 +55,7 @@ int javaLineNum, StringBuffer errMsg) { - this.javaFileName = javaFileName; - this.javaLineNum = javaLineNum; - this.errMsg = errMsg; - this.jspBeginLineNum = -1; + this(javaFileName, javaLineNum, null, -1, errMsg); } /** @@ -88,19 +86,28 @@ int jspBeginLineNum, StringBuffer errMsg, JspCompilationContext ctxt) { - this(javaFileName, javaLineNum, errMsg); + this.javaFileName = javaFileName; + this.javaLineNum = javaLineNum; this.jspFileName = jspFileName; + this.errMsg = errMsg; this.jspBeginLineNum = jspBeginLineNum; - - if (jspBeginLineNum > 0 && ctxt != null) { - try { + + int beginLineNum = 0; + String[] sourceLines = null; + InputStream javaStream = null; + InputStream jspStream = null; + + try { + // To display canonical path at DefaultErrorHandler. + this.javaFileName = (new File(javaFileName)).getCanonicalPath(); + javaStream = new FileInputStream(this.javaFileName); + String[] javaLines = readFile(javaStream); + + if (jspBeginLineNum > 0 && ctxt != null) { // Read both files in, so we can inspect them - String[] jspLines = readFile - (ctxt.getResourceAsStream(jspFileName)); + jspStream = ctxt.getResourceAsStream(jspFileName); + String[] jspLines = readFile(jspStream); - String[] javaLines = readFile - (new FileInputStream(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... @@ -116,26 +123,40 @@ } } } - - // copy out a fragment of JSP to display to the user - StringBuffer fragment = new StringBuffer(1024); - int startIndex = Math.max(0, this.jspBeginLineNum-1-3); - int endIndex = Math.min( - jspLines.length-1, this.jspBeginLineNum-1+3); - - for (int i=startIndex;i<=endIndex; ++i) { - fragment.append(i+1); - fragment.append(": "); - fragment.append(jspLines[i]); - fragment.append("\n"); - } - jspExtract = fragment.toString(); - - } catch (IOException ioe) { - // Can't read files - ignore + beginLineNum = this.jspBeginLineNum; + sourceLines = jspLines; + } else { + beginLineNum = javaLineNum; + sourceLines = javaLines; } + + // copy out a fragment of JSP to display to the user + StringBuffer fragment = new StringBuffer(1024); + int startIndex = Math.max(0, beginLineNum-1-3); + int endIndex = Math.min(sourceLines.length-1, beginLineNum-1+3); + + for (int i=startIndex;i<=endIndex; ++i) { + fragment.append(i+1); + fragment.append(": "); + fragment.append(sourceLines[i]); + fragment.append("\n"); + } + jspExtract = fragment.toString(); + + } catch (IOException ioe) { + // Can't read files - ignore + } finally{ + if (javaStream != null){ + try { + javaStream.close(); + } catch (IOException e) {} + } + if (jspStream != null){ + try { + jspStream.close(); + } catch (IOException e) {} + } } - } /** * Gets the name of the Java source file in which the compilation error --- src/share/org/apache/jasper/resources/LocalStrings.properties (revision 534336) +++ src/share/org/apache/jasper/resources/LocalStrings.properties (working copy) @@ -300,6 +300,7 @@ jsp.error.needAlternateJavaEncoding=Default java encoding {0} is invalid on your java platform. An alternate can be specified via the 'javaEncoding' parameter of JspServlet. #Error when compiling, used for jsp line number error messages jsp.error.single.line.number=An error occurred at line: {0} in the jsp file: {1} +jsp.error.single.line.number.servlet=An error occurred at line: {0} in the generated servlet: {1} jsp.error.multiple.line.number=\n\nAn error occurred between lines: {0} and {1} in the jsp file: {2}\n\n jsp.error.corresponding.servlet=Generated servlet error:\n jsp.error.empty.body.not.allowed=Empty body not allowed for {0} --- src/share/org/apache/jasper/resources/LocalStrings_ja.properties (revision 534336) +++ src/share/org/apache/jasper/resources/LocalStrings_ja.properties (working copy) @@ -294,6 +294,7 @@ jsp.error.needAlternateJavaEncoding=\u30c7\u30d5\u30a9\u30eb\u30c8\u306eJava\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0 {0} \u306f\u3042\u306a\u305f\u306e\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u3067\u306f\u7121\u52b9\u3067\u3059\u3002JspServlet\u306e 'javaEncoding' \u30d1\u30e9\u30e1\u30bf\u3067\u3001\u5225\u306e\u5024\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 #Error when compiling, used for jsp line number error messages jsp.error.single.line.number=JSP\u30d5\u30a1\u30a4\u30eb: {1} \u306e\u4e2d\u306e{0}\u884c\u76ee\u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f +jsp.error.single.line.number.servlet=\u751f\u6210\u3055\u308c\u305f\u30b5\u30fc\u30d6\u30ec\u30c3\u30c8: {1} \u306e\u4e2d\u306e{0}\u884c\u76ee\u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f jsp.error.multiple.line.number=\n\nJPS\u30d5\u30a1\u30a4\u30eb: {2}\u306e\u4e2d\u306e{0}\u884c\u76ee\u3068{1}\u884c\u76ee\u306e\u9593\u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\n\n jsp.error.corresponding.servlet=\u751f\u6210\u3055\u308c\u305f\u30b5\u30fc\u30d6\u30ec\u30c3\u30c8\u306e\u30a8\u30e9\u30fc\u3067\u3059:\n jsp.error.empty.body.not.allowed={0} \u306b\u5bfe\u3057\u3066\u7a7a\u306e\u30dc\u30c7\u30a3\u306f\u8a31\u3055\u308c\u307e\u305b\u3093 @@ -405,3 +406,4 @@ jsp.error.invalid.bean=useBean\u306e\u30af\u30e9\u30b9\u5c5e\u6027 {0} \u306e\u5024\u304c\u7121\u52b9\u3067\u3059 jsp.error.prefix.use_before_dcl=\u3053\u306e\u30bf\u30b0\u6307\u793a\u5b50\u3067\u6307\u5b9a\u3055\u308c\u3066\u3044\u308b\u30d7\u30ea\u30d5\u30a3\u30c3\u30af\u30b9 {0} \u306f\u3001\u3059\u3067\u306b\u30d5\u30a1\u30a4\u30eb {1} \u306e {2} \u884c\u76ee\u306e\u30a2\u30af\u30b7\u30e7\u30f3\u3067\u4f7f\u7528\u3055\u308c\u3066\u3044\u307e\u3059 +