cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefano Mazzocchi <stef...@apache.org>
Subject [BUGFIX] AdaptiveClassLoader chokes on resources loaded from compressed archives
Date Wed, 29 Mar 2000 18:32:28 GMT
Hi guys, 

I'm back to tell you that I _NEED_ this fixed ASAP because it's a very
nasty bug that prevents operations of complex web applications that
reside on servlet zones.

The problem is simple to recreate:

1) create a jar file with both classes, servlets and files (i.e. images)
2) place your jar file as your servlet zone repository
3) try accessing the resource files with
this.getClass().getResourceAsStream()

Results are:

- IBM 1.1.8 -> NullPointerException at
java.util.zip.ZipFile.read(ZipFile.java:120)
- SUN 1.2.2 (classic VM) -> general protection fault!!!

Yes, people, this bug kills the VM! And shortly you'll understand
why....

It took me a while to figure out if this was a 1.1 vs. 1.2 problem and
to actually understand what was going on (messing with classloaders is
not exactly an easy task, expecially when you must be both 1.1 and 1.2
compliant with the exact same code!)

BTW, the problem is here

    /**
     * Loads resource from a zip file
     */
    private InputStream loadResourceFromZipfile(File file, String name)
{
        ZipFile zipfile = null;
        try {
            zipfile = new ZipFile(file);
            ZipEntry entry = zipfile.getEntry(name);

            if (entry != null) {
                return zipfile.getInputStream(entry);
            } else {
                return null;
            }
        } catch(IOException e) {
            return null;
        } finally {
            if ( zipfile != null ) {
                try {
                    zipfile.close();
                } catch ( IOException ignored ) {
                }
            }
        }
    }

Note anything wrong? Well, somebody believed that once you have the
output stream, it's safe to "close" the Zip file. Evidently it is not!

My quick and dirty bugfix goes like this

    private InputStream loadResourceFromZipfile(File file, String name)
{
        try {
            ZipFile zipfile = new ZipFile(file);
            ZipEntry entry = zipfile.getEntry(name);
            return (entry == null) ? entry :
zipfile.getInputStream(entry);
        } catch(IOException e) {
            return null;
        }
     }

but this leaves the ZIP file open all the time.... the problem is that
there is _no_ absolute way to know where all the released
ZipInputStreams are closed so that it is safe to close the ZIP file.

Note that this does not prevent jar hot-reloading, IMO, but the
AdaptiveClassLoader is not able to do it anyway (another bug I'd like to
fix, but that is much less critical).

Ok, people, tell me what you think and if good, I'll patch it myself.

Also, I would like to propose an ApacheJServ 1.1.1 release ASAP.

Comments?

-- 
Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<stefano@apache.org>                             Friedrich Nietzsche
--------------------------------------------------------------------
 Missed us in Orlando? Make it up with ApacheCON Europe in London!
------------------------- http://ApacheCon.Com ---------------------


Mime
View raw message