On Tue, 24 Jul 2001 17:15, Stephane Bailliez wrote:
> Yes, but this is the expected behavior and perfectly logical...
> Here in fact what I had in mind was if there was some *trouble*
> (bugs/features) associated with Class.forName() use.
> For example I bumped into this message:
> http://lists.w3.org/Archives/Public/www-jigsaw/1999JanFeb/0046.html
Another "bug" (or feature) that often catches people is that classes loaded
via references are not necessarily initialized immediately. For instance
about a week ago I ran into bug where something like
class MyClass
{
public final static String MY_CLASS_NAME = MyClass.class.getName();
}
Under certain conditions this can cause a NPE because the class object has
not been initialized yet. This was the case with ant because it didn't force
full resolution (ie load, link and initialize) and thus things like launching
proggies in JVM from junit or java tasks failed.
The only solution I know of is
class MyClass
{
public final static String MY_CLASS_NAME;
static
{
synchronized( MyClass.class )
{
MY_CLASS_NAME = MyClass.class.getName();
}
}
}
which is impractical when you have large numbers of these constructs.
This is one of the reasons I was lobbying for full resolution in Ant2 ;)
Cheers,
Pete
*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof." |
| - John Kenneth Galbraith |
*-----------------------------------------------------*