See below.

On Fri, 20 Jul 2001, Immanuel, Gidado-Yisa wrote:

> 
> > -----Original Message-----
> > From: Scott Sanders [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, July 19, 2001 5:00 PM
> > 
> > Committed, thank you very much.  The only thing is that I 
> > updated to include
> > the other rules that looked for the context class loader, 
> > that you did not
> > include in your patch.  Good patch otherwise!
> 
> Sorry, I did not look to hard to see where else the
> classloader was used.
> 
> > Gidado, could you test the patch to see if it is what you are 
> > expecting?
> > Thanks a lot.
> 
> I've updated my sandbox, and the changes work fine for me. 
> My test was to run it againt my own code, otherwise there
> was no extensive testing.
> 
> > About the default being false (do not use context class loader), I was
> > wondering if that should be true or not?  All of my use of 
> > Digester is in a
> > web application context, so I would prefer it to be true.  
> > What are other
> > people's thoughts on the matter.
> 
> Yes, I use it in webapp context also.  Let's explore 2 scenarios
> starting with the following:
> 
>     . my code (in webapp context) creates a Digester
>     . add rule-A to digester
>     . call digester.parse()
> 
> Senario 1: digester.setUseContextClassLoader(false)
>     . digester fires rule-A which needs class 'my.code.Run'
>     . uses Class.forName() which uses ClassLoader of Digester
>       Digester is defined in webapp-ClassLoader, so that's
>       the one that's used
>     . webapp-ClassLoader delegates to bootClassLoader, which
>       fails to find it
>     . the webapp-Classloader looks for and finds the class
> 
> Senario 2: digester.setUseContextClassLoader(true)
>     . digester fires rule-A which needs class 'a.b.stuff'    
>     . uses the Context ClassLoader.  This classloader is rooted
>       in the servlet-container and is quite likely the
>       bootClassLoader.

This is not actually correct.  In most current servlet containers, the
context class loader is set to the webapp class loader for the request
currently being processed by this thread.  This behavior will be mandated
in J2EE 1.3.

>     . bootClassLoader cannot find the class, and the
>       ClassNotFoundException is thrown.
> 
> Scenario 1 is the behavior I want, so I set it as the default.
> In fact, do we ever really need to check the Context ClassLoader
> at all?
> 

There are two more scenarios that matter, even in a web application
environment.  That's when commons-digester.jar is itself loaded in a
shared directory (such as the $TOMCAT_HOME/lib directory in Tomcat),
instead of in /WEB-INF/lib.  In that scenario, defaulting to "true" leads
to the more useful behavior, because it gives Digester access to the
classes in the web app, even though Digester itself is shared.

> - Gidado
> 

Craig McClanahan


Reply via email to