avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leo Sutic" <leo.su...@inspireinfrastructure.com>
Subject RE: DefaultLogTargetFactoryManager
Date Fri, 23 Nov 2001 13:11:28 GMT


> -----Original Message-----
> From: Peter Donald [mailto:peter@apache.org]
> Sent: den 22 november 2001 21:35
> To: Avalon Developers List
> Subject: Re: DefaultLogTargetFactoryManager
> 
> 
> On Fri, 23 Nov 2001 00:13, Leo Sutic wrote:
> > Java API for Thread.getContextClassLoader ():
> >
> > "Returns the context ClassLoader for this Thread. The context 
> ClassLoader
> > is provided by the creator of the thread for use by code running in this
> > thread when loading classes and resources.
> >
> > If not set, the default is the ClassLoader context of the parent Thread.
> >
> > The context ClassLoader of the primordial thread is typically set to the
> > class loader used to load the application."
> >
> > So that should be "never", as I understand it. Do you have any examples
> > when getContextClassLoader () == null?
> 
> oh - I thought it started out as null for some reason.

The API clearly states that the context class loader is not null.

UNLESS THE CONTEXT CLASS LOADER IS THE BOOTSTRAP CLASS LOADER.

So, my mistake here.

So what I propose is:

  Thread.currentThread ().getContextClassLoader ().loadClass (className);

          <==============Transforms into===================>

  Class.forName (className, true, Thread.currentThread ().getContextClassLoader ());

This works even if Thread.currentThread ().getContextClassLoader () == null as stated in the
API spec:

  If the parameter loader is null, the class is loaded through the bootstrap class loader.


Someday I'll get around to submit a patch to Cocoon's ClassUtils about this...

/LS



--
To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>


Mime
View raw message