From: "Conor MacNeill" > > Why is AntClassLoader.initializeClass(target) being called? > > This method creates a new instance of the class by calling > > its no-arg constructor. I mean, when main.invoke is called, the > > static initializers of the class are anyway going to be invoked, > > right? > > No, unfortunately not always, IIRC although I could be wrong :-) Certainly > under JDK 1.1, static initializers are not always run when you load a class > through a classloader. This causes a problem for JDBC driver loading. > Perhaps not required for ExecuteJava. This is how I had understood the issue to be: http://developer.java.sun.com/developer/bugParade/bugs/4073950.html I might be recollecting it wrongly, but whenever I invoked a method by reflection on a class, even in 1.1, it used to result in the static initializers being called. I agree static initializers may not have been called when the class is 'loaded'. But when a method is invoked (for the first time) the static initializers would get called before 'first method invocation' Anyway, I will double check. I will download JDK 1.1 and see what gives... I know there used to be issues with JDBC Driver loading, but still... > BTW, Have you read the comments in the initializeClass method? I know it is > a hack. If you want to change it - feel free. It will be good to test your > class under JDK 1.1. I most definitely read the comments ;-) Comments are so rare I digest them with much fervour whenever they are available. I am not so satisfied with the hack anyways - maybe a better hack would be to invoke newInstance with a large (usually unlikely) array of arguments - this would result in an instantiation error because the constructor wouldn't be found, but at the same time, the class would have been loaded - I will confirm this for JDK 1.1. We achive both aims - loading the class as well as not calling default constructor. What do you think? > > I can't seem to access CVSWeb at the moment to get more history for this. In rev 1.9's checkin comments, you have explained the reason behind doing it this way. > > > Or is it being invoked to work around some JDK bug? > > The issue I have is that the class's constructor gets called > > twice if the main method constructs this object also. > > Yes, this is a side-effect. Does this cause you problems? Not exactly to me, but to people who have posted PRs ;-) They say that their no-arg constructor performs a whole bunch of further initialization, calling of various other objects ;-( whcih essentially makes the whole app sort of run twice... > > Conor > Cheers, Magesh -- To unsubscribe, e-mail: For additional commands, e-mail: