You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Petr Jiricka <pe...@netbeans.com> on 2000/04/17 16:59:48 UTC
[PATCH] RE: [Bug 100] Changed - The JSP compiler does not check f
or cyclic include directives
Hello,
I am sorry for not looking at this bugfix earlier, I didn't have much time.
But it seems to me that the bugfix introduced another bug - now you can't
include the same file twice in one file. I just noticed now that if you try
to run a page like this:
<html>
hello<br>
<%@include file="incl.jsp"%>
hello2<br>
<%@include file="incl.jsp"%>
hello3<br>
</html>
(which I think you should be able to do), the engine throws the following
exception:
org.apache.jasper.compiler.ParseException: Seen file \incl.jsp already,
maybe this is a recursive include?!
at org.apache.jasper.compiler.JspReader.pushFile(JspReader.java:152)
at org.apache.jasper.compiler.JspReader.pushFile(JspReader.java:127)
at
org.apache.jasper.compiler.JspParseEventListener.handleDirective(JspParseEve
ntListener.java:686)
at
org.apache.jasper.compiler.DelegatingListener.handleDirective(DelegatingList
ener.java:116)
at
org.apache.jasper.compiler.Parser$Directive.accept(Parser.java:215)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1073)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1038)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1034)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:182)
at org.apache.jasper.runtime.JspServlet.loadJSP(JspServlet.java:413)
at
org.apache.jasper.runtime.JspServlet$JspServletWrapper.loadIfNecessary(JspSe
rvlet.java:149)
at
org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.ja
va:161)
at
org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:261)
at org.apache.jasper.runtime.JspServlet.service(JspServlet.java:369)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:502)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:160)
at
org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338
)
at java.lang.Thread.run(Thread.java:484)
.
I believe the patch below fixes this (I tested it).
Petr
W:\Development\src_jakarta\jakarta-tomcat\jakarta-tomcat\src\share\org\apach
e\jasper\compiler>cvs diff -u *.java
Index: JspReader.java
===================================================================
RCS file:
/home/cvspublic/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspReade
r.java,v
retrieving revision 1.13
diff -u -r1.13 JspReader.java
--- JspReader.java 2000/03/28 04:29:48 1.13
+++ JspReader.java 2000/04/17 14:48:05
@@ -101,8 +101,6 @@
* @return The index of the now registered file.
*/
protected int registerSourceFile(String file) {
- if (sourceFiles.contains(file))
- return -1;
sourceFiles.addElement(file);
this.size++;
return sourceFiles.size()-1;
@@ -148,12 +146,6 @@
// Register the file, and read its content:
int fileid = registerSourceFile(file.getAbsolutePath());
- if (fileid == -1)
- throw new
ParseException(Constants.getString("jsp.error.file.already.registered",
- new Object[] {
- file
- }));
-
InputStreamReader reader = null;
try {
@@ -181,7 +173,11 @@
if (current == null) {
current = new Mark( this, caw.toCharArray(), fileid,
file.getParent(), encoding );
} else {
- current.pushStream( caw.toCharArray(), fileid,
file.getParent(), encoding );
+ if (!current.pushStream( caw.toCharArray(), fileid,
file.getParent(), encoding ))
+ throw new
ParseException(Constants.getString("jsp.error.file.already.registered",
+ new
Object[] {
+ file
+ }));
}
} catch (FileNotFoundException fnfe) {
Index: Mark.java
===================================================================
RCS file:
/home/cvspublic/jakarta-tomcat/src/share/org/apache/jasper/compiler/Mark.jav
a,v
retrieving revision 1.2
diff -u -r1.2 Mark.java
--- Mark.java 1999/12/21 13:14:16 1.2
+++ Mark.java 2000/04/17 14:48:11
@@ -148,11 +148,19 @@
* @param inStream new stream for mark
* @param inFileid id of new file from which stream comes from
* @param inBaseDir directory of file
- * @param inEncoding encoding of new file
+ * @param inEncoding encoding of new file
+ * @return true if the file has not been registered yet, false if a
cycle was detected
*/
- public void pushStream(char[] inStream, int inFileid, String inBaseDir,
+ public boolean pushStream(char[] inStream, int inFileid, String
inBaseDir,
String inEncoding)
{
+ // check that the file has not been registered yet
+ String newFile = reader.getFile(inFileid);
+ for (int i = 0; i < includeStack.size() - 1; i++) {
+ String file =
reader.getFile(((IncludeState)includeStack.elementAt(i)).fileid);
+ if (newFile.equals(file))
+ return false;
+ }
// store current state in stack
includeStack.push(new IncludeState(cursor, line, col, fileid,
baseDir,
@@ -166,6 +174,8 @@
baseDir = inBaseDir;
encoding = inEncoding;
stream = inStream;
+
+ return true;
}
> -----Original Message-----
> From: bugzilla-daemon@locus.apache.org
> [mailto:bugzilla-daemon@locus.apache.org]
> Sent: Friday, March 31, 2000 1:36 AM
> To: Anil.Vijendran@eng.sun.com; petr.jiricka@netbeans.com
> Subject: [Bug 100] Changed - The JSP compiler does not check
> for cyclic
> include directives
>
>
> http://jakarta.apache.org/bugs/show_bug.cgi?id=100
>
> *** shadow/100 Tue Mar 21 05:32:30 2000
> --- shadow/100.tmp.25523 Thu Mar 30 15:36:20 2000
> ***************
> *** 3,10 ****
> Version: 3.1
> Platform: All
> OS/Version: All
> ! Status: NEW
> ! Resolution:
> Severity: normal
> Priority: P2
> Component: JSP
> --- 3,10 ----
> Version: 3.1
> Platform: All
> OS/Version: All
> ! Status: RESOLVED
> ! Resolution: FIXED
> Severity: normal
> Priority: P2
> Component: JSP
> ***************
> *** 16,18 ****
> --- 16,22 ----
> If tho pages include each other by the <%@include
> directive, the compiler end
> in an infinite loop (and eventually the JVM crashes with
> OutOfMemoryError),
> instead of detecting the cycle and reporting a compilation error.
> +
> + ------- Additional Comments From Anil.Vijendran@eng.sun.com
> 03/30/00 15:36 -------
> + I think I fixed this. Please help me verify this works for
> you. Thanks for the
> + bug report.
>