DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10127>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10127

tomcat 4.0.4 locks jsp files





------- Additional Comments From [EMAIL PROTECTED]  2003-08-21 10:53 -------
Hi,

I think I found the reason for this behaviour.

>From my point of view the reason can be found in the method loadJSP
in org.apache.jasper.servlet.JspServlet (lines 509 till 590) in JspServlet.java.
(I refer to Tomcat 4.0.4 here, but this seems to be also valid for all later
versions
of Tomcat, including 4.1.x).

Lines 509-517:

    boolean loadJSP(String jspUri, String classpath,
        boolean isErrorPage, HttpServletRequest req, HttpServletResponse res)
        throws JasperException, FileNotFoundException
    {
        // First check if the requested JSP page exists, to avoid creating
        // unnecessary directories and files.
        if (context.getResourceAsStream(jspUri) == null)
            throw new FileNotFoundException(jspUri);
 
To be more precise I see the problem in context.getResourceAsStream(jspUri).
On success context.getResourceAsStream(jspUri) returns an InputStream.
But this instance of InputStream is discarded immediately after the if clause
without
calling the close method to close the file. So the file jspUri stays open until this
instance of InputStream gets collected by the garbage collection of the VM
during which
the finalize method will close the file via the close method.
 
So I would like to propose the following straight forward patch to solve this
(against 4.0.4):

diff -Nru
jakarta-tomcat-4.0.4-src.orig/jasper/src/share/org/apache/jasper/servlet/JspServlet.java
jakarta-tomcat-4.0.4-src/jasper/src/share/org/apache/jasper/servlet/JspServlet.java
---
jakarta-tomcat-4.0.4-src.orig/jasper/src/share/org/apache/jasper/servlet/JspServlet.java
2002-06-11 07:09:42.000000000 +0200
+++
jakarta-tomcat-4.0.4-src/jasper/src/share/org/apache/jasper/servlet/JspServlet.java
2003-08-20 22:19:11.000000000 +0200
@@ -68,6 +68,7 @@
 
 import java.util.Hashtable;
 import java.util.Enumeration;
+import java.io.InputStream;
 import java.io.File;
 import java.io.PrintWriter;
 import java.io.IOException;
@@ -510,11 +511,23 @@
        boolean isErrorPage, HttpServletRequest req, HttpServletResponse res) 
        throws JasperException, FileNotFoundException 
     {
+        InputStream JspPage;
+
        // First check if the requested JSP page exists, to avoid creating
        // unnecessary directories and files.
-       if (context.getResourceAsStream(jspUri) == null)
+       if ((JspPage = context.getResourceAsStream(jspUri)) == null) {
            throw new FileNotFoundException(jspUri);
-
+        }
+        else {
+          // Close InputStream to avoid file descriptor resource leak
+          // and file locking with Windows
+          try {
+              JspPage.close();
+          } catch (IOException e) {
+          // Ignore any IOException in this case
+          }
+        }
+            
        JspServletWrapper jsw=(JspServletWrapper) jsps.get(jspUri);
        if( jsw==null ) {
            throw new JasperException("Can't happen - JspServletWrapper=null");



This patch should be also applicable in general to all Tomcat versions after 4.0.4.


Regards

RĂ¼diger

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to