ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gurdev Parmar" <gpar...@versant.com>
Subject Re: AntClassLoader leads to ClassCastException
Date Thu, 28 Feb 2002 01:12:46 GMT
Firstly, Thanks for responding. You seem to be the only person
interested in sorting out ClassLoader stuff :)

I agree, I was using forceLoadClass in my original code.
But that I had put after trying the usual findClass and loadClass
which were giving me the same result. It doesn't make much
difference, anyways. Right? Because the parent classloader
doesn't have TestClient and TestEjbSelect classes.

I am not instantiating two instances of AntClassLoader as you
had pointed out. I create one instance in execute() and call
createDynamically() from there.

Does it matter that my jdk is 1.3 version and I am using ant1.4?

Still looking for an answer.

-Gurdev

----- Original Message -----
From: "Stefan Bodewig" <bodewig@apache.org>
To: <ant-user@jakarta.apache.org>
Sent: Wednesday, February 27, 2002 2:20 AM
Subject: Re: AntClassLoader leads to ClassCastException


> On Tue, 26 Feb 2002, Gurdev Parmar <gparmar@versant.com> wrote:
>
> > public TestClient createDynamically(String classname, AntClassLoader
acl) {
> >     Class clazz = acl.findClass(classname);
> >
> >     return (TestClient) clazz.newInstance();
> > }
>
> > The method is invoked with classname as "TestEjbSelect".
> >
> > I get a ClassCastException at the "return (TestClient)
> > clazz.newInstance()" point. When run in debug mode I can see that
> > TestClient and TestEjbSelect are being loaded from the ant loader.
>
> I don't see that.
>
> I see TestClient being loaded by ant class loader(s) twice, which
> makes me suspect you have two instances of AntClassloader's loading
> this class (those would be incompatible).
>
> And I don't see any message that TestEjbSelect has been loaded at all.
> The messages about TestEjbSelect look as if you had called
> forceLoadClass which you certainly don't do in the code snippet above.
>
> What I suspect is happening here is that you load TestClient and
> TestEjbSelect in AntClassLoader 1, then again load TestClient in
> AntClassLoader 2 and try to cast TestEjbSelect from class loader 1 to
> a TestClient from 2.
>
> Stefan
>
> --
> To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>
>


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


Mime
View raw message