ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Magesh Umasankar" <umag...@apache.org>
Subject Re: ExecuteJava and initializeClass
Date Wed, 16 Jan 2002 16:47:22 GMT
From: "Conor MacNeill" <conor@cortexebusiness.com.au>

> OK, check here for some relevant bugs from Ant
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1362
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1066
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1613
>
> These were the original motivaters for this change. It would be good if
> these continue to stay fixed.

This is the patch I propose (sorry it is not in diff yet)
ExecuteJava.java:

            } else {
                loader = new AntClassLoader(project.getCoreLoader(),
project, classpath, false);
                loader.setIsolated(true);
                loader.setThreadContextLoader();
                target = loader.forceLoadClass(classname);
                java.lang.reflect.Constructor[] c =
target.getConstructors();
                if (c != null) {//This check is not really needed, but
anyway...
                    java.lang.reflect.Constructor c1 = c[0]; //Class will
have at least one constructor.
                    String[] s = new String[1024];  //Hope nobody has a
constructor which taken in 1024 arguments
                    try {
                        c[0].newInstance(s);
                    } catch (Throwable t) {
                        /*
                            Ignore as static initializers would have
                            been loaded anyway.
                        */
                    }
                }
                //AntClassLoader.initializeClass(target);
            }

> You are thinking reflection not straight Class.newInstance?
Yes.

> You'll need a valid Constructor object for that and I'm not sure
> it will work but worth a try.

JVM guarantees that each class *will* have a constructor, either
provided by default or explicitly specified.  So, getting a constructor
object is easy and it can be safely assumed that we will get
a constructor object when using reflection.

> I remember trying a number of things to trigger startic initializers to
> run to no avail. Let me know if you have more success.

I would be most pleased if you can please cross-verify and let
me know if this works after patching up ExecuteJava with what
I have provided above.  It works in my environments...

After you confirm, perhaps, I may even move this piece
into AntClassLoader itself.

>
> Conor
>

Cheers,
Magesh



--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message