tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <h...@visi.com>
Subject Re: Tomcat 5.0.14 classloader bug
Date Sat, 29 Nov 2003 02:27:50 GMT

This will almost certainly get lost in the shuffle unless you post the bug 
to Apache's Bugzilla.  Better get it in soon before they make the next 
release...
http://issues.apache.org/bugzilla/

Jake

At 01:40 AM 11/29/2003 +0100, you wrote:
>Hello,
>
>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 convenience.
>
>import java.io.*;
>import java.net.URL;
>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()+" : "+
>             getClass().getResourceAsStream("Test.class");
>         out.println(tst);
>         out.close();
>     }
>}
>
>
>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 : 
>java.io.BufferedInputStream@6a3960 : java.io.ByteArrayInputStream@1dccedd
>
>
>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
>message
>description The server encountered an internal error () that prevented it 
>from fulfilling this request.
>exception
>java.io.FileNotFoundException: 
>/jakarta-tomcat-5.0.14/work/Catalina/localhost/_/loader/Test.class
>(No such file or directory)
>java.io.FileInputStream.open(Native Method)
>java.io.FileInputStream.(FileInputStream.java:106)
>java.io.FileInputStream.(FileInputStream.java:66)
>sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:69)
>sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:156)

>java.net.URL.openStream(URL.java:913)
>Test.service(Test.java:13)
>javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
>
>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 
>org.apache.catalina.loader.WebappClassLoader.
>
>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
>
>--
>Geert Bevin                       Uwyn
>"Use what you need"               Rue Victor Cuvelier 57
>http://www.uwyn.com               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 pgp.mit.edu, wwwkeys.pgp.net
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


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


Mime
View raw message