Conor MacNeill <[EMAIL PROTECTED]> wrote: > I have been looking at bug 1613 which is a summary of two other bugs > (1066 and 1362). The synopsis for these is "AntClassLoader doesn't > run static initializer blocks". I do not believe it is the class > loader's responsibility to run static initializer blocks.
It is not, agreed. The problem is, that some code in Ant uses either Class.forName (which will run the static initializers) or AntClassLoader.loadClass() which will not run them - but users expect both to work the same way. I'm not sure, whether loadClass should initialize the classes or not - but if we agree that it should not, we need to update all those places that use the loadClass method to explicitly initialize the class as well. > In fact, there is no way that I know to explicitly run these from > Java code. Class.forName like Pete said (starting with 1.2 you had the choice to not initialize the class, but the default is to run the static blocks). This is no option in Ant 1, as you cannot specify a ClassLoader in JDK 1.1 for it. > I have been trying various things in that block to get the static > initializers to run. The only thing which has worked has been to > call newInstance(). Yes, this is what the javadoc for newInstance says as well: "The class is initialized if it has not already been initialized." > So, that may be a hacky workaround to this problem. It is for Ant 1, we could get around it by using the three argument Class.forName version in Ant2 - up to then I could live with a hack like this. Stefan
