dev@glassfish.java.net

Re: Classloading strategy for OSGi <was> Fwd: [Jersey] Jersey in Felix

From: Eamonn McManus <Eamonn.McManus_at_Sun.COM>
Date: Mon, 08 Dec 2008 16:36:23 +0100

Hi,

Disclaimer: I know much more about class loading than I would like to.

The boolean parameter in question is usually unimportant. If the class has already been loaded, the
boolean makes no difference. If this is the first time the class is being loaded, then its static
initializer will be run only if this parameter is true. But otherwise the static initializer will be
run anyway as soon as you try to do pretty much anything with the Class that you have obtained.

I'm not sure I see the relation to 6500212, which is more about why you should always use
Class.forName(name, false, cl) rather than cl.loadClass(name). The latter is not guaranteed to work
for names of array types, such as "[Ljava.lang.String;" (which is String[].class.getName()).
Recognizing array types is not part of the contract of ClassLoader.loadClass, and in JDK 6
URLClassLoader stopped recognizing them.

Regards,
-- 
Éamonn McManus · JMX Spec Lead · http://weblogs.java.net/blog/emcmanus/
Roberto Chinnici wrote:
> Paul Sandoz wrote:
>> On Dec 4, 2008, at 9:23 AM, Roberto Chinnici wrote:
>>>         clazz = Class.forName(name, false, cl);
>>                                                                     ^
>>                                                                     |
>>                                                      Why is this 
>> "false" ?
> 
> In short, true vs. false won't make a difference except in the case of a 
> serialization framework trying to deserialize an array of a new type:
> 
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6500212
> 
> And no, I do not understand all the details.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>