You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2003/01/30 04:02:17 UTC

DO NOT REPLY [Bug 16577] New: - WebappClassLoader delegates to parent loader

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=16577>.
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=16577

WebappClassLoader delegates to parent loader

           Summary: WebappClassLoader delegates to parent loader
           Product: Tomcat 4
           Version: 4.1.18
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Critical
          Priority: Other
         Component: Catalina
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: bobbackfar@yahoo.com


Hope this is a false alarm, but here it is any way...

The WebappClassLoader is supposed to check WEB-INF classes and jar files before 
consulting its parent loader.  This is the basis for overriding many a library 
on a per-context basis.  The following test servlet demonstrates the problem:


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 * 
 */
public class ClassStats extends HttpServlet {


    public void doGet(
    HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
        
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        out.println("<html>");
        out.println("<head>");
        out.println("<title>" + getClass().getName() + "</title>");
        out.println("</head>");
        out.println("<body bgcolor=\"white\">");
        
        String className = request.getQueryString();
        
        try {
            Class clazz = Class.forName(className);
            out.println(
            "<table cellpadding=\"5\" cellspacing=\"10\" border=\"2\">");
            printNameValue("Name", className, out);
            printNameValue("ClassLoader", clazz.getClassLoader(), out);
            printNameValue(
            "Location",
            clazz.getProtectionDomain().getCodeSource().getLocation(), out);
            out.println("</table>");
        } catch (Exception x) {
            out.println("Encountered exception:");
            out.println("<pre>");
            x.printStackTrace(out);
            out.println("</pre>");
        }
        
        out.println("</body>");
        out.println("</html>");
    }
    
    
    private void printNameValue(String name, Object value, PrintWriter out) {
            out.println("<tr>");
            out.println("<td>");
            out.println(name);
            out.println("</td>");
            out.println("<td>");
            out.println(value);
            out.println("</td>");
            out.println("</tr>");
    }
}

The above servlet prints the location from which a given class
(specified in the query string) is loaded.  Including the activation.jar
file in the lib directory of the context in which the above servlet is defined,
for example, should yield something like

file:/<absolute path to context>/WEB-INF/lib/activation.jar

It doesn't.  Instead we get something like

file:/<CATALINA HOME>/commons/lib/activation.jar

As a reality-check, I *have* checked this behavior against
Tomcat 4.0.3, and the behavior there is correct.

-Babak.

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org