Bug 44337

Summary: Dir listing crashes if no readme-file present
Product: Tomcat 6 Reporter: Dr. Albrecht Weinert <albrecht>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: blocker CC: albrecht
Priority: P2    
Version: 6.0.14   
Target Milestone: default   
Hardware: Sun   
OS: Windows Server 2003   
URL: http://www.a-weinert.de
Attachments: Patch to DefaultServlet.java

Description Dr. Albrecht Weinert 2008-02-01 01:54:32 UTC
DefaultServlet docu 6.0  says about attibute readmeFile:
If a directory listing is presented, a readme file
 *may* 
also be presented with the listing. This file is inserted
.....

This was true for 5.5.x.

6.0.14 crashes if the file is absent in the listed directory.
javax.servlet.ServletException: 
Error opening readme resource at
org.apache.catalina.servlets.DefaultServlet.getReadme(DefaultServlet.java:1418)

This new behaviour blocks the listing of big directory trees managed by others,
where the work-around is nor feasible.

Work around 1: readme file in *every* subdir, empty (length=0) if none wanted 
     (and subsequent changes in the used XSL-Transformers)
Work around 2: Change "may" to  "must" in docu.

Repair: fix DefaultServlet

From web.xml:

    <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>listings</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>globalXsltFile</param-name>
            <param-value>D:\www\serv-intra\meva-dir-li.xsl</param-value>
        </init-param>
        <init-param>
            <param-name>readmeFile</param-name>
            <param-value>readme.htm</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
Comment 1 Tim Funk 2008-02-02 10:34:59 UTC
Created attachment 21461 [details]
Patch to DefaultServlet.java

Patch is for tomcat6 trunk. 

When the readme resource is not found. A NamingException is thrown instead of
assuming null is returned.

Patch eats the NamingException and returns null as well as optionally logs it
if debugging turned up very high.

Same condition can occur with the localxslt lookup.
Comment 2 Tim Funk 2008-02-12 08:17:55 UTC
applied to version 6.0.17+