tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geert Bevin <>
Subject Tomcat 5.0.14 classloader bug
Date Sat, 29 Nov 2003 00:40:16 GMT

I think I've stumbled into a bug in the webapp classloader in Tomcat 5.0.14.

Consider the following servlet, which I mapped to /* for testing 

import javax.servlet.ServletException;
import javax.servlet.http.*;

public class Test extends HttpServlet
     public void service(HttpServletRequest req, HttpServletResponse res)
     throws ServletException, IOException
         PrintWriter out = res.getWriter();
         URL rsrc = getClass().getResource("Test.class");
         String tst = rsrc.toString()+" : "+
             rsrc.openStream()+" : "+

When I put the compiled class file in ROOT/WEB-INF/classes
and visit http://localhost:8080/ after a server startup, I get the 
following page:

file:/jakarta-tomcat-5.0.14/webapps/ROOT/WEB-INF/classes/Test.class : :

When I create a jar file with just that class inside, put it in 
ROOT/WEB-INF/lib (after removing everything from ROOT/WEB-INF/classes 
before) and visit http://localhost:8080/ after a server restart, I get 
the following page:

HTTP Status 500 -
type Exception report
description The server encountered an internal error () that prevented 
it from fulfilling this request.
(No such file or directory) Method)

The openStream() method has thrown this exception, and the 
getResourceAsStream("Test.class") method returns null.

There's clearly something wrong here, since the file is indeed not 
available on that location. The work directory 
"/jakarta-tomcat-5.0.14/work/Catalina/localhost/_" just contains one 
file: "tldCache.ser" and no directory "loader" at all.

I've looked through the sources and found some things in 

On line 552, the following is done:

public void setWorkDir(File workDir) {
     this.loaderDir = new File(workDir, "loader");

Which is where the "loader" directory comes from.

On line 1085, the following is done:

if (repository.endsWith(".jar")) {
     // Copy binary content to the work directory if not present
     File resourceFile = new File(loaderDir, name);
     url = resourceFile.toURL();

On line 1814, I found this:

// Extract resources contained in JAR to the workdir
if (!(path.endsWith(".class"))) {
     byte[] buf = new byte[1024];
     File resourceFile = new File
         (loaderDir, jarEntry.getName());
     if (!resourceFile.exists()) {

To me it seems that the code on line 1085 assumes that the code on line 
1814 has already been executed before, somehow this isn't the case which 
leads to unretrieval resources when they are stored in jar files.

I hope I identified this issue correctly and that it can be fixed for 
the next release.

Best regards,


Geert Bevin                       Uwyn
"Use what you need"               Rue Victor Cuvelier 57               7190 Ecaussinnes
gbevin[remove] at uwyn dot com    Tel +32 67 78 04 06

PGP Fingerprint : 4E21 6399 CD9E A384 6619  719A C8F4 D40D 309F D6A9
Public PGP key  : available at servers,

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message