avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <pe...@apache.org>
Subject Re: DefaultLogTargetFactoryManager
Date Sat, 24 Nov 2001 11:10:08 GMT
On Sat, 24 Nov 2001 00:11, Leo Sutic wrote:
> 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.

okay - that makes more sense to me - which is precisely why I like to first 
check by ContextClassLoader (via above) and then check the using calling 
class loader. Rarely is any of the needed classes in the bootstrap 
classloader but it is likely that they are in the calling classloader. Thus I 
would still use

Class clazz = null;

try
{
  clazz = Class.forName (className, true, 
      Thread.currentThread().getContextClassLoader ());
}
catch( final ClassNotFoundException cnfe )
{
  clazz = Class.forName( className );
}

if at all possible. This maybe partially because I am used to having apps 
work in both hosted (ala servlets/blocks/ejbs) and unhosted environments 
(normal apps).

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

;)

-- 
Cheers,

Pete

----------------------------------
   "Don't play dumb with me. 
I happen to be an expert at that" 
           - Maxwell Smart
----------------------------------

--
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